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): default the AgentCore MCP protocol version to the gateway default

mateo-berrib3c3e6ebb8a3
diff --git a/litellm/llms/bedrock/search/transformation.py b/litellm/llms/bedrock/search/transformation.py
index 80e20d00ff9..94b69912faa 100644
--- a/litellm/llms/bedrock/search/transformation.py
+++ b/litellm/llms/bedrock/search/transformation.py
@@ -67,9 +67,12 @@ AGENTCORE_DEFAULT_TOOL_NAME: Final = "web-search-tool___WebSearch"
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"
+# called statelessly, without an initialize handshake to negotiate a version.
+# AgentCore gateways whose protocolConfiguration leaves supportedVersions unset
+# accept only 2025-03-26 and reject anything newer with a -32600 error, so that
+# is the default; a gateway pinned to another version needs
+# AGENTCORE_MCP_PROTOCOL_VERSION set to match.
+AGENTCORE_DEFAULT_MCP_PROTOCOL_VERSION: Final = "2025-03-26"
# Matched against the URL host so a crafted path or query string can't pass for
# a gateway hostname.
@@ -168,7 +171,8 @@ class AgentCoreSearchConfig(BaseSearchConfig, BaseAWSLLM):
**headers,
"Content-Type": "application/json",
"Accept": "application/json, text/event-stream",
- "MCP-Protocol-Version": AGENTCORE_MCP_PROTOCOL_VERSION,
+ "MCP-Protocol-Version": get_secret_str("AGENTCORE_MCP_PROTOCOL_VERSION")
+ or AGENTCORE_DEFAULT_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 889f78c58b9..78808542c82 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
@@ -14,7 +14,7 @@ from unittest.mock import AsyncMock, patch, MagicMock
import litellm
from litellm.llms.bedrock.search.transformation import (
- AGENTCORE_MCP_PROTOCOL_VERSION,
+ AGENTCORE_DEFAULT_MCP_PROTOCOL_VERSION,
AgentCoreSearchConfig,
)
@@ -157,7 +157,20 @@ class TestAgentCoreSearch:
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
+ assert headers["MCP-Protocol-Version"] == AGENTCORE_DEFAULT_MCP_PROTOCOL_VERSION
+
+ def test_default_protocol_version_is_the_agentcore_gateway_default(self):
+ """A default AgentCore gateway supports only 2025-03-26 and answers
+ -32600 to anything newer, so that exact revision must be the default."""
+ assert AGENTCORE_DEFAULT_MCP_PROTOCOL_VERSION == "2025-03-26"
+
+ def test_protocol_version_env_override_wins(self):
+ """A gateway pinned to a newer supportedVersions list needs the header
+ to match, so AGENTCORE_MCP_PROTOCOL_VERSION must override the default."""
+ config = AgentCoreSearchConfig()
+ with patch.dict(os.environ, {"AGENTCORE_MCP_PROTOCOL_VERSION": "2025-06-18"}):
+ headers = config.validate_environment(headers={})
+ assert headers["MCP-Protocol-Version"] == "2025-06-18"
def test_protocol_version_header_survives_signing(self):
"""Both auth paths must keep the MCP-Protocol-Version header on the wire."""
@@ -171,7 +184,7 @@ class TestAgentCoreSearch:
api_base=GATEWAY_URL,
api_key="test-jwt-token",
)
- assert bearer_headers["MCP-Protocol-Version"] == AGENTCORE_MCP_PROTOCOL_VERSION
+ assert bearer_headers["MCP-Protocol-Version"] == AGENTCORE_DEFAULT_MCP_PROTOCOL_VERSION
with patch.dict(
os.environ,
@@ -187,7 +200,7 @@ class TestAgentCoreSearch:
api_base=GATEWAY_URL,
)
assert signed_headers["Authorization"].startswith("AWS4-HMAC-SHA256")
- assert signed_headers["MCP-Protocol-Version"] == AGENTCORE_MCP_PROTOCOL_VERSION
+ assert signed_headers["MCP-Protocol-Version"] == AGENTCORE_DEFAULT_MCP_PROTOCOL_VERSION
def test_transform_search_response_parses_sse_frame(self):
"""Gateway may answer with an SSE-framed JSON-RPC message."""