fix mypy linting

This commit is contained in:
Ishaan Jaffer
2025-11-22 10:46:03 -08:00
parent 9ea74a1aa9
commit aa9544380d
@@ -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,