Return JSON-RPC errors for expired sessions#4426
Merged
amirejaz merged 2 commits intostacklok:mainfrom Mar 30, 2026
Merged
Conversation
ToolHive's proxies returned plain-text HTTP errors for expired or unknown sessions. MCP clients like Claude Code rely on receiving HTTP 404 with a JSON-RPC error body containing code -32001 to trigger automatic session recovery. The plain-text responses bypassed this detection, leaving connections broken until the user manually restarted their client. Fixes stacklok#4425 Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Greg Katz <gkatz@indeed.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4426 +/- ##
==========================================
- Coverage 69.50% 69.49% -0.02%
==========================================
Files 486 487 +1
Lines 50017 50044 +27
==========================================
+ Hits 34766 34776 +10
- Misses 12570 12584 +14
- Partials 2681 2684 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
The revive linter requires exported constants to have doc comments. The blank line between the two constants in the const block means they need individual comments. Signed-off-by: Greg Katz <gkatz@indeed.com>
amirejaz
approved these changes
Mar 30, 2026
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
Fixes #4425
Type of change
Test plan
task test)task lint-fix)Built from the fix branch and started MCP servers exercising all three proxy types. Verified with curl that requests with a bogus
Mcp-Session-Idreturn HTTP 404 withContent-Type: application/jsonand"code":-32001in the JSON-RPC error body:--proxy-mode sse)Changes
pkg/transport/session/jsonrpc_errors.goWriteNotFound,NotFoundResponse,NotFoundBody)pkg/transport/session/jsonrpc_errors_test.gopkg/transport/proxy/streamable/streamable_proxy.gosession.WriteNotFoundpkg/transport/proxy/transparent/transparent_proxy.gosession.NotFoundResponse, fix status 400→404pkg/transport/proxy/httpsse/http_proxy.gosession.WriteNotFoundpkg/transport/proxy/streamable/streamable_proxy_spec_test.gopkg/transport/proxy/transparent/backend_routing_test.gopkg/transport/proxy/httpsse/http_proxy_test.goDoes this introduce a user-facing change?
MCP clients that implement session recovery (checking for HTTP 404 with JSON-RPC error code -32001) will now be able to automatically recover from session expiry without requiring a client restart.
Generated with Claude Code