fix: preserve upstream tool schemas verbatim through the stdio→HTTP relay#179
Open
avargaskun wants to merge 1 commit into
Open
fix: preserve upstream tool schemas verbatim through the stdio→HTTP relay#179avargaskun wants to merge 1 commit into
avargaskun wants to merge 1 commit into
Conversation
…elay Relay tools/list over the raw transport and carry the upstream inputSchema/ outputSchema bytes through RawInputSchema/RawOutputSchema so the proxy server re-emits them verbatim. Fixes dangling $ref (draft-07 definitions were rewritten to $defs without rewriting the matching #/definitions/... refs) and silently dropped root-level keywords ($schema, title, oneOf, ...). Graceful fallback to the typed ListTools path on error so tool discovery never regresses. Covered by fake-transport unit tests, in-process HTTP integration tests that read the proxy's raw wire bytes, and a real subprocess/stdio integration test. Tracking: sigbit#178 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
What
When
mcp-auth-proxyrelaystools/listfrom a stdio MCP server over the HTTP/mcpendpoint, the toolinputSchema/outputSchemanow reach the downstream client byte-for-byte identical to what the upstream emitted.Why
The relay round-tripped each schema through mcp-go's typed
ToolArgumentsSchema, which:definitions→$defswithout rewriting the matching#/definitions/...$reftargets, producing dangling refs that break JSON-Schema-validating clients (ajv, etc.); and$schema,title,oneOf, …).Both classes apply to
outputSchemaas well, which uses the same type.How
New helper
listToolsPreservingSchema(pkg/backend/toolschema.go) issuestools/listdirectly over the raw transport, parses the same response bytes twice (typedmcp.ListToolsResultfor metadata, a raw struct for the schema bytes), and carries the original schema bytes viaRawInputSchema/RawOutputSchemaso the proxy server re-emits them unchanged.setupProxycalls it in place ofc.ListTools, with a graceful fallback to the typed path on error (tool discovery never regresses to unavailable). No$refrewriting or schema normalization is done on our side. Prompts/resources handling and theNewStreamableHTTPServerconstruction are unchanged.Testing
client.ListToolsround-trip, which would re-normalize and mask the fix): draft-07definitions/$refpreserved, unmodeled root keywords preserved, native$defsback-compat, plain-schema back-compat,outputSchemapreserved, and multi-tool index alignment.go run ./testserver.gofmt -s,go vet,go build,go test ./...all green locally. (staticcheckruns here in CI — the current release can't analyze go1.26 locally.)Closes #178
🤖 Generated with Claude Code