-
Notifications
You must be signed in to change notification settings - Fork 104
Fix StreamableHttpServerTransport review comments #112
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
base: main
Are you sure you want to change the base?
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
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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();
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.