From 1f9a08770103ac5f3e27c0906dde4bf9d1ee7fd8 Mon Sep 17 00:00:00 2001 From: Ishaan Jaffer Date: Thu, 9 Apr 2026 17:41:42 -0700 Subject: [PATCH] feat(mcp): validate token_response_metadata against server token_validation rules before storing credential --- .../mcp_management_endpoints.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/litellm/proxy/management_endpoints/mcp_management_endpoints.py b/litellm/proxy/management_endpoints/mcp_management_endpoints.py index 40d00adeb0b..9f7cbc184db 100644 --- a/litellm/proxy/management_endpoints/mcp_management_endpoints.py +++ b/litellm/proxy/management_endpoints/mcp_management_endpoints.py @@ -1619,6 +1619,22 @@ if MCP_AVAILABLE: status_code=status.HTTP_404_NOT_FOUND, detail={"error": f"MCP Server {server_id} not found"}, ) + + # Enforce token validation rules configured on the server. + # The caller must pass token_response_metadata with any fields + # that the server requires (e.g. enterprise_id from Slack's token response). + token_validation = getattr(mcp_server, "token_validation", None) + if token_validation and isinstance(token_validation, dict) and token_validation: + from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + _validate_token_response, + ) + + _validate_token_response( + token_response=payload.token_response_metadata or {}, + validation_rules=token_validation, + server_id=server_id, + ) + user_id = user_api_key_dict.user_id or "" if not user_id: raise HTTPException(