This commit is contained in:
Yug 2026-04-29 12:34:01 +05:30
parent 9b710c3502
commit f24744fc81
3 changed files with 22 additions and 10 deletions

View file

@ -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

View file

@ -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}"

View file

@ -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