mirror of
https://github.com/tiennm99/litellm.git
synced 2026-08-01 20:21:14 +00:00
[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
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user