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

1"""MCP 工具集成""" 

2 

3from .base import BaseTool 

4 

5 

6class MCPTool(BaseTool): 

7 """MCP 服务器工具调用""" 

8 

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 } 

21 

22 def check(self) -> bool: 

23 """MCP 客户端未实现时隐藏此工具""" 

24 return False # TODO: 实现后改为 True 

25 

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 } 

33 

34 

35from .registry import tool_registry # noqa: E402 — 模块末尾自注册 

36tool_registry.register(MCPTool()) 

37 

38 

39class MCPManager: 

40 """MCP 服务器管理器""" 

41 

42 def __init__(self): 

43 self._servers = {} 

44 

45 async def connect(self, name: str, config: dict): 

46 """连接 MCP 服务器""" 

47 raise NotImplementedError 

48 

49 async def disconnect(self, name: str): 

50 """断开 MCP 服务器""" 

51 raise NotImplementedError 

52 

53 def list_servers(self) -> list: 

54 """列出已连接的服务器""" 

55 return list(self._servers.keys())