fix(proxy): allow trailing slash and sub-paths on MCP inference routes

`/mcp/{subpath}` compiles to `^/mcp/[^/]+$`, so `/mcp/<server>/` and
`/mcp/<server>/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
This commit is contained in:
mariohome5 2026-08-11 13:39:31 +02:00
parent b0fac57fe4
commit 6f3cf9aec9
2 changed files with 3 additions and 1 deletions

View file

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

View file

@ -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"),