MCP断路器架构
DevOps
弹性模式,使用三种状态包装MCP调用:关闭(正常)、打开(检测到故障,快速失败)和半开(测试恢复)。防止工具无响应时的级联故障。对于生产级可靠性至关重要。
完整 FlowZap 代码
Host { # Host Application
n1: circle label="User sends prompt"
n2: rectangle label="Agent prepares MCP call"
n3: rectangle label="Pass call to circuit breaker"
n4: rectangle label="Receive result or error"
n5: rectangle label="Agent responds to user"
n1.handle(right) -> n2.handle(left)
n2.handle(right) -> n3.handle(left)
n3.handle(bottom) -> CB.n6.handle(top) [label="MCP tool call"]
n4.handle(right) -> n5.handle(left)
}
CB { # Circuit Breaker
n6: rectangle label="Check circuit state"
n7: diamond label="Circuit open?"
n8: rectangle label="Forward to MCP server"
n9: rectangle label="Fast-fail with error"
n10: diamond label="Call succeeded?"
n11: rectangle label="Record success"
n12: rectangle label="Record failure and check threshold"
n6.handle(right) -> n7.handle(left)
n7.handle(right) -> n8.handle(left) [label="Closed"]
n7.handle(bottom) -> n9.handle(top) [label="Open"]
n8.handle(bottom) -> MCPServer.n13.handle(top) [label="Forward request"]
n9.handle(top) -> Host.n4.handle(bottom) [label="CircuitOpenError"]
n10.handle(right) -> n11.handle(left) [label="Yes"]
n10.handle(bottom) -> n12.handle(top) [label="No"]
n11.handle(top) -> Host.n4.handle(left) [label="Return result"]
n12.handle(top) -> Host.n4.handle(right) [label="Return error"]
}
MCPServer { # MCP Server
n13: rectangle label="Attempt tool execution"
n14: rectangle label="Return result or error"
n13.handle(right) -> n14.handle(left)
n14.handle(top) -> CB.n10.handle(bottom) [label="Execution outcome"]
}
相关模板
MCP智能体网格架构
DevOps
多智能体网格模式,其中智能体通过MCP支持的共享上下文代理进行通信。实现多个专业智能体(规划者、编码者、审查者、操作者)之间的协调工具访问和状态同步。支持编排和编排的交互模式。
MCP上下文代理架构
DevOps
位于智能体和MCP服务器之间的缓存和压缩层,在冗余上下文请求到达网络之前拦截它们。使用基于TTL的缓存失效、Brotli压缩和语义缓存。可实现高达95%以上的token减少,并显著降低LLM账单。