8000 refactor: align protocol version header capitalization to lowercase by felixweinberger · Pull Request #911 · modelcontextprotocol/python-sdk · GitHub
[go: up one dir, main page]

Skip to content

refactor: align protocol version header capitalization to lowercase #911

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/mcp/client/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import anyio
import httpx

from mcp.client.streamable_http import MCP_PROTOCOL_VERSION
from mcp.shared.auth import (
OAuthClientInformationFull,
OAuthClientMetadata,
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/mcp/client/streamable_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion src/mcp/server/auth/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/mcp/server/streamable_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions tests/shared/test_streamable_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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):
Expand Down Expand Up @@ -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={
Expand Down
Loading
0