Fix StreamableHttpServerTransport review comments#112
Closed
michaellatman wants to merge 4 commits intomodelcontextprotocol:mainfrom
Closed
Fix StreamableHttpServerTransport review comments#112michaellatman wants to merge 4 commits intomodelcontextprotocol:mainfrom
michaellatman wants to merge 4 commits intomodelcontextprotocol:mainfrom
Conversation
- Clear callMapping in close() method to prevent memory leaks - Add comprehensive KDoc comments for all public APIs - Fix Accept header validation to use proper matching instead of contains - Fix ContentType header key to use HttpHeaders.ContentType - Fix parseBody error message for invalid JSON format - Add unit tests for StreamableHttpServerTransport
Author
|
Definitely, I’ll need to revisit this. If no one else gets to it, I’ll probably come work on the client project as well. |
Contributor
There was a problem hiding this comment.
Pull Request Overview
This pull request refactors the StreamableHttpServerTransport implementation by addressing review comments, improving API documentation, and refining header validation and error handling.
- Improved KDoc documentation for public APIs
- Enhanced header validation logic and updated error messages
- Added comprehensive unit tests for the transport’s behavior
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/jvmTest/kotlin/server/StreamableHttpServerTransportTest.kt | Added unit tests to verify start/close behavior, message and error callbacks, and flag handling |
| src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/types.kt | Made the response id field nullable to support error responses without valid ids |
| src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/shared/Constants.kt | Introduced a constant for the MCP session header |
| src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/server/StreamableHttpServerTransport.kt | Updated header validation, session management, JSON response handling, and documented API methods |
Comments suppressed due to low confidence (2)
src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/server/StreamableHttpServerTransport.kt:109
- In the non-JSON response branch (lines 109–112), the callMapping entry is not removed after sending a message. Consider also cleaning up the callMapping (e.g., callMapping.remove(streamId)) to avoid potential resource leaks.
} else {
src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/server/StreamableHttpServerTransport.kt:288
- [nitpick] Consider either implementing the flush of headers as indicated by the TODO comment or, if deferred intentionally, add a comment clarifying why this behavior is not required to improve clarity for future maintenance.
// TODO: Equivalent of typescript res.writeHead(200, headers).flushHeaders();
Contributor
|
Obsolete |
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.
Summary
This PR addresses all review comments from PR #87:
Changes
Documentation
Header Validation
Bug Fixes
CallMapping Handling
Tests
Disclaimer
Note: I have not yet tried this library with a full application - I just wanted to help kick the stale review from PR #87. I can come back with more thorough testing around June 12 if you need additional help.
Test Results
All tests are passing successfully.