MCPcopy Create free account
hub / github.com/CJackHwang/AIstudioProxyAPI / execute_mcp_tool

Function execute_mcp_tool

api_utils/mcp_adapter.py:15–38  ·  view source on GitHub ↗

Minimal MCP-over-HTTP adapter: - POST {MCP_HTTP_ENDPOINT}/tools/execute with {name, arguments} - Returns JSON string. Compatible with servers exposing MCP-like HTTP interface.

(name: str, params: Dict[str, Any])

Source from the content-addressed store, hash-verified

13
14
15async def execute_mcp_tool(name: str, params: Dict[str, Any]) -> str:
16 """
17 Minimal MCP-over-HTTP adapter:
18 - POST {MCP_HTTP_ENDPOINT}/tools/execute with {name, arguments}
19 - Returns JSON string.
20 Compatible with servers exposing MCP-like HTTP interface.
21 """
22 ep = os.environ.get("MCP_HTTP_ENDPOINT")
23 if not ep:
24 raise RuntimeError("MCP_HTTP_ENDPOINT not configured")
25 url = f"{_normalize_endpoint(ep)}/tools/execute"
26 payload = {"name": name, "arguments": params}
27 headers = {"Content-Type": "application/json"}
28 timeout = float(os.environ.get("MCP_HTTP_TIMEOUT", "15"))
29 async with httpx.AsyncClient(timeout=timeout) as client:
30 resp = await client.post(url, json=payload, headers=headers)
31 resp.raise_for_status()
32 try:
33 data = resp.json()
34 except asyncio.CancelledError:
35 raise
36 except Exception:
37 data = {"raw": resp.text}
38 return json.dumps(data, ensure_ascii=False)
39
40
41async def execute_mcp_tool_with_endpoint(

Calls 2

_normalize_endpointFunction · 0.85
getMethod · 0.45