The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(mcp): return malformed_payload for signed envelopes with empty identity claims
Tin Chi Lodd38e9f1a0d8
diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/envelope.py b/litellm/proxy/_experimental/mcp_server/outbound_credentials/envelope.pyindex 5023a5a76f2..666ef87e6b2 100644--- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/envelope.py+++ b/litellm/proxy/_experimental/mcp_server/outbound_credentials/envelope.py@@ -160,12 +160,17 @@ EnvelopeOpenError: TypeAlias = NotAnEnvelope | BadSignature | Expired | Malformeclass _EnvelopeClaims(BaseModel):+ """Decoded-claims boundary. ``user_id``/``server_id`` mirror the ``min_length``+ constraints of :class:`EnvelopeIdentity` so any claim set that validates here also+ constructs an identity, keeping :func:`open_envelope` raise-free: a correctly signed+ JWT with an empty identity claim fails here and maps to ``MalformedPayload``."""+model_config = ConfigDict(frozen=True)iss: striat: intexp: int- user_id: str- server_id: str+ user_id: str = Field(min_length=1)+ server_id: str = Field(min_length=1)grant: str = Field(min_length=1)diff --git a/tests/test_litellm/proxy/_experimental/mcp_server/outbound_credentials/test_envelope.py b/tests/test_litellm/proxy/_experimental/mcp_server/outbound_credentials/test_envelope.pyindex b99853c1b3d..b9d91c011c6 100644--- a/tests/test_litellm/proxy/_experimental/mcp_server/outbound_credentials/test_envelope.py+++ b/tests/test_litellm/proxy/_experimental/mcp_server/outbound_credentials/test_envelope.py@@ -211,6 +211,16 @@ def test_missing_identity_claim_is_malformed_payload():assert isinstance(open_envelope(forged, _KEYS, _NOW), MalformedPayload)[email protected]("identity_claim", ["user_id", "server_id"])+def test_signed_empty_identity_claim_is_malformed_payload_not_a_raise(identity_claim):+ claims = _unverified_claims(_sealed_token(_full_grant()))+ forged = _forge({**claims, identity_claim: ""})+ assert isinstance(open_envelope(forged, _KEYS, _NOW), MalformedPayload)+ intact = open_envelope(_forge(claims), _KEYS, _NOW)+ assert isinstance(intact, OpenedEnvelope)+ assert intact.identity == _IDENTITY++def test_correctly_signed_garbage_grant_blob_is_decrypt_failed():claims = _unverified_claims(_sealed_token(_full_grant()))forged = _forge({**claims, "grant": "not-a-ciphertext"})