客服退款工单里,Agent 常见故障就两类:查订单时工具连不上,退款 Agent 和物流 Agent 交接时上下文丢了。MCP 管前一类,A2A 管后一类。2026 年,MCP 由 Anthropic 在 2024 年 11 月发起并开源,规范在 modelcontextprotocol.io;A2A 由 Google 在 2025 年 4 月公布,2025 年 6 月捐给 Linux Foundation,规范在 a2a-protocol.org。一个 Agent 可以同时用 MCP 调工具、用 A2A 找另一个 Agent。
1. MCP 和 A2A 各自管什么
MCP 的调用链:Host 启动 MCP Client,Client 连接 MCP Server。Server 暴露 tools、resources、prompts。传输用 stdio 或 Streamable HTTP,消息走 JSON-RPC 2.0。订单查询、文件读取、数据库只读查询适合放进 MCP Server。
A2A 的调用链:调用方拿到远端 Agent 的 Agent Card,发 task,收 message 和 artifact。传输是 JSON-RPC 2.0 over HTTPS,支持 SSE 流式。跨团队、跨语言、跨进程的退款 Agent、风控 Agent、物流 Agent 适合走 A2A。
| 维度 | MCP | A2A |
|---|---|---|
| 主要连接 | 模型/Agent 到工具、数据源 | Agent 到 Agent |
| 发现方式 | tools/list、resources/list | Agent Card |
| 调用消息 | JSON-RPC 2.0 | JSON-RPC 2.0 |
| 流式 | Streamable HTTP | SSE、推送通知 |
| 治理重点 | 工具 schema、scope、幂等 | 任务状态、交接、身份 |
| 常见故障 | 工具超时、权限过大 | 循环、上下文丢失 |
2. 生产架构:网关、权限、审计、可观测
单机 Demo 能跑,是因为没有网关。生产里把 MCP 和 A2A 都挡在网关后面。
MCP Gateway 做四件事:工具注册和 schema 校验;OAuth scope 检查;速率限制和超时;每次 tool call 写审计。A2A Gateway 做三件事:维护 Agent Card 目录;校验调用方身份和委托链;跟踪 task 状态和配额。
权限不要只放在 Prompt 里。MCP 工具声明所需 scope,例如 order:read、refund:write。A2A 调用方用 OAuth 2.1 或云 IAM 拿 token,委托链里保留 user_id 和 agent_id。退款这类写操作加人工审批或二次确认。
审计记录字段:
- trace_id:贯通 A2A task 和 MCP tool call
- agent_id、user_id、tool_name
- args_hash、result_hash:避免把 PII 明文写入日志
- policy_decision:allow、deny、require_approval
- latency_ms、token_cost
3. 评测与回归
MCP 侧做契约测试。用 tools/list 拿 schema,和快照比对。改工具参数就更新快照。再跑权限负例:没有 refund:write 调用 create_refund 必须失败。写操作要测幂等,重复调用不能重复退款。
A2A 侧做协作回放。把真实任务录制为 fixture,包括输入、Agent Card、交接顺序、最终 artifact。CI 里验证三件事:任务是否完成;交接是否落在预期 Agent;有没有循环调用。
| 指标 | 说明 | 建议阈值 |
|---|---|---|
| 工具调用成功率 | MCP tool call 成功/总调用 | 大于 99% |
| A2A 任务完成率 | 无人工接管的完成/总任务 | 按业务定 |
| 交接错误率 | 错发 Agent/总交接 | 小于 1% |
| 循环次数 | 同一 task 内重复交接 | 0 |
| 单任务成本 | token + 工具费用 | 设预算告警 |
4. 云厂商平台怎么选
2026 年,平台功能变化快。下表给核验方向,具体支持以你所在区域官方文档为准。
| 平台/项目 | MCP 接入 | A2A 接入 | 生产治理 | 核验关键词 |
|---|---|---|---|---|
| AWS Bedrock AgentCore | AgentCore Gateway 面向 MCP 工具接入 | 查 Runtime 的 A2A 示例 | Identity、Memory、Observability | AgentCore Gateway MCP |
| Azure AI Foundry Agent Service | 文档提供 MCP 工具接入 | 查 Foundry、Copilot Studio 的跨 Agent 能力 | Entra ID、Purview、Azure Monitor | Foundry Agent MCP |
| Google Vertex AI Agent Engine + ADK | ADK 支持 MCP 工具 | A2A 是 ADK 和 Agent Engine 的公开能力 | IAM、Cloud Trace、Cloud Logging | ADK A2A |
| 阿里云百炼 | MCP 服务市场和自定义 MCP | 公开资料中 A2A 支持少,常见自建 | RAM、SLS | 百炼 MCP |
| 腾讯云智能体开发平台 | MCP 插件接入 | 跨 Agent 协作多需自建 | CAM、CLS | 腾讯云 MCP 插件 |
| 火山引擎扣子/Coze | MCP 服务接入 | 跨平台 A2A 以官方文档为准 | 火山 IAM、日志服务 | 扣子 MCP |
5. 最小可行代码栈
目录结构:
agent-demo/
mcp_server/
server.py
a2a_agent/
agent_card.md
gateway/
policy.yaml
eval/
test_tool_contract.py
docker-compose.yml
MCP Server 用官方 Python SDK 的 FastMCP:
from mcp.server.fastmcp import FastMCP
mcp = FastMCP('orders')
@mcp.tool()
def get_order(order_id: str) -> dict:
return {'order_id': order_id, 'status': 'paid'}
if __name__ == '__main__':
mcp.run()
安装和调通:
pip install mcp
npx @modelcontextprotocol/inspector python mcp_server/server.py
A2A 侧先写 Agent Card 字段:name、description、url(你的真实端点)、version、capabilities、skills。skills 里写清输入输出。不要先写复杂编排。
网关策略用 YAML:
tools:
get_order:
scopes: [order:read]
rate_limit: 10/s
create_refund:
scopes: [refund:write]
require_approval: true
编排先用 FastAPI 或 LangGraph 跑通一条链路:Triage Agent 收工单 -> 调 MCP 查订单 -> 通过 A2A 调 Refund Agent -> Refund Agent 调 MCP 发起退款。可观测接 OpenTelemetry Collector,评测用 pytest。
看完能立刻做的一件事:选一个只读工具,用 FastMCP 暴露,在 MCP Inspector 里调通,再给这个工具加一条审计日志。跑通后再加 A2A Agent Card,不要一上来就做全自动多 Agent。
免责声明:文中协议与平台信息基于 2026 年公开文档,具体接口、区域和定价以官方最新说明为准。未附视频链接,避免给出未核验来源。