From 6f3cf9aec956fb1dc9b320ce16ea7622f61b71e5 Mon Sep 17 00:00:00 2001 From: mariohome5 Date: Tue, 11 Aug 2026 13:39:31 +0200 Subject: [PATCH] fix(proxy): allow trailing slash and sub-paths on MCP inference routes `/mcp/{subpath}` compiles to `^/mcp/[^/]+$`, so `/mcp//` and `/mcp//mcp` are not recognised as LLM API routes and fall through to the admin-only branch, producing a misleading key/user/team error. Use the `:path` placeholder already used by `mcp_management_routes`. Fixes #36531 --- litellm/proxy/_types.py | 2 +- tests/test_litellm/proxy/auth/test_route_checks.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/litellm/proxy/_types.py b/litellm/proxy/_types.py index dc4f17c7b31..a3854a6f3c3 100644 --- a/litellm/proxy/_types.py +++ b/litellm/proxy/_types.py @@ -472,7 +472,7 @@ class LiteLLMRoutes(enum.Enum): mcp_inference_routes = [ "/mcp", "/mcp/", - "/mcp/{subpath}", + "/mcp/{subpath:path}", "/mcp/tools", "/mcp/tools/list", "/mcp/tools/call", diff --git a/tests/test_litellm/proxy/auth/test_route_checks.py b/tests/test_litellm/proxy/auth/test_route_checks.py index 0bfb10320f7..d5161db7f37 100644 --- a/tests/test_litellm/proxy/auth/test_route_checks.py +++ b/tests/test_litellm/proxy/auth/test_route_checks.py @@ -462,6 +462,8 @@ def test_virtual_key_llm_api_routes_rejects_mcp_multi_segment_admin_subpaths( ("/mcp", "POST"), ("/mcp/", "POST"), ("/mcp/my-server", "POST"), # matches the /mcp/{subpath} pattern + ("/mcp/my-server/", "POST"), # same server, trailing slash + ("/mcp/my-server/mcp", "POST"), # streamable-http transport sub-path ("/mcp/tools", "GET"), ("/mcp/tools/list", "POST"), ("/mcp/tools/call", "POST"),