Repository navigation
fix(host): self-contained MCP tool schemas; skip a failing tool instead of the whole mount - #671
Merged
Merged
Conversation
…ad of the whole mount (#670) mountMcpRoute copied parameter and request-body schemas into each tool's inputSchema without spec.components, so any $ref (e.g. from a recursive z.json() input) failed Ajv compilation in fromJsonSchema. With no per-tool error handling, that one failure aborted the mount and /api/mcp returned 404. Copy referenced component schemas into $defs with refs rewritten, and log and skip any tool whose schema still fails to compile.
Contributor
Review: approveThe approach is correct and the test is real (real oRPC contract → real Correctness checks (all pass):
Nits (non-blocking):
|
…not be resolved (#670 follow-up)
Contributor
|
Pushed two follow-up commits addressing the review nits:
Verified: host Left as-is (deliberately, to keep this PR small): #670 suggestion 3 ( |
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.
Closes #670.
Problem
mountMcpRoutebuilds each tool'sinputSchemafrom the operation's parameters and JSON body properties, but it dropsspec.components. A$refin an input (any recursive zod schema, e.g.z.json()) therefore fails Ajv compilation insidefromJsonSchema. There's no per-tool error handling, so that one failure aborts the whole mount. The host logs[MCP] Failed to mount /api/mcp, and/api/mcpreturns 404 while/.well-known/mcp.jsonstill advertises it. activity.nearbuilders.org hit this with apayload: z.json()body: 51 tools, 1 failed, MCP gone. That app has worked around it in NEARBuilders/activity.nearbuilders.org#109.Fix
buildToolInputSchema(operation, componentSchemas)(extracted from the loop) collects the#/components/schemas/*refs that the inputs reach, follows them transitively, copies those entries into$defs, and rewrites the refs to#/$defs/*. Inputs without refs come out the same as before.[MCP] Skipping tool "<id>": …and moves on, instead of dropping the whole route.Tests
host/tests/unit/mcp-tool-schema.test.tsgenerates a real spec from an oRPC contract with az.json()body. It asserts the tool schema has no#/components/refs, compiles withfromJsonSchema, validates nested JSON, and still enforcesrequired. Without the fix, the recursive case fails. A second case pins that ref-free inputs are unchanged.tsc --noEmitandbiome check hostare clean, and host unit tests pass (101). I couldn't run theoxlinttype-aware pass locally because its config failed to load here (Unknown plugin: 'effecttsgo'), so it's left to CI.Not included: suggestion 3 from #670 (only advertise
/api/mcpin/.well-known/mcp.jsonafter a successful mount).