Sfoglia il codice sorgente

删除部分冗余代码

关习习 1 mese fa
parent
commit
ddb8600143
2 ha cambiato i file con 1 aggiunte e 43 eliminazioni
  1. 0 36
      mcp_tools.py
  2. 1 7
      tools.py

+ 0 - 36
mcp_tools.py

@@ -114,42 +114,6 @@ class MCPTools:
         else:
             return result
 
-    def get_mcp_tool_list(self):
-        """
-        获取MCP工具列表,用于添加到AI工具中
-        根据配置动态生成工具列表
-        """
-        tools = []
-        
-        # 为每个配置的MCP服务创建对应的工具
-        for server_name, server_config in self.mcp_servers.items():
-            tool_name = f"call_{server_name}_mcp"
-            description = server_config.get("description", f"调用{server_name} MCP服务")
-            
-            tools.append({
-                "type": "function",
-                "function": {
-                    "name": tool_name,
-                    "description": description,
-                    "parameters": {
-                        "type": "object",
-                        "properties": {
-                            "method": {
-                                "type": "string",
-                                "description": "要调用的MCP方法,如tools/list, tools/call等"
-                            },
-                            "params": {
-                                "type": "object",
-                                "description": "方法参数"
-                            }
-                        },
-                        "required": ["method"]
-                    }
-                }
-            })
-        
-        return tools
-
     async def get_actual_mcp_tools(self, server_name):
         """
         获取指定MCP服务的实际工具列表

+ 1 - 7
tools.py

@@ -98,9 +98,6 @@ class Tools:
                     result_dict = json.loads(result)
                     if "error" in result_dict:
                         error_msg = result_dict['error']
-                        # 提供更详细的错误信息和建议
-                        if "unhandled errors in a TaskGroup" in error_msg:
-                            return f"MCP调用错误: {server_name}服务内部出现未处理的异常。这通常表示服务端存在问题。错误详情: {error_msg}"
                         return f"MCP调用错误: {error_msg}"
                 except json.JSONDecodeError:
                     pass  # 如果不是JSON格式,直接返回原始结果
@@ -108,9 +105,6 @@ class Tools:
             else:
                 return f"未知工具: {tool_name}"
 
-        return f"工具 {tool_name} 执行完成"
-
 if __name__ == "__main__":
     tools = Tools()
-    print(tools.get_tool_list())
-    print(tools.call_tool("read_webpage", {"url": "https://www.baidu.com"}))
+    print(tools.get_tool_list())