Conversation
The per-backend response collector and the response proxy decided whether to parse a backend response as JSON via an exact string comparison on the Content-Type header. A backend responding with application/json;charset=UTF-8 (the servlet-container default emitted by the MCP Java SDK's servlet transports) failed that check, fell through to the SSE parser, and produced zero events with no error, so its tools/list response was silently dropped. Parse the media type with mime.ParseMediaType and match on application/json, ignoring parameters such as charset. Signed-off-by: Vladimir Babin <vovababin@gmail.com>
…entrouter#2587 The charset-tolerant Content-Type match landed in theagentrouter#2587, which added isJSONContentType in sse.go. Remove the duplicate implementation (and the now-unused mime import) from session.go per review; the additive regression test (JSON response with charset=UTF-8 yields one decoded event) is kept and now exercises the shared helper. Signed-off-by: chiliec <vovababin@gmail.com>
Author
|
Thanks — you're right, #2587 already covers the charset-tolerant match. I've deleted the now-duplicate Kept the additive regression test ( |
Contributor
|
lgtm |
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.
Description
The MCP proxy's per-backend response collector (
session.go) and the response proxy (handlers.go) decided whether to parse a backend response as JSON via an exact string comparison on theContent-Typeheader (== "application/json").A backend responding with
Content-Type: application/json;charset=UTF-8— the servlet-container default emitted by the official MCP Java SDK's servlet transports (HttpServletStatelessServerTransport, which doessetContentType("application/json")+setCharacterEncoding("UTF-8")) — failed that check. The body fell through to the SSE parser, which found nodata:lines and yielded zero events and zero errors, so the backend'stools/listresponse was silently discarded (connected-but-toolless, nothing logged).This parses the media type with
mime.ParseMediaTypeand matches on theapplication/jsonmedia type, ignoring parameters likecharset(per RFC 9110 §8.3;charsetis meaningless forapplication/jsonper RFC 8259 §8.1). A small sharedisJSONContentTypehelper replaces the three exact-match sites in the package (sendRequestPerBackend,copyProxyHeaders,proxyResponseBody).Related Issues/PRs (if applicable)
Fixes #2568
Special notes for reviewers (if applicable)
Added a regression test
TestSendRequestPerBackend_JSONContentTypeWithCharsetmirroring the existingTestSendRequestPerBackend_BOMPrefixedJSON, using a backend that returnsapplication/json;charset=UTF-8.Verification (Go 1.26.6,
go test ./internal/mcpproxy/):session.godispatch back to the exact string match makes the new test fail withDiff: -message / +(0 events collected); restoring the fix makes it pass.internal/mcpproxypackage suite green (ok ... 2.980s),go vetandgofmt -lclean on the touched files.AI-assisted; all results above are from real local runs. Happy to adjust.