Skip to content

feat: implement MCP protocol version header support #404

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 2 commits into from
Jul 30, 2025

Conversation

tzolov
Copy link
Contributor

@tzolov tzolov commented Jul 16, 2025

Add MCP-Protocol-Version header to all HTTP requests as required by MCP specification 2025-06-18. This enables proper server-side version negotiation and backwards compatibility handling.

  • Add protocol version constants (2025-06-18 for streamable HTTP, 2024-11-05 for SSE)
  • Include MCP-Protocol-Version header in all GET/POST/DELETE requests
  • Update WebClientStreamableHttpTransport, WebFluxSseClientTransport, HttpClientSseClientTransport, and HttpClientStreamableHttpTransport

Complies with MCP specification requirement that HTTP clients MUST include protocol version header on all requests to MCP servers.

Related to #398 , #363 , #250

Implementation Details:

  • Added MCP_PROTOCOL_VERSION and MCP_PROTOCOL_VERSION_HEADER_NAME constants to all HTTP transport classes
  • Uses protocol version 2025-06-18 for streamable HTTP transports (WebClientStreamableHttpTransport, HttpClientStreamableHttpTransport)
  • Uses protocol version 2024-11-05 for SSE transports (WebFluxSseClientTransport, HttpClientSseClientTransport) for backwards compatibility
  • Header is included in all HTTP requests (GET, POST, DELETE) across all transport implementations

Specification Reference:

This change ensures full compliance with the MCP specification requirement that "the client MUST include the MCP-Protocol-Version HTTP header on all subsequent requests to the MCP server."

Add MCP protocol version header support to all HTTP transport implementations as required by MCP specification 2025-06-18.

Motivation and Context

The MCP specification 2025-06-18 requires that HTTP clients MUST include the MCP-Protocol-Version header on all requests to MCP servers. This enables:
Without this header, servers cannot properly handle version-specific behavior and may not function correctly with clients using different protocol versions.

How Has This Been Tested?

  • All existing unit tests pass with the changes
  • HTTP requests now include the MCP-Protocol-Version header in all transport implementations
  • Tested with both streamable HTTP transport (2025-06-18) and SSE transport (2024-11-05) scenarios
  • Verified header is included in GET, POST, and DELETE requests across all affected transport classes

Breaking Changes

No breaking changes. This is a backwards-compatible addition:

  • Existing client code continues to work without modification
  • Only adds required headers to HTTP requests
  • Servers that don't check for the header will continue to function normally
  • Maintains backwards compatibility with older MCP protocol versions

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

@tzolov tzolov added this to the 0.11.0 milestone Jul 16, 2025
@kenneth-bro
Copy link

how to config ?

tzolov added 2 commits July 30, 2025 22:22
Add MCP-Protocol-Version header to all HTTP requests as required by
MCP specification 2025-06-18. This enables proper server-side version
negotiation and backwards compatibility handling.

- Add protocol version constants (2025-06-18 for streamable HTTP, 2024-11-05 for SSE)
- Include MCP-Protocol-Version header in all GET/POST/DELETE requests
- Update WebClientStreamableHttpTransport, WebFluxSseClientTransport,
  HttpClientSseClientTransport, and HttpClientStreamableHttpTransport

Complies with MCP specification requirement that HTTP clients MUST
include protocol version header on all requests to MCP servers.

Related to #398 , #363 , #250

Signed-off-by: Christian Tzolov <[email protected]>
- Add protocolVersion() method to transport and transport provider interfaces and implementations
- Replace hardcoded HTTP header strings with HttpHeaders constants
- Update protocol versions to be transport-specific rather than global
- Deprecate McpSchema.LATEST_PROTOCOL_VERSION in favor of transport-specific versions
- Standardize header names: MCP-Protocol-Version, mcp-session-id, last-event-id
- Update clients and servers to use transport.protocolVersion() for initialization
- Refactor tests to use transport-specific protocol versions

This change improves maintainability by centralizing header name constants
and allows different transports to support different protocol versions
independently.

Signed-off-by: Christian Tzolov <[email protected]>
@tzolov tzolov force-pushed the add-protocol-version-header branch from b9c6c90 to c477064 Compare July 30, 2025 20:23
@tzolov tzolov marked this pull request as ready for review July 30, 2025 21:10
@tzolov tzolov merged commit 9d58621 into main Jul 30, 2025
1 of 2 checks passed
@tzolov tzolov deleted the add-protocol-version-header branch July 30, 2025 21:54
@SightStudio
Copy link

@tzolov

public static final String LATEST_PROTOCOL_VERSION = "2025-03-26";

i see that

LATEST_PROTOCOL_VERSION = "2025-03-26";

in sourc code

Did you mean 2025-03-26? not 2025-06-18

because release note said 2025-06-18 either
https://github.com/modelcontextprotocol/java-sdk/releases/tag/v0.11.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants