fix: improve streamable HTTP session reinitialization#469
Closed
tzolov wants to merge 7 commits intomodelcontextprotocol:mainfrom
Closed
fix: improve streamable HTTP session reinitialization#469tzolov wants to merge 7 commits intomodelcontextprotocol:mainfrom
tzolov wants to merge 7 commits intomodelcontextprotocol:mainfrom
Conversation
e45be72 to
87409d3
Compare
Implements the MCP spec guidelines for streamable HTTP (re)initialization: - Server MAY terminate session and MUST respond with HTTP 404 for terminated session IDs - Client MUST start new session when receiving HTTP 404 for requests with session ID Changes: - Replace generic McpError with McpTransportException for transport-layer errors - Only throw McpTransportSessionNotFoundException when session ID is present in request (per spec: 404 with session ID means session terminated, without means general error) - Enhance error messages with more context (status codes, response events) - Use RuntimeException for non-transport specific SSE endpoint failures - Ensure consistent error handling across HTTP client transports Fixes modelcontextprotocol#459 Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
Replace generic McpError with appropriate standard exceptions: - Use IllegalArgumentException for invalid input parameters - Use IllegalStateException for state-related issues - Use RuntimeException wrapper for initialization failures - Use McpError.builder() with proper error codes for protocol errors This change improves error handling clarity and follows Java best practices by using more specific exception types that better describe the error conditions. Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
Contributor
Author
|
Rebase, squashed and merged at 6c38f37 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements the MCP spec guidelines for streamable HTTP (re)initialization:
Changes:
Fixes #459
Motivation and Context
This change addresses issue #459 and implements the MCP specification requirements for streamable HTTP (re)initialization:
McpTransportSessionNotFoundExceptionfor any 404/400 response, even when no session ID was present, which didn't align with the spec.McpErrorfor transport-layer issues made it difficult to distinguish between different error types and handle them appropriately.This fix ensures proper session reinitialization flow where clients can detect terminated sessions (404 with session ID) and start fresh sessions without an ID.
How Has This Been Tested?
Breaking Changes
Minor breaking changes for users who catch specific exception types:
McpErrorfor transport errors will need to catchMcpTransportExceptioninsteadTypes of changes
Checklist