feat: MCP 客户端(连接外部 MCP server,外部工具桥接进统一工具体系)

- 新增 mcp_client.py:McpClient(subprocess stdio JSON-RPC,reader 线程+响应表,
  initialize/list_tools/call_tool/shutdown 超时可控)+ McpClientManager(connect_all
  读 mcpServers、聚合、call_tool、cleanup 幂等)
- unified_tool_manager.py:initialize 末尾加载外部 MCP server,按 server__tool 前缀
  register_tool 带真实 inputSchema mcp_definition,shutdown 经 manager.cleanup 幂等终止子进程
- fc_tools.py:mcp_to_openai_tools 新增 get_mcp_tools 保真分支(同时修现状 liugin 工具
  schema 被压成 args 的坑)
- config.json:顶层加 mcpServers 空段(用户自填,已被 gitignore 不入库,代码 .get 兼容)
- 新增 tests/test_mcp_client.py(5 项,全链路+桥接+保真,不触真实引擎/网络)

Co-Authored-By: WorkBuddy <workbuddy@tencent.com>
This commit is contained in:
shuiyu67andWorkBuddy committed 2026-08-05 17:40:45 +08:00
1 parent a3977ecc85
commit d2ad1000b6
4 files changed
+606 -2

No files matched your search

+11 -2
View File
@@ -21,8 +21,17 @@ def mcp_to_openai_tools(plugin_manager) -> List[Dict]:
if not plugin_manager:
return tools
# 统一工具管理器
if hasattr(plugin_manager, 'plugins'):
# 优先使用统一工具管理器的 MCP 定义(含外部 MCP client 桥接的工具,schema 保真)
if hasattr(plugin_manager, 'get_mcp_tools'):
try:
for mcp_def in plugin_manager.get_mcp_tools():
fc_def = mcp_to_fc(mcp_def)
if fc_def:
tools.append(fc_def)
except Exception:
pass
# 统一工具管理器(兜底,旧实现未暴露 get_mcp_tools 时)
elif hasattr(plugin_manager, 'plugins'):
for plugin in plugin_manager.plugins:
fc_def = _extract_fc_def(plugin)
if fc_def: