10000 refactor: align protocol version header capitalization to lowercase (… · modelcontextprotocol/python-sdk@bb4eaab · GitHub
[go: up one dir, main page]

Skip to content

Commit bb4eaab

Browse files
refactor: align protocol version header capitalization to lowercase (#911)
1 parent d14666b commit bb4eaab

File tree

5 files changed

+15
-8
lines changed

5 files changed

+15
-8
lines changed

src/mcp/client/auth.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@
1717
import anyio
1818
import httpx
1919

20-
from mcp.shared.auth import OAuthClientInformationFull, OAuthClientMetadata, OAuthMetadata, OAuthToken
20+
from mcp.client.streamable_http import MCP_PROTOCOL_VERSION
21+
from mcp.shared.auth import (
22+
OAuthClientInformationFull,
23+
OAuthClientMetadata,
24+
OAuthMetadata,
25+
OAuthToken,
26+
)
2127
from mcp.types import LATEST_PROTOCOL_VERSION
2228

2329
logger = logging.getLogger(__name__)
@@ -121,7 +127,7 @@ async def _discover_oauth_metadata(self, server_url: str) -> OAuthMetadata | Non
121127
# Extract base URL per MCP spec
122128
auth_base_url = self._get_authorization_base_url(server_url)
123129
url = urljoin(auth_base_url, "/.well-known/oauth-authorization-server")
124-
headers = {"MCP-Protocol-Version": LATEST_PROTOCOL_VERSION}
130+
headers = {MCP_PROTOCOL_VERSION: LATEST_PROTOCOL_VERSION}
125131

126132
async with httpx.AsyncClient() as client:
127133
try:

src/mcp/client/streamable_http.py

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

4141
MCP_SESSION_ID = "mcp-session-id"
42-
MCP_PROTOCOL_VERSION = "MCP-Protocol-Version"
42+
MCP_PROTOCOL_VERSION = "mcp-protocol-version"
4343
LAST_EVENT_ID = "last-event-id"
4444
CONTENT_TYPE = "content-type"
4545
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

@@ -55,7 +56,7 @@ def cors_middleware(
5556
app=request_response(handler),
5657
allow_origins="*",
5758
allow_methods=allow_methods,
58-
allow_headers=["mcp-protocol-version"],
59+
allow_headers=[MCP_PROTOCOL_VERSION_HEADER],
5960
)
6061
return cors_app
6162

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
@@ -1415,7 +1415,7 @@ async def test_streamablehttp_request_context_isolation(context_aware_server: No
14151415
async def test_client_includes_protocol_version_header_after_init(
14161416
context_aware_server, basic_server_url
14171417
):
1418-
"""Test that client includes MCP-Protocol-Version header after initialization."""
1418+
"""Test that client includes mcp-protocol-version header after initialization."""
14191419
async with streamablehttp_client(f"{basic_server_url}/mcp") as (
14201420
read_stream,
14211421
write_stream,
@@ -1435,7 +1435,7 @@ async def test_client_includes_protocol_version_header_after_init(
14351435

14361436
# Verify protocol version header is present
14371437
assert "mcp-protocol-version" in headers_data
1438-
assert headers_data["mcp-protocol-version"] == negotiated_version
1438+
assert headers_data[MCP_PROTOCOL_VERSION_HEADER] == negotiated_version
14391439

14401440

14411441
def test_server_validates_protocol_version_header(basic_server, basic_server_url):
@@ -1518,7 +1518,7 @@ def test_server_backwards_compatibility_no_protocol_version(
15181518
assert init_response.status_code == 200
15191519
session_id = init_response.headers.get(MCP_SESSION_ID_HEADER)
15201520

1521-
# Test request without MCP-Protocol-Version header (backwards compatibility)
1521+
# Test request without mcp-protocol-version header (backwards compatibility)
15221522
response = requests.post(
15231523
f"{basic_server_url}/mcp",
15241524
headers={

0 commit comments

Comments
 (0)
0