跳转至

MCP 参考

本页回答“当前项目里的 MCP 不只是 server list,而是已经成型的 transport、credential、policy、audit 和 direct response 体系”。

核心分层

路径 作用
传输层 ai_service/services/mcp_client.py 负责 stdiohttp_sse 调用
注册层 ai_service/services/mcp_registry.py 解析 agent 挂载的 MCP server
凭据层 ai_service/services/mcp_secret_manager.py 加载、注入、轮换凭据
策略层 ai_service/services/mcp_policy.py approval、allow / deny、runtime policy
审计层 ai_service/services/mcp_audit.py 持久化 MCP 调用记录
运行时配置层 ai_service/orchestrator/mcp_runtime_config.py agent 级 MCP runtime override
响应控制层 ai_service/orchestrator/mcp_response_config.py quick match、intent gate、direct response field selection
透传层 ai_service/orchestrator/mcp_passthrough.py passthrough 决策与业务响应渲染

当前支持的 transport

stdio

  • 启动外部命令进程
  • 通过 stdin/stdout 交换 JSON payload
  • 适合本地或同机部署的 MCP server

http_sse

  • 通过 URL 发起外部调用
  • 支持 URL import mode,把普通 HTTP GET / POST 端点映射成虚拟 MCP tool
  • 适合第三方 API、远端服务或不方便进程直连的场景

这些都已经在 ai_service/services/mcp_client.py 里是现成行为,不是规划状态。

控制面入口

路径 作用
ai_service/api/routers/mcp.py server registry、credential、health check、test call、agent mount、response preview
ai_service/storage/model_domains/mcp.py MCP server / credential / agent mount 持久化模型
ai_service/storage/model_domains/enums.py transport type 与相关状态枚举

运营侧高频改动点

新增一个 MCP server

优先看:

  1. ai_service/api/routers/mcp.py
  2. ai_service/services/mcp_client.py
  3. ai_service/services/mcp_secret_manager.py

调整 agent 的 MCP 行为

优先看:

  1. ai_service/orchestrator/mcp_runtime_config.py
  2. ai_service/orchestrator/mcp_response_config.py
  3. ai_service/services/mcp_policy.py

排查工具调用失败

优先看:

  1. ai_service/services/mcp_client.py
  2. ai_service/services/mcp_audit.py
  3. ai_service/api/routers/mcp.py 的 health check / test call 相关入口

容易忽略但很关键的现实

  • MCP 不只是在聊天里调工具,也已经和 Studio 控制面、审计与审批联动
  • 当前系统允许把 MCP 输出直接转成业务响应,而不必总是走完整模型总结
  • MCP server 既可以作为 server 挂载给 agent,也能成为 skill backend 的底层能力来源

相关文档