Skip to content

fix(mcp): advertise JSON values without recursive schemas - #995

Merged
N0zoM1z0 merged 4 commits into
mainfrom
fix/non-recursive-json-schemas
Oct 8, 2026
Merged

N0zoM1z0 merged 4 commits into
mainfrom
fix/non-recursive-json-schemas

Conversation

@kaoru0822-kitauji

Copy link
Copy Markdown
Collaborator

Summary

z.json() projects a self-referential definition:

"__schema0": { "anyOf": [ …, {"type":"array","items":{"$ref":"#/$defs/__schema0"}},
  {"type":"object","additionalProperties":{"$ref":"#/$defs/__schema0"}} ] }

On main, 20 of 133 tool input schemas and 123 output schemas carry it. Clients and model APIs that reject recursive JSON Schemas refuse the whole tool list (#919: Recursive JSON schemas are not currently supported).

Every JSON value satisfies {}, so the shared jsonValueSchema now advertises {} through Zod's per-schema toJSONSchema override. The two contracts that called z.json() directly (errorSchemas.ts, the MCP doctor catalog output) now use jsonValueSchema. The fix sits on the schema rather than on registration. That covers the live server, z.toJSONSchema users, the generated catalog, and docs/error-contract.schema.json.

Runtime parsing is unchanged: jsonValueSchema still rejects undefined, non-finite numbers, functions, and nested non-JSON values.

This differs from the closed #923, which rewrote cyclic $refs after projection at registration.

Scope

Refs #919, not Fixes: this removes the recursion only. Measured after this change over the live tool list ($refs now absent):

check main this PR
input schemas with a recursive $ref 20 0
output schemas with a recursive $ref 123 0
schemas using $defs at all 143 0
max input depth, object/array levels 11 11 (compare_web_captures)

The reported depth limit of 10 still applies to compare_web_captures, whose input embeds whole web-capture inspections. The issue leaves the remedy for that to maintainer choice (compact inputs vs. lowering the wire schema), so this PR does not change it.

Verification

  • src/domain/jsonValue.test.ts (new): projection has no $ref/$defs for input and output, Ajv 2020 accepts nested JSON and still rejects a non-object map; runtime parsing still rejects non-JSON values.
  • tests/boundary/mcp/toolSchemaValidity.test.ts: new recursiveReferences check over the live listTools result and GENERATED_MCP_TOOL_CATALOG. Before regenerating, the catalog assertion failed with 147 recursive references; it passes after.
  • npm run check:changed: typecheck, lint, 135 files / 1303 tests passed.
  • All tests/boundary/mcp/*.test.ts (after npm run build:cached): 56 files passed, 2 skipped.
  • npm run docs:generate then npm run docs:check: passed.
  • Built dist/main.js over real stdio MCP: 133 tools, 0 recursive schemas.

Not verified: a real opencode + Muse Spark 1.3 run. No Hopper/Ghidra/IDA verification is relevant.

🤖 Generated with Claude Code

`z.json()` projects a self-referential `$defs/__schema0` entry. Twenty
tool input schemas and 123 output schemas carried it, and clients or
model APIs that reject recursive JSON Schemas refuse the whole tool
list. Every JSON value satisfies `{}`, so the shared JSON value schema
now advertises that. Runtime parsing still admits only JSON values.

Refs #919

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-08T03:40:04.867049Z 7e81a29 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

…n-schemas

# Conflicts:
#	docs/product-catalog.json
#	docs/verification/managed-conformance-manifest.json
#	skills/reverse-engineer-anything/SKILL.md
#	src/generatedMcpToolCatalog.ts
…n-schemas

# Conflicts:
#	src/generatedMcpToolCatalog.ts
@N0zoM1z0

N0zoM1z0 commented Oct 8, 2026

Copy link
Copy Markdown
Collaborator

Reviewed the schema projection, runtime parser, SDK registration path, and generated catalog. The shared JSON-value projection is lossless for transport JSON and removes recursive references from both input and output schemas without changing runtime validation.

I pushed follow-up commit 7e81a29 to reconcile this PR with current main. It preserves the current strict-root input, authority-hint, parameter-description, catalog-parity, and handler-binding regressions, and adds cycle coverage including root # references and escaped JSON pointers.

Local verification passed with the pinned toolchain and a fresh locked dependency install:

  • npm run build:cached
  • Five focused test files, 21 tests, covering JSON validation, advertised schemas, CLI/MCP presentation, contract identity, and handler binding.
  • npm run check:fast -- --concurrency=1
  • npm run docs:check
  • Actual stdio MCP tools/list: 134 tools; zero reachable recursive references in either input or output schemas.

The push triggered a new CI run. This addresses the recursion portion of #919; the deep web-capture comparison input still needs a separate follow-up. A real Muse Spark run has not been performed.

@N0zoM1z0
N0zoM1z0 merged commit 7425f70 into main Oct 8, 2026
24 checks passed
@N0zoM1z0
N0zoM1z0 deleted the fix/non-recursive-json-schemas branch October 8, 2026 03:49
darsrc pushed a commit to darsrc/rea that referenced this pull request Oct 10, 2026
`z.json()` projects a self-referential `$defs/__schema0` entry. Twenty
tool input schemas and 123 output schemas carried it, and clients or
model APIs that reject recursive JSON Schemas refuse the whole tool
list. Every JSON value satisfies `{}`, so the shared JSON value schema
now advertises that. Runtime parsing still admits only JSON values.

Refs morluto#919

Co-authored-by: N0zoM1z0 <[email protected]>
@morluto morluto added bug Something isn't working area: mcp MCP server, transport, and tool registration labels Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: mcp MCP server, transport, and tool registration bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants