From f2524de12da48a0610c43101aca8ac14fd89189b Mon Sep 17 00:00:00 2001 From: Felix Weinberger Date: Mon, 9 Jun 2025 19:22:24 +0100 Subject: [PATCH] refactor: align protocol version header capitalization to lowercase Standardize the MCP protocol version header name to lowercase "mcp-protocol-version" across the entire codebase for consistency. This change affects: - Client auth module - Client streamable HTTP transport - Server auth routes - Server streamable HTTP transport - Test files The lowercase format aligns with common HTTP header conventions and ensures consistent header handling throughout the SDK. --- src/mcp/client/auth.py | 3 ++- src/mcp/client/streamable_http.py | 2 +- src/mcp/server/auth/routes.py | 3 ++- src/mcp/server/streamable_http.py | 2 +- tests/shared/test_streamable_http.py | 6 +++--- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/mcp/client/auth.py b/src/mcp/client/auth.py index fc6c96a43..061e0161d 100644 --- a/src/mcp/client/auth.py +++ b/src/mcp/client/auth.py @@ -17,6 +17,7 @@ import anyio import httpx +from mcp.client.streamable_http import MCP_PROTOCOL_VERSION from mcp.shared.auth import ( OAuthClientInformationFull, OAuthClientMetadata, @@ -129,7 +130,7 @@ async def _discover_oauth_metadata(self, server_url: str) -> OAuthMetadata | Non # Extract base URL per MCP spec auth_base_url = self._get_authorization_base_url(server_url) url = urljoin(auth_base_url, "/.well-known/oauth-authorization-server") - headers = {"MCP-Protocol-Version": LATEST_PROTOCOL_VERSION} + headers = {MCP_PROTOCOL_VERSION: LATEST_PROTOCOL_VERSION} async with httpx.AsyncClient() as client: try: diff --git a/src/mcp/client/streamable_http.py b/src/mcp/client/streamable_http.py index 7a3a3612d..ef2213188 100644 --- a/src/mcp/client/streamable_http.py +++ b/src/mcp/client/streamable_http.py @@ -40,7 +40,7 @@ GetSessionIdCallback = Callable[[], str | None] MCP_SESSION_ID = "mcp-session-id" -MCP_PROTOCOL_VERSION = "MCP-Protocol-Version" +MCP_PROTOCOL_VERSION = "mcp-protocol-version" LAST_EVENT_ID = "last-event-id" CONTENT_TYPE = "content-type" ACCEPT = "Accept" diff --git a/src/mcp/server/auth/routes.py b/src/mcp/server/auth/routes.py index d588d78ee..394a67e7e 100644 --- a/src/mcp/server/auth/routes.py +++ b/src/mcp/server/auth/routes.py @@ -16,6 +16,7 @@ from mcp.server.auth.middleware.client_auth import ClientAuthenticator from mcp.server.auth.provider import OAuthAuthorizationServerProvider from mcp.server.auth.settings import ClientRegistrationOptions, RevocationOptions +from mcp.server.streamable_http import MCP_PROTOCOL_VERSION_HEADER from mcp.shared.auth import OAuthMetadata @@ -59,7 +60,7 @@ def cors_middleware( app=request_response(handler), allow_origins="*", allow_methods=allow_methods, - allow_headers=["mcp-protocol-version"], + allow_headers=[MCP_PROTOCOL_VERSION_HEADER], ) return cors_app diff --git a/src/mcp/server/streamable_http.py b/src/mcp/server/streamable_http.py index 89cdac908..b5578d775 100644 --- a/src/mcp/server/streamable_http.py +++ b/src/mcp/server/streamable_http.py @@ -46,7 +46,7 @@ # Header names MCP_SESSION_ID_HEADER = "mcp-session-id" -MCP_PROTOCOL_VERSION_HEADER = "MCP-Protocol-Version" +MCP_PROTOCOL_VERSION_HEADER = "mcp-protocol-version" LAST_EVENT_ID_HEADER = "last-event-id" # Content types diff --git a/tests/shared/test_streamable_http.py b/tests/shared/test_streamable_http.py index 67373bda5..85b834ae3 100644 --- a/tests/shared/test_streamable_http.py +++ b/tests/shared/test_streamable_http.py @@ -1482,7 +1482,7 @@ async def test_streamablehttp_request_context_isolation( async def test_client_includes_protocol_version_header_after_init( context_aware_server, basic_server_url ): - """Test that client includes MCP-Protocol-Version header after initialization.""" + """Test that client includes mcp-protocol-version header after initialization.""" async with streamablehttp_client(f"{basic_server_url}/mcp") as ( read_stream, write_stream, @@ -1502,7 +1502,7 @@ async def test_client_includes_protocol_version_header_after_init( # Verify protocol version header is present assert "mcp-protocol-version" in headers_data - assert headers_data["mcp-protocol-version"] == negotiated_version + assert headers_data[MCP_PROTOCOL_VERSION_HEADER] == negotiated_version def test_server_validates_protocol_version_header(basic_server, basic_server_url): @@ -1585,7 +1585,7 @@ def test_server_backwards_compatibility_no_protocol_version( assert init_response.status_code == 200 session_id = init_response.headers.get(MCP_SESSION_ID_HEADER) - # Test request without MCP-Protocol-Version header (backwards compatibility) + # Test request without mcp-protocol-version header (backwards compatibility) response = requests.post( f"{basic_server_url}/mcp", headers={