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 mypy linting

Ishaan Jafferaa9544380d7d
diff --git a/litellm/proxy/_experimental/mcp_server/server.py b/litellm/proxy/_experimental/mcp_server/server.py
index b6b36622d60..6133c658069 100644
--- a/litellm/proxy/_experimental/mcp_server/server.py
+++ b/litellm/proxy/_experimental/mcp_server/server.py
@@ -1,6 +1,7 @@
"""
LiteLLM MCP Server Routes
"""
+# pyright: reportInvalidTypeForm=false, reportArgumentType=false, reportOptionalCall=false
import asyncio
import contextlib
@@ -45,17 +46,17 @@ try:
except ImportError as e:
verbose_logger.debug(f"MCP module not found: {e}")
MCP_AVAILABLE = False
- # For type checking only - these will never be accessed at runtime when MCP is unavailable
- # because all code using them is guarded by `if MCP_AVAILABLE:`
- if TYPE_CHECKING:
- from typing import Any as BlobResourceContents # type: ignore
- from typing import Any as GetPromptResult
- from typing import Any as ReadResourceContents
- from typing import Any as ReadResourceResult
- from typing import Any as Resource
- from typing import Any as ResourceTemplate
- from typing import Any as Server
- from typing import Any as TextResourceContents
+ # When MCP is not available, we set these to None at module level
+ # All code using these types is inside `if MCP_AVAILABLE:` blocks
+ # so they will never be accessed at runtime
+ BlobResourceContents = None # type: ignore
+ GetPromptResult = None # type: ignore
+ ReadResourceContents = None # type: ignore
+ ReadResourceResult = None # type: ignore
+ Resource = None # type: ignore
+ ResourceTemplate = None # type: ignore
+ Server = None # type: ignore
+ TextResourceContents = None # type: ignore
# Global variables to track initialization
@@ -1191,11 +1192,11 @@ if MCP_AVAILABLE:
allowed_mcp_servers: List[MCPServer] = []
for allowed_mcp_server_id in allowed_mcp_server_ids:
- mcp_server = global_mcp_server_manager.get_mcp_server_by_id(
+ allowed_server = global_mcp_server_manager.get_mcp_server_by_id(
allowed_mcp_server_id
)
- if mcp_server is not None:
- allowed_mcp_servers.append(mcp_server)
+ if allowed_server is not None:
+ allowed_mcp_servers.append(allowed_server)
allowed_mcp_servers = await _get_allowed_mcp_servers_from_mcp_server_names(
mcp_servers=mcp_servers,