From e3c9318bd453c4140dfe61d4c8a72841faa4e9b4 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Fri, 27 Jun 2025 09:05:38 -0700 Subject: [PATCH] [Fix] MCP - Ensure internal users can access /mcp and /mcp/ routes (#12106) * fixes for MCP route checks * test is is_llm_api_route for MCP --- litellm/proxy/_types.py | 8 +++++++- litellm/proxy/auth/route_checks.py | 6 ++++++ litellm/proxy/proxy_config.yaml | 10 ---------- .../test_route_check_unit_tests.py | 2 ++ 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/litellm/proxy/_types.py b/litellm/proxy/_types.py index db0959a1d4..d4d852031d 100644 --- a/litellm/proxy/_types.py +++ b/litellm/proxy/_types.py @@ -341,7 +341,12 @@ class LiteLLMRoutes(enum.Enum): anthropic_routes = [ "/v1/messages", - # MCP routes + ] + + mcp_routes = [ + "/mcp", + "/mcp/", + "/mcp/{subpath}", "/mcp/tools", "/mcp/tools/list", "/mcp/tools/call", @@ -365,6 +370,7 @@ class LiteLLMRoutes(enum.Enum): + anthropic_routes + mapped_pass_through_routes + apply_guardrail_routes + + mcp_routes ) info_routes = [ "/key/info", diff --git a/litellm/proxy/auth/route_checks.py b/litellm/proxy/auth/route_checks.py index 5fae38cee6..22490919e0 100644 --- a/litellm/proxy/auth/route_checks.py +++ b/litellm/proxy/auth/route_checks.py @@ -195,6 +195,12 @@ class RouteChecks: if route in LiteLLMRoutes.anthropic_routes.value: return True + if RouteChecks.check_route_access( + route=route, + allowed_routes=LiteLLMRoutes.mcp_routes.value + ): + return True + # fuzzy match routes like "/v1/threads/thread_49EIN5QF32s4mH20M7GFKdlZ" # Check for routes with placeholders for openai_route in LiteLLMRoutes.openai_routes.value: diff --git a/litellm/proxy/proxy_config.yaml b/litellm/proxy/proxy_config.yaml index 11e90307a2..b31ab0b272 100644 --- a/litellm/proxy/proxy_config.yaml +++ b/litellm/proxy/proxy_config.yaml @@ -8,13 +8,3 @@ mcp_servers: deepwiki_mcp: url: "https://mcp.deepwiki.com/mcp" transport: "http" - -general_settings: - store_model_in_db: true - store_prompts_in_spend_logs: true - -litellm_settings: - callbacks: ["langfuse", "datadog"] - cache: True - cache_params: # set cache params for redis - type: redis \ No newline at end of file diff --git a/tests/proxy_admin_ui_tests/test_route_check_unit_tests.py b/tests/proxy_admin_ui_tests/test_route_check_unit_tests.py index a4d9eab0ad..8f75888468 100644 --- a/tests/proxy_admin_ui_tests/test_route_check_unit_tests.py +++ b/tests/proxy_admin_ui_tests/test_route_check_unit_tests.py @@ -89,6 +89,8 @@ def test_is_llm_api_route(): ) # MCP routes + assert RouteChecks.is_llm_api_route("/mcp") is True + assert RouteChecks.is_llm_api_route("/mcp/") is True assert RouteChecks.is_llm_api_route("/mcp/tools") is True assert RouteChecks.is_llm_api_route("/mcp/tools/call") is True assert RouteChecks.is_llm_api_route("/mcp/tools/list") is True