Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

fix: Ensure MCP client stays open during tool call

Yuta Saito3035305c76bf
diff --git a/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py b/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py
index 3c27a65f06a..2efd27a1aa9 100644
--- a/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py
+++ b/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py
@@ -1098,13 +1098,14 @@ class MCPServerManager:
extra_headers=extra_headers,
)
- async with client:
- # Use the original tool name (without prefix) for the actual call
- call_tool_params = MCPCallToolRequestParams(
- name=original_tool_name,
- arguments=arguments,
- )
- tasks.append(asyncio.create_task(client.call_tool(call_tool_params)))
+ call_tool_params = MCPCallToolRequestParams(
+ name=original_tool_name,
+ arguments=arguments,
+ )
+ async def _call_tool_via_client(client, params):
+ async with client:
+ return await client.call_tool(params)
+ tasks.append(asyncio.create_task(_call_tool_via_client(client, call_tool_params)))
try:
mcp_responses = await asyncio.gather(*tasks)