-
Notifications
You must be signed in to change notification settings - Fork 701
fix(sse): don't throw error when get http.StatusNoContent #312
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?
fix(sse): don't throw error when get http.StatusNoContent #312
Conversation
WalkthroughThe changes expand the set of HTTP status codes considered successful in the Changes
Assessment against linked issues
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (1.64.8)Error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2 Note ⚡️ AI Code Reviews for VS Code, Cursor, WindsurfCodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback. Note ⚡️ Faster reviews with cachingCodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure ✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Signed-off-by: ZheNing Hu <[email protected]>
22083f9
to
c0c5890
Compare
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.
Actionable comments posted: 1
🧹 Nitpick comments (1)
client/transport/streamable_http.go (1)
375-376
: Reduce duplication in status-code checks
The success check for OK/Accepted/NoContent is duplicated inSendRequest
andSendNotification
. Extract a helper to improve maintainability and keep both methods in sync:+// isSuccessStatus returns true for HTTP codes that should not be treated as errors. +func isSuccessStatus(code int) bool { + return code == http.StatusOK || + code == http.StatusAccepted || + code == http.StatusNoContent +}Then use it in both places:
- if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusAccepted && - resp.StatusCode != http.StatusNoContent { + if !isSuccessStatus(resp.StatusCode) { // ... }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting
📒 Files selected for processing (2)
client/transport/sse.go
(2 hunks)client/transport/streamable_http.go
(2 hunks)
🔇 Additional comments (2)
client/transport/sse.go (2)
303-304
: LGTM: Consistent handling of http.StatusNoContent in SSE transportThis change correctly adds HTTP 204 (No Content) to the list of acceptable status codes in the SSE implementation, matching the changes in the StreamableHTTP transport. This ensures the SendRequest method properly handles the NoContent response during SSE server initialization.
379-380
: LGTM: Properly updated SendNotification to accept 204 statusGood job ensuring consistent behavior by applying the same status code acceptance pattern to the SendNotification method. This change properly aligns with the PR's objective to fix the SSE initialization issue when the server returns HTTP 204 NoContent.
if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusAccepted && | ||
resp.StatusCode != http.StatusNoContent { |
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.
Missing post-check handling for HTTP 204 No Content
While you’ve expanded the success criteria to include StatusNoContent, the code still falls through to content-type parsing, which will error out on 204 (no Content-Type header). You need to short-circuit and return immediately when you see a 204.
Apply a special-case early return for NoContent, for example:
if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusAccepted &&
resp.StatusCode != http.StatusNoContent {
// existing error handling…
}
+
+ // Handle 204 No Content explicitly: valid success with empty body
+ if resp.StatusCode == http.StatusNoContent {
+ return nil, nil
+ }
Please confirm that callers of SendRequest
can handle a (nil, nil)
response appropriately, or adjust to return an empty JSONRPCResponse
if needed.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusAccepted && | |
resp.StatusCode != http.StatusNoContent { | |
if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusAccepted && | |
resp.StatusCode != http.StatusNoContent { | |
// existing error handling… | |
} | |
// Handle 204 No Content explicitly: valid success with empty body | |
if resp.StatusCode == http.StatusNoContent { | |
return nil, nil | |
} |
🤖 Prompt for AI Agents
In client/transport/streamable_http.go around lines 185 to 186, the code
includes HTTP 204 No Content as a success status but does not handle it properly
afterward, leading to errors when parsing a missing Content-Type header. Add an
early return immediately after detecting a 204 status code to avoid further
processing. Confirm that the SendRequest callers can handle a nil response and
nil error, or alternatively return an empty JSONRPCResponse to prevent
downstream issues.
In our scenario, the successful return value of the MCP SSE server initialize request is 204 NoContent, which currently causes the SSE initialization to fail. Therefore, modify the sendRequest function to also handle http.StatusNoContent to prevent errors from being thrown.
just reopen #153
may fix #217
Summary by CodeRabbit