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

Function execute_mcp_tool_with_endpoint

api_utils/mcp_adapter.py:41–57  ·  view source on GitHub ↗
(
    endpoint: str, name: str, params: Dict[str, Any]
)

Source from the content-addressed store, hash-verified

39
40
41async def execute_mcp_tool_with_endpoint(
42 endpoint: str, name: str, params: Dict[str, Any]
43) -> str:
44 url = f"{_normalize_endpoint(endpoint)}/tools/execute"
45 payload = {"name": name, "arguments": params}
46 headers = {"Content-Type": "application/json"}
47 timeout = float(os.environ.get("MCP_HTTP_TIMEOUT", "15"))
48 async with httpx.AsyncClient(timeout=timeout) as client:
49 resp = await client.post(url, json=payload, headers=headers)
50 resp.raise_for_status()
51 try:
52 data = resp.json()
53 except asyncio.CancelledError:
54 raise
55 except Exception:
56 data = {"raw": resp.text}
57 return json.dumps(data, ensure_ascii=False)

Callers 9

test_successMethod · 0.90
test_http_errorMethod · 0.90
test_uses_env_timeoutMethod · 0.90
test_complex_paramsMethod · 0.90
execute_tool_callFunction · 0.90

Calls 2

_normalize_endpointFunction · 0.85
getMethod · 0.45

Tested by 8

test_successMethod · 0.72
test_http_errorMethod · 0.72
test_uses_env_timeoutMethod · 0.72
test_complex_paramsMethod · 0.72