-
Notifications
You must be signed in to change notification settings - Fork 291
Clean streamable 2 #172
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
Clean streamable 2 #172
Conversation
Consolidate several maps into a single struct. Simplifies the code, for the most part.
- Move the done field above mu: it does not need the mutex to be held. - Use an atomic for signal, simplifying locking. - Return from servePOST and serveGET instead of calling http.Error. Each cleanup is in a separate commit.
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 PR refactors the streamable transport code to improve its structure and simplify locking mechanisms. The changes consolidate stream-related data into a single struct and optimize concurrency handling.
- Introduces a new
streamstruct to encapsulate stream-related fields and logic - Replaces the
signalsmap with atomic operations to reduce mutex contention - Refactors HTTP handlers to return status codes instead of calling
http.Errordirectly
Comments suppressed due to low confidence (2)
mcp/streamable.go:274
- [nitpick] The function name
signalChanPtris ambiguous. Consider renaming tonewSignalChannelPointerorcreateSignalChannelto better indicate it creates a new buffered channel pointer.
func signalChanPtr() *chan struct{} {
mcp/streamable.go:593
- [nitpick] The error message "session is closed" may not provide enough context for debugging. Consider including the session ID or operation context in the error message.
return errors.New("session is closed") // TODO: should this be EOF?
| // "After the JSON-RPC response has been sent, the server SHOULD close the SSE stream." | ||
| // §6.4, https://modelcontextprotocol.io/specification/2025-06-18/basic/transports#sending-messages-to-the-server | ||
| // TODO(jba): why not terminate regardless of http method? | ||
| // TODO(jba,findleyr): why not terminate regardless of http method? |
Copilot
AI
Jul 24, 2025
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.
[nitpick] This TODO comment raises an important design question about termination behavior but lacks sufficient context. Consider expanding the comment to explain the current behavior difference between GET and POST methods.
| // TODO(jba,findleyr): why not terminate regardless of http method? | |
| // TODO(jba,findleyr): The current behavior terminates the connection only for POST requests | |
| // when all outstanding requests have been handled. This is based on the assumption that | |
| // POST requests are used for sending data to the server, and once the data is processed, | |
| // the connection can be safely closed. For GET requests, the connection remains open to | |
| // allow for potential future responses or streaming data. This distinction aligns with | |
| // the intended use cases of these HTTP methods as per the specification: | |
| // §6.4, https://modelcontextprotocol.io/specification/2025-06-18/basic/transports#sending-messages-to-the-server. | |
| // Consider whether this distinction is necessary or if termination behavior should be | |
| // unified across all HTTP methods for simplicity and consistency. |
mcp: various cleanups to streamable code
Each cleanup is in a separate commit.