Skip to content

Commit 32e64b6

Browse files
refactor: align protocol version header capitalization to lowercase (#911)
1 parent 14c3af8 commit 32e64b6

File tree

5 files changed

+9
-7
lines changed

5 files changed

+9
-7
lines changed

src/mcp/client/auth.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import anyio
1818
import httpx
1919

20+
from mcp.client.streamable_http import MCP_PROTOCOL_VERSION
2021
from mcp.shared.auth import (
2122
OAuthClientInformationFull,
2223
OAuthClientMetadata,
@@ -129,7 +130,7 @@ async def _discover_oauth_metadata(self, server_url: str) -> OAuthMetadata | Non
129130
# Extract base URL per MCP spec
130131
auth_base_url = self._get_authorization_base_url(server_url)
131132
url = urljoin(auth_base_url, "/.well-known/oauth-authorization-server")
132-
headers = {"MCP-Protocol-Version": LATEST_PROTOCOL_VERSION}
133+
headers = {MCP_PROTOCOL_VERSION: LATEST_PROTOCOL_VERSION}
133134

134135
async with httpx.AsyncClient() as client:
135136
try:

src/mcp/client/streamable_http.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
GetSessionIdCallback = Callable[[], str | None]
4141

4242
MCP_SESSION_ID = "mcp-session-id"
43-
MCP_PROTOCOL_VERSION = "MCP-Protocol-Version"
43+
MCP_PROTOCOL_VERSION = "mcp-protocol-version"
4444
LAST_EVENT_ID = "last-event-id"
4545
CONTENT_TYPE = "content-type"
4646
ACCEPT = "Accept"

src/mcp/server/auth/routes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from mcp.server.auth.middleware.client_auth import ClientAuthenticator
1717
from mcp.server.auth.provider import OAuthAuthorizationServerProvider
1818
from mcp.server.auth.settings import ClientRegistrationOptions, RevocationOptions
19+
from mcp.server.streamable_http import MCP_PROTOCOL_VERSION_HEADER
1920
from mcp.shared.auth import OAuthMetadata
2021

2122

@@ -59,7 +60,7 @@ def cors_middleware(
5960
app=request_response(handler),
6061
allow_origins="*",
6162
allow_methods=allow_methods,
62-
allow_headers=["mcp-protocol-version"],
63+
allow_headers=[MCP_PROTOCOL_VERSION_HEADER],
6364
)
6465
return cors_app
6566

src/mcp/server/streamable_http.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646

4747
# Header names
4848
MCP_SESSION_ID_HEADER = "mcp-session-id"
49-
MCP_PROTOCOL_VERSION_HEADER = "MCP-Protocol-Version"
49+
MCP_PROTOCOL_VERSION_HEADER = "mcp-protocol-version"
5050
LAST_EVENT_ID_HEADER = "last-event-id"
5151

5252
# Content types

tests/shared/test_streamable_http.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,7 +1482,7 @@ async def test_streamablehttp_request_context_isolation(
14821482
async def test_client_includes_protocol_version_header_after_init(
14831483
context_aware_server, basic_server_url
14841484
):
1485-
"""Test that client includes MCP-Protocol-Version header after initialization."""
1485+
"""Test that client includes mcp-protocol-version header after initialization."""
14861486
async with streamablehttp_client(f"{basic_server_url}/mcp") as (
14871487
read_stream,
14881488
write_stream,
@@ -1502,7 +1502,7 @@ async def test_client_includes_protocol_version_header_after_init(
15021502

15031503
# Verify protocol version header is present
15041504
assert "mcp-protocol-version" in headers_data
1505-
assert headers_data["mcp-protocol-version"] == negotiated_version
1505+
assert headers_data[MCP_PROTOCOL_VERSION_HEADER] == negotiated_version
15061506

15071507

15081508
def test_server_validates_protocol_version_header(basic_server, basic_server_url):
@@ -1585,7 +1585,7 @@ def test_server_backwards_compatibility_no_protocol_version(
15851585
assert init_response.status_code == 200
15861586
session_id = init_response.headers.get(MCP_SESSION_ID_HEADER)
15871587

1588-
# Test request without MCP-Protocol-Version header (backwards compatibility)
1588+
# Test request without mcp-protocol-version header (backwards compatibility)
15891589
response = requests.post(
15901590
f"{basic_server_url}/mcp",
15911591
headers={

0 commit comments

Comments
 (0)