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: removed initialize the tool name to MCP server name mapping(oauth2) on startup for avoiding 401 error

Eric846260306f02e74d7
diff --git a/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py b/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py
index 8c9d8630457..c2215efe9d0 100644
--- a/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py
+++ b/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py
@@ -1913,6 +1913,9 @@ class MCPServerManager:
Note: This now handles prefixed tool names
"""
for server in self.get_registry().values():
+ if server.auth_type == MCPAuth.oauth2:
+ # Skip OAuth2 servers for now as they may require user-specific tokens
+ continue
tools = await self._get_tools_from_server(server)
for tool in tools:
# The tool.name here is already prefixed from _get_tools_from_server
diff --git a/tests/test_litellm/proxy/_experimental/mcp_server/test_mcp_server_manager.py b/tests/test_litellm/proxy/_experimental/mcp_server/test_mcp_server_manager.py
index 7a6e5ad17f6..c0ded9c728c 100644
--- a/tests/test_litellm/proxy/_experimental/mcp_server/test_mcp_server_manager.py
+++ b/tests/test_litellm/proxy/_experimental/mcp_server/test_mcp_server_manager.py
@@ -536,7 +536,26 @@ class TestMCPServerManager:
assert (
server.registration_url == "https://discovered.example.com/register"
)
+ @pytest.mark.asyncio
+ async def test_config_oauth_initialize_tool_name_to_mcp_server_name_mapping(self):
+ manager = MCPServerManager()
+
+ config = {
+ "example": {
+ "url": "https://example.com/mcp",
+ "transport": MCPTransport.http,
+ "auth_type": MCPAuth.oauth2,
+ "scopes": ["config"],
+ "authorization_url": "https://config.example.com/auth",
+ }
+ }
+
+ await manager.load_servers_from_config(config)
+ # Initialize the tool mapping
+ await manager._initialize_tool_name_to_mcp_server_name_mapping()
+ assert manager.tool_name_to_mcp_server_name_mapping == {}
+
@pytest.mark.asyncio
async def test_list_tools_handles_missing_server_alias(self):
"""Test that list_tools handles servers without alias gracefully"""