Skip to content

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]

fix(search): send MCP-Protocol-Version on AgentCore gateway calls

yassin17b72d5089c7
diff --git a/litellm/llms/bedrock/search/transformation.py b/litellm/llms/bedrock/search/transformation.py
index ca9759ed151..5567dc8403e 100644
--- a/litellm/llms/bedrock/search/transformation.py
+++ b/litellm/llms/bedrock/search/transformation.py
@@ -66,6 +66,11 @@ AGENTCORE_DEFAULT_TOOL_NAME: Final = "web-search-tool___WebSearch"
# with the proxy's credentials.
AGENTCORE_TOOL_NAME_SUFFIX: Final = "___WebSearch"
+# MCP revision this provider speaks. Sent on every request because the gateway is
+# called statelessly, without an initialize handshake to negotiate a version;
+# servers that predate the header ignore it.
+AGENTCORE_MCP_PROTOCOL_VERSION: Final = "2025-06-18"
+
_GATEWAY_REGION_PATTERN: Final = re.compile(r"\.gateway\.bedrock-agentcore\.([a-z0-9-]+)\.amazonaws\.com")
_SSE_EVENT_SEPARATOR: Final = re.compile(r"\n[ \t]*\n")
@@ -147,7 +152,8 @@ class AgentCoreSearchConfig(BaseSearchConfig, BaseAWSLLM):
) -> dict: # mutable-ok: the handler passes these headers straight to httpx, which wants a dict
"""
Set MCP transport headers. Per the MCP Streamable HTTP transport spec,
- the client MUST accept both application/json and text/event-stream.
+ the client MUST accept both application/json and text/event-stream, and
+ declare its protocol revision with MCP-Protocol-Version.
Authentication itself happens in sign_request(): bearer token for
CUSTOM_JWT gateways, AWS SigV4 for AWS_IAM gateways.
@@ -156,6 +162,7 @@ class AgentCoreSearchConfig(BaseSearchConfig, BaseAWSLLM):
**headers,
"Content-Type": "application/json",
"Accept": "application/json, text/event-stream",
+ "MCP-Protocol-Version": AGENTCORE_MCP_PROTOCOL_VERSION,
}
def get_complete_url(
diff --git a/tests/test_litellm/llms/bedrock/search/test_agentcore_search_transformation.py b/tests/test_litellm/llms/bedrock/search/test_agentcore_search_transformation.py
index 38189abe0e8..63ec2286c3d 100644
--- a/tests/test_litellm/llms/bedrock/search/test_agentcore_search_transformation.py
+++ b/tests/test_litellm/llms/bedrock/search/test_agentcore_search_transformation.py
@@ -13,7 +13,10 @@ import pytest
from unittest.mock import AsyncMock, patch, MagicMock
import litellm
-from litellm.llms.bedrock.search.transformation import AgentCoreSearchConfig
+from litellm.llms.bedrock.search.transformation import (
+ AGENTCORE_MCP_PROTOCOL_VERSION,
+ AgentCoreSearchConfig,
+)
GATEWAY_URL = "https://testgateway-abc123.gateway.bedrock-agentcore.us-east-1.amazonaws.com/mcp"
@@ -148,11 +151,43 @@ class TestAgentCoreSearch:
assert config.get_complete_url(api_base=GATEWAY_URL, optional_params={}) == GATEWAY_URL
def test_validate_environment_sets_mcp_headers(self):
- """MCP Streamable HTTP requires accepting both JSON and SSE."""
+ """MCP Streamable HTTP requires accepting both JSON and SSE, and declaring
+ the protocol revision the client speaks."""
config = AgentCoreSearchConfig()
headers = config.validate_environment(headers={})
assert headers["Accept"] == "application/json, text/event-stream"
assert headers["Content-Type"] == "application/json"
+ assert headers["MCP-Protocol-Version"] == AGENTCORE_MCP_PROTOCOL_VERSION
+
+ def test_protocol_version_header_survives_signing(self):
+ """Both auth paths must keep the MCP-Protocol-Version header on the wire."""
+ config = AgentCoreSearchConfig()
+ headers = config.validate_environment(headers={})
+
+ bearer_headers, _ = config.sign_request(
+ headers=headers,
+ optional_params={},
+ request_data={"jsonrpc": "2.0"},
+ api_base=GATEWAY_URL,
+ api_key="test-jwt-token",
+ )
+ assert bearer_headers["MCP-Protocol-Version"] == AGENTCORE_MCP_PROTOCOL_VERSION
+
+ with patch.dict(
+ os.environ,
+ {
+ "AWS_ACCESS_KEY_ID": "AKIAIOSFODNN7EXAMPLE",
+ "AWS_SECRET_ACCESS_KEY": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
+ },
+ ):
+ signed_headers, _ = config.sign_request(
+ headers=headers,
+ optional_params={"aws_region_name": "us-east-1"},
+ request_data={"jsonrpc": "2.0"},
+ api_base=GATEWAY_URL,
+ )
+ assert signed_headers["Authorization"].startswith("AWS4-HMAC-SHA256")
+ assert signed_headers["MCP-Protocol-Version"] == AGENTCORE_MCP_PROTOCOL_VERSION
def test_transform_search_response_parses_sse_frame(self):
"""Gateway may answer with an SSE-framed JSON-RPC message."""