Skip to content

fix(mcp): traverse contentSchema and tuple items in literal normalization - #7122

Closed
carcraze wants to merge 1 commit into
morluto:mainfrom
carcraze:fix/content-schema-literal-traversal
Closed

carcraze wants to merge 1 commit into
morluto:mainfrom
carcraze:fix/content-schema-literal-traversal

Conversation

@carcraze

@carcraze carcraze commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #7123.

Closes three gaps in advertised input-schema literal normalization and catalog-wide client-constraint checks:

  1. src/contracts/jsonSchemaKeywords.ts: add contentSchema to schemaChildren so schema-valued contentSchema subschemas are traversed during literal normalization, reference checks, and client-constraint checks.
  2. tests/fixtures/mcpClientSchemaConstraints.ts & tests/boundary/mcp/toolSchemaValidity.test.ts: extract a shared schemaChildEntries helper so unsupportedInputLiteralSchemaError traverses array-valued schemaChildren (such as draft-07 tuple items) just like arrayItemSchemaError, and reuse the shared jsonSchemaKeywords sets in localInputReferences.
  3. src/contracts/inputSchemaPresentation.ts: preserve every primitive member type via literalSchemaType when widening a mixed enum containing "" (presenting anyOf of the primitive member types rather than an untyped schema).

Problem and expected behavior

Trigger:

  • presentInputJsonSchema on { type: "string", contentSchema: { const: "" } } left const: "" un-widened because contentSchema was absent from schemaChildren.
  • unsupportedInputLiteralSchemaError on { type: "array", items: [{ type: "string" }, { const: "" }] } returned undefined because array-valued schemaChildren were only traversed in arrayItemSchemaError.
  • presentInputJsonSchema on { enum: ["", 1] } dropped enum without retaining anyOf: [{ type: "string" }, { type: "integer" }].

Expected: all three positions are normalized and checked consistently across full and compact profiles.

Change and scope

  • src/contracts/jsonSchemaKeywords.ts: add "contentSchema" to schemaChildren.
  • src/contracts/inputSchemaPresentation.ts: add literalSchemaType so mixed primitive enums containing "" widen to anyOf of their member types.
  • tests/fixtures/mcpClientSchemaConstraints.ts: share schemaChildEntries between arrayItemSchemaError and unsupportedInputLiteralSchemaError.
  • tests/boundary/mcp/toolSchemaValidity.test.ts: import the shared keyword sets in localInputReferences and cover tuple items in unsupportedInputLiteralSchemaError.
  • src/contracts/toolInputReferences.test.ts: add regression tests for mixed-enum widening, contentSchema widening, and the recorded applicationFeatureSeedSchema trace seed.

Follow the contribution scope. Not applicable (ordinary MCP schema projection and test-guard fix within existing boundaries).

Contract and boundary impact

  • Semantic owner and earliest changed stage: src/contracts/jsonSchemaKeywords.ts and src/contracts/inputSchemaPresentation.ts.
  • Contribution scope fit and linked maintainer decision: not applicable.
  • CLI and MCP/tool-catalog contract: advertised input schemas and client-constraint tests only; canonical runtime validation is unchanged.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: none.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): not applicable.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: none.

Expected effects:

  • Documentation or usability only; no target interaction.

Evidence and regression coverage

  • Tests added or updated: src/contracts/toolInputReferences.test.ts and tests/boundary/mcp/toolSchemaValidity.test.ts.
  • Base reproduction or other evidence: unit tests verify enum: ["", 1] widens to anyOf: [{ type: "string" }, { type: "integer" }], contentSchema: { const: "" } widens to { type: "string" }, and unsupportedInputLiteralSchemaError catches tuple items[1].
  • User-visible CLI/MCP output (if applicable): not applicable.
  • Remaining proof gaps: none.

Validation performed

  • npx vitest run src/contracts/toolInputReferences.test.ts — 37 passed
  • npx vitest run tests/boundary/mcp/compactInputSchemaMcp.test.ts tests/boundary/mcp/toolSchemaValidity.test.ts — 28 passed
  • npm run check:fast (tsc --noEmit, oxlint, verify:module-boundaries) & npm run format:check — clean (0 errors)

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: none.

Author readiness

Human owner: @carcraze

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 25, 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-31T10:22:16.182845Z 378e2df 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.

@greptile-apps

greptile-apps Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: apex

[Medium impact] The reviewed changes appear safe to merge; no blocking issue was found.

Summary

Adds contentSchema to the shared schema-child keywords so presentation, reference checks, and client checks visit its nested schemas.

  • MCP input schemas now include contentSchema in nested-schema traversal.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  K["Shared schema-child keywords include contentSchema"]
  K --> P["Input presentation"]
  K --> R["Reference checks"]
  K --> C["Client schema checks"]
  P --> W["Widen unsupported literals"]
  W --> A["Full and compact advertisements"]
  C --> L["Check literals and array items"]
Loading

Reviews (9) · Last reviewed commit: "fix(mcp): traverse contentSchema in sche..." · Reviewed by Greptile

@carcraze
carcraze force-pushed the fix/content-schema-literal-traversal branch 2 times, most recently from c8d53c5 to 7163aaa Compare October 25, 2026 13:37
@carcraze
carcraze force-pushed the fix/content-schema-literal-traversal branch 2 times, most recently from 42a75f8 to 12320cb Compare October 25, 2026 13:45
@carcraze

Copy link
Copy Markdown
Contributor Author

@codex review

@carcraze
carcraze force-pushed the fix/content-schema-literal-traversal branch from 9d055f6 to 868addd Compare October 25, 2026 16:00

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 868addd5b4

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@carcraze

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: 3eeef37c19

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@carcraze
carcraze force-pushed the fix/content-schema-literal-traversal branch from f5851c1 to 378e2df Compare October 31, 2026 10:19
@carcraze

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (23de10b) at 378e2df — Greptile 5/5, Codex 0 findings, and ready for review whenever convenient.

@CassieFox23

Copy link
Copy Markdown
Contributor

TL;DR: I ran the two test files on head 378e2df on three Node versions, and all 52 tests passed each time. With jsonSchemaKeywords.ts swapped back to the merge base, 2 tests failed on every version, so the contentSchema change is covered. The PR body also lists a schemaChildEntries helper and a literalSchemaType change, and I found neither in this head.

Findings

Check Node 22.23.4 Node 24.22.1 Node 26.12.1
Head 378e2df pass: 2 files, 52 tests pass: 2 files, 52 tests pass: 2 files, 52 tests
Red run (jsonSchemaKeywords.ts from 23de10b) fail: 2 tests failed, 50 passed fail: 2 tests failed, 50 passed fail: 2 tests failed, 50 passed

The test files were src/contracts/toolInputReferences.test.ts and tests/boundary/mcp/toolSchemaValidity.test.ts. The red run used the same head and test files. Only jsonSchemaKeywords.ts went back to the merge base, which is the commit where the branch left main.

  • In the Node 24.22.1 log, the two failures are checks client array constraints in schema positions while preserving literal metadata and widens empty-string literals under contentSchema.
  • The PR body lists three changes. They are contentSchema in jsonSchemaKeywords.ts and a shared schemaChildEntries helper. The third is a literalSchemaType helper in src/contracts/inputSchemaPresentation.ts, so a mixed enum like ["", 1] widens to anyOf.
  • At 378e2df the PR is one commit. Against the merge base it changes 3 files: src/contracts/jsonSchemaKeywords.ts (1 line), src/contracts/toolInputReferences.test.ts and tests/boundary/mcp/toolSchemaValidity.test.ts.
  • No file under src or tests at this head contains schemaChildEntries or literalSchemaType. inputSchemaPresentation.ts and tests/fixtures/mcpClientSchemaConstraints.ts are unchanged. So the helper and the mixed-enum change from the body are not in this head.
  • One idea: push the missing commits, or trim the body to the contentSchema change.
  • CI on 378e2df: PR readiness, Greptile Review and Validate author declaration passed. CI and PR title are waiting for a maintainer to approve them (action_required).
  • The head is 420 commits behind main b81da90. GitHub says the PR is mergeable, and its merge state is blocked.

Not run

  • The mixed-enum case { enum: ["", 1] } from the body.
  • A merge with current main, b81da90.
Test setup
  • Box: Fedora 44 VM (4 vCPUs, 8 GB) on my Nobara 44 PC, Linux 7.2.11
  • Node: 22.23.4, 24.22.1, 26.12.1
  • Head / base: 378e2df / 23de10b (merge base with main)
  • Red run: 378e2df with src/contracts/jsonSchemaKeywords.ts from 23de10b
  • Install: npm ci --offline and npm run test:prepare on Node 24.22.1, exit 0, for both trees
Commands
npm ci --offline
npm run test:prepare
xvfb-run -a npm run test:focused -- src/contracts/toolInputReferences.test.ts tests/boundary/mcp/toolSchemaValidity.test.ts

🤖 Written and tested with Claude Code (Sonnet 5.5, verified by Opus 5.5), posted with my OK 🦊

gensokyo-dev added a commit that referenced this pull request Nov 14, 2026
Fixes #7123

Supersedes #7122

Co-authored-by: mawahnnie <[email protected]>
Co-Authored-By: gensokyo-dev <[email protected]>
N0zoM1z0 pushed a commit that referenced this pull request Nov 14, 2026
Fixes #7123

Supersedes #7122

Co-authored-by: mawahnnie <[email protected]>
Co-Authored-By: gensokyo-dev <[email protected]>
@N0zoM1z0

Copy link
Copy Markdown
Collaborator

Thank you for this fix. It landed in #10519 with your authorship kept on the commit (adapted where noted in the PR), so I'm closing this PR as superseded.

@N0zoM1z0 N0zoM1z0 closed this Nov 14, 2026
@morluto morluto added area: mcp MCP server, transport, and tool registration bug Something isn't working labels Nov 23, 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.

[Bug] Advertised input schema normalization and literal constraint checks skip contentSchema and array-valued tuple items

4 participants