mcp-go
mcp-go copied to clipboard
fix: SSE client hangs after 30 seconds
In #55, an option was added to set an sse read timeout. This timeout, however, applies to the entire readSSE function which is responsible for receiving messages from the server after the client's initialization. Because of this, any SSE client stops working 30 seconds after initialization. Any request hangs because no responses are being processed.
The original author mentioned parity with the Python SDK as a justification for adding this option. However, in the python SDK, the timeout applies to a specific call, not to the entire message loop. In Go, callers can directly create their context with a given timeout or deadline without a specific option for timeouts.
For this reason, I would recommend removing the option altogether.
Summary by CodeRabbit
- Refactor
- Updated real-time event stream handling by removing the configurable read timeout setting. SSE connections now conclude based on connection termination signals rather than a preset timeout, resulting in a more straightforward and consistent streaming experience.
Walkthrough
This pull request simplifies the SSE client setup by removing the timeout mechanism previously used to terminate read operations. The changes include removing the sseReadTimeout field from the SSEMCPClient struct and eliminating the WithSSEReadTimeout function from client initialization. Additionally, the readSSE method is updated to check for the closure of the done channel instead of using a context with a timeout, thereby altering the control flow for handling long-running SSE connections.
Changes
| File(s) | Changes |
|---|---|
| client/sse.go | Removed the sseReadTimeout field from the SSEMCPClient struct and the WithSSEReadTimeout function. Modified NewSSEMCPClient to omit the default timeout and updated readSSE to rely on the done channel instead of a context timeout. |
Possibly related PRs
- mark3labs/mcp-go#65: Modifies the
readSSEmethod to enhance its implementation and error handling, directly relating to the control flow changes made in this PR.
✨ Finishing Touches
- [ ] 📝 Generate Docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
🪧 Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
I pushed a fix in commit <commit_id>, please review it.Generate unit testing code for this file.Open a follow-up GitHub issue for this discussion.
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. Examples:@coderabbitai generate unit testing code for this file.@coderabbitai modularize this function.
- PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.@coderabbitai read src/utils.ts and generate unit testing code.@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.@coderabbitai help me debug CodeRabbit configuration file.
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.
CodeRabbit Commands (Invoked using PR comments)
@coderabbitai pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository.@coderabbitai full reviewto do a full review from scratch and review all the files again.@coderabbitai summaryto regenerate the summary of the PR.@coderabbitai generate docstringsto generate docstrings for this PR.@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai planto trigger planning for file edits and PR creation.@coderabbitai configurationto show the current CodeRabbit configuration for the repository.@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile to the root of your repository. - Please see the configuration documentation for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation:
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
Documentation and Community
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.
I am in favor of removing this in favor of a more Go aligned method of dealing with timeouts. However, maybe it would be good to add a test or, at a minimum, some documentation about how someone could use context to handle timeouts in the README
Are there any updates? The client is borken, should be fixed ASAP.
Are there any updates? The client is borken, should be fixed ASAP.
If it helps I have a tag with the fix that you can replace in go.mod pending this being merged:
replace github.com/mark3labs/mcp-go v0.17.0 => github.com/mrene/mcp-go v0.17.0-ssefix