Coverage for merco/tools/mcp_tools.py: 0%
21 statements
« prev ^ index » next coverage.py v7.15.0, created at 2026-07-07 14:04 +0800
« prev ^ index » next coverage.py v7.15.0, created at 2026-07-07 14:04 +0800
1"""MCP 工具集成"""
3from .base import BaseTool
6class MCPTool(BaseTool):
7 """MCP 服务器工具调用"""
9 name = "mcp_call"
10 description = "调用已连接的 MCP 服务器工具"
11 toolset = "mcp"
12 parameters = {
13 "type": "object",
14 "properties": {
15 "server": {"type": "string", "description": "MCP 服务器名称"},
16 "tool": {"type": "string", "description": "工具名称"},
17 "arguments": {"type": "object", "description": "工具参数"},
18 },
19 "required": ["server", "tool"],
20 }
22 def check(self) -> bool:
23 """MCP 客户端未实现时隐藏此工具"""
24 return False # TODO: 实现后改为 True
26 async def execute(self, server: str, tool: str, arguments: dict = None) -> dict:
27 # TODO: 实现 MCP 客户端
28 return {
29 "error": "MCP integration not yet configured",
30 "server": server,
31 "tool": tool,
32 }
35from .registry import tool_registry # noqa: E402 — 模块末尾自注册
36tool_registry.register(MCPTool())
39class MCPManager:
40 """MCP 服务器管理器"""
42 def __init__(self):
43 self._servers = {}
45 async def connect(self, name: str, config: dict):
46 """连接 MCP 服务器"""
47 raise NotImplementedError
49 async def disconnect(self, name: str):
50 """断开 MCP 服务器"""
51 raise NotImplementedError
53 def list_servers(self) -> list:
54 """列出已连接的服务器"""
55 return list(self._servers.keys())