fix: store original MCP tool name, make close_mcp public

This commit is contained in:
Re-bin
2026-02-15 07:00:27 +00:00
parent 54d5f637e7
commit 52cf1da30a
4 changed files with 41 additions and 9 deletions
+1 -1
View File
@@ -229,7 +229,7 @@ class AgentLoop:
except asyncio.TimeoutError:
continue
async def _close_mcp(self) -> None:
async def close_mcp(self) -> None:
"""Close MCP connections."""
if self._mcp_stack:
try:
+2 -4
View File
@@ -14,7 +14,7 @@ class MCPToolWrapper(Tool):
def __init__(self, session, server_name: str, tool_def):
self._session = session
self._server = server_name
self._original_name = tool_def.name
self._name = f"mcp_{server_name}_{tool_def.name}"
self._description = tool_def.description or tool_def.name
self._parameters = tool_def.inputSchema or {"type": "object", "properties": {}}
@@ -33,9 +33,7 @@ class MCPToolWrapper(Tool):
async def execute(self, **kwargs: Any) -> str:
from mcp import types
result = await self._session.call_tool(
self._name.removeprefix(f"mcp_{self._server}_"), arguments=kwargs
)
result = await self._session.call_tool(self._original_name, arguments=kwargs)
parts = []
for block in result.content:
if isinstance(block, types.TextContent):
+3 -3
View File
@@ -405,7 +405,7 @@ def gateway(
except KeyboardInterrupt:
console.print("\nShutting down...")
finally:
await agent._close_mcp()
await agent.close_mcp()
heartbeat.stop()
cron.stop()
agent.stop()
@@ -473,7 +473,7 @@ def agent(
with _thinking_ctx():
response = await agent_loop.process_direct(message, session_id)
_print_agent_response(response, render_markdown=markdown)
await agent_loop._close_mcp()
await agent_loop.close_mcp()
asyncio.run(run_once())
else:
@@ -515,7 +515,7 @@ def agent(
console.print("\nGoodbye!")
break
finally:
await agent_loop._close_mcp()
await agent_loop.close_mcp()
asyncio.run(run_interactive())