MCPcopy Create free account
hub / github.com/MiniMax-AI/Mini-Agent / execute

Method execute

mini_agent/tools/mcp_loader.py:89–119  ·  view source on GitHub ↗

Execute MCP tool via the session with timeout protection.

(self, **kwargs)

Source from the content-addressed store, hash-verified

87 return self._parameters
88
89 async def execute(self, **kwargs) -> ToolResult:
90 """Execute MCP tool via the session with timeout protection."""
91 timeout = self._execute_timeout or _default_timeout_config.execute_timeout
92
93 try:
94 # Wrap call_tool with timeout
95 async with asyncio.timeout(timeout):
96 result = await self._session.call_tool(self._name, arguments=kwargs)
97
98 # MCP tool results are a list of content items
99 content_parts = []
100 for item in result.content:
101 if hasattr(item, "text"):
102 content_parts.append(item.text)
103 else:
104 content_parts.append(str(item))
105
106 content_str = "\n".join(content_parts)
107
108 is_error = result.isError if hasattr(result, "isError") else False
109
110 return ToolResult(success=not is_error, content=content_str, error=None if not is_error else "Tool returned error")
111
112 except TimeoutError:
113 return ToolResult(
114 success=False,
115 content="",
116 error=f"MCP tool execution timed out after {timeout}s. The remote server may be slow or unresponsive.",
117 )
118 except Exception as e:
119 return ToolResult(success=False, content="", error=f"MCP tool execution failed: {str(e)}")
120
121
122class MCPServerConnection:

Callers

nothing calls this directly

Calls 2

ToolResultClass · 0.85
call_toolMethod · 0.80

Tested by

no test coverage detected