From f24744fc81c101821a8700a1e0beab6f6050c204 Mon Sep 17 00:00:00 2001 From: Yug Date: Wed, 29 Apr 2026 12:34:01 +0530 Subject: [PATCH] issues --- .../mcp_server/mcp_server_manager.py | 8 ++++++-- litellm/proxy/_experimental/mcp_server/server.py | 8 ++++---- litellm/proxy/_types.py | 16 ++++++++++++---- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py b/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py index 50579124c2f..5f8505a6b62 100644 --- a/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py +++ b/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py @@ -1211,8 +1211,12 @@ class MCPServerManager: # config/DB records predating the allowlist. if server.command: base_command = os.path.basename(server.command) - # Strip .exe/.cmd/.bat suffix for Windows compatibility - base_command_no_ext = os.path.splitext(base_command)[0] + # Strip .exe/.cmd/.bat/.com suffix for Windows compatibility + base_command_no_ext = base_command + for ext in [".exe", ".cmd", ".bat", ".com"]: + if base_command.lower().endswith(ext): + base_command_no_ext = base_command[: -len(ext)] + break if ( base_command not in MCP_STDIO_ALLOWED_COMMANDS and base_command_no_ext not in MCP_STDIO_ALLOWED_COMMANDS diff --git a/litellm/proxy/_experimental/mcp_server/server.py b/litellm/proxy/_experimental/mcp_server/server.py index dd834a9194a..a7f68f00b1c 100644 --- a/litellm/proxy/_experimental/mcp_server/server.py +++ b/litellm/proxy/_experimental/mcp_server/server.py @@ -376,14 +376,12 @@ if MCP_AVAILABLE: from litellm.exceptions import BlockedPiiEntityError, GuardrailRaisedException from litellm.proxy.litellm_pre_call_utils import add_litellm_data_to_request from litellm.proxy.proxy_server import proxy_config - from mcp.server.models import CallToolResult - from mcp.server.lowlevel.server import request_ctx, request_ctx_var + from mcp.types import CallToolResult + from mcp.server.lowlevel.server import request_ctx req_ctx = request_ctx.get(None) if req_ctx: active_mcp_session_var.set(req_ctx.session) - elif request_ctx_var.get(None): - active_mcp_session_var.set(request_ctx_var.get().session) # Validate arguments ( @@ -2758,6 +2756,8 @@ if MCP_AVAILABLE: raw_headers=raw_headers, client_ip=_sse_client_ip, ) + except HTTPException: + raise except Exception as e: verbose_logger.warning( f"Failed to extract auth context in POST /messages: {e}" diff --git a/litellm/proxy/_types.py b/litellm/proxy/_types.py index e5e2fc82b88..33376271171 100644 --- a/litellm/proxy/_types.py +++ b/litellm/proxy/_types.py @@ -1215,8 +1215,12 @@ class NewMCPServerRequest(LiteLLMPydanticObjectBase): raise ValueError("args is required for stdio transport") # Validate command against allowlist to prevent arbitrary execution base_command = os.path.basename(values["command"]) - # Strip .exe/.cmd/.bat suffix for Windows compatibility - base_command_no_ext = os.path.splitext(base_command)[0] + # Strip .exe/.cmd/.bat/.com suffix for Windows compatibility + base_command_no_ext = base_command + for ext in [".exe", ".cmd", ".bat", ".com"]: + if base_command.lower().endswith(ext): + base_command_no_ext = base_command[: -len(ext)] + break if ( base_command not in MCP_STDIO_ALLOWED_COMMANDS and base_command_no_ext not in MCP_STDIO_ALLOWED_COMMANDS @@ -1288,8 +1292,12 @@ class UpdateMCPServerRequest(LiteLLMPydanticObjectBase): raise ValueError("args is required for stdio transport") # Validate command against allowlist to prevent arbitrary execution base_command = os.path.basename(values["command"]) - # Strip .exe/.cmd/.bat suffix for Windows compatibility - base_command_no_ext = os.path.splitext(base_command)[0] + # Strip .exe/.cmd/.bat/.com suffix for Windows compatibility + base_command_no_ext = base_command + for ext in [".exe", ".cmd", ".bat", ".com"]: + if base_command.lower().endswith(ext): + base_command_no_ext = base_command[: -len(ext)] + break if ( base_command not in MCP_STDIO_ALLOWED_COMMANDS and base_command_no_ext not in MCP_STDIO_ALLOWED_COMMANDS