Skip to content

Preserve recursive MCP schemas and explicit object data - #389

Merged
Eigenwise merged 1 commit into
Eigenwise:mainfrom
Afloat16:fix/recursive-mcp-models-20261113
Nov 17, 2026
Merged

Eigenwise merged 1 commit into
Eigenwise:mainfrom
Afloat16:fix/recursive-mcp-models-20261113

Conversation

@Afloat16

@Afloat16 Afloat16 commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Problem

MCP object schemas currently lose constraints or data in three related paths: recursive children fall back to Any, Pydantic-reserved property names prevent a tool from loading or disappear, and explicitly permitted object extensions are dropped.

Changes

  • Resolve recursive object fields through forward references keyed by the complete JSON Pointer, retaining current main's reference resolution.
  • Alias only field names Pydantic rejects or ignores; keep permitted attributes such as params.schema unchanged.
  • Preserve explicitly allowed and typed extra values at the model and MCP transport boundaries. Keep existing ignore behavior for additionalProperties: false and unspecified policies.
  • Preserve main's routing-field escaping, fixed tuples, and mapping constraints.

Consolidates #370 and #393 into this PR under the contribution guide's same-module rule.

Validation

  • Full MCP connector suite: 845 passed.
  • Focused regression/compatibility cases: 58 passed; the current main implementation yields 43 failed, 15 passed on those same cases.
  • Black, Flake8, and git diff --check: passed.

Includes input/output schemas, full and escaped pointers, nested/array-index references, same-named definition containers, mutual recursion, actual in-memory MCP transport, and combinations of recursive extras with reserved property names.

@Eigenwise Eigenwise left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Recursive models are a real gap, but this branch predates the JSON Pointer $ref resolution from #335 and has to be rebuilt on top of it.

Leaving this open for an update. Please also keep to the limit in What gets reviewed before opening new pull requests.

@Afloat16
Afloat16 force-pushed the fix/recursive-mcp-models-20261113 branch from cb20328 to eec314a Compare November 17, 2026 12:48
@Afloat16 Afloat16 changed the title Preserve recursive object validation in MCP schemas Preserve recursive MCP schemas and explicit object data Nov 17, 2026

Afloat16 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor Author

Rebased onto current main cdab450, preserving the full JSON Pointer resolver from #335 and the newly merged MCP argument-name, tuple, and mapping constraints.

I have consolidated the overlapping schema fixes from #370 and #393 here, as requested by the contribution guidelines:

  • Recursive object references now bind to the eventual model using the complete reference path; nested descendants retain validation.
  • Only field names Pydantic rejects or ignores receive aliases. Permitted shadowing fields retain their existing attributes, including params.schema.
  • Explicit additionalProperties: true and typed extensions are preserved. false and omitted policies retain main's existing ignore behavior.

Validation: 845 MCP tests passed, including 58 focused cases across the three fixes. Against the current main implementation, the same focused cases produce 43 failures and 15 passes. Coverage includes full/escaped pointers, array-index pointers, same-named definition containers, mutual recursion, transport round trips, and combined recursive typed extensions with reserved keys. Black, Flake8, and git diff --check pass.

#370 and #393 are superseded by this combined patch so the same module no longer needs three overlapping PRs.

Cross-PR integration check: I also applied #378 (213a405a93c3), #387 (df89abe7540c), this PR (eec314ac0406), #396 (424ab24847e2) and #401 (0e365500b4c3) together on main 07a82993dbed in a temporary validation tree. The patches combine without conflicts. The combined tree passes 1,781 core tests, 165 webpage tests, 53 YouTube tests, and 3 real-process session example tests: 2,002 passed, 26 skipped. The run imports both core and assembler from that same tree; in-memory tracing tests use an always-on sampler rather than the execution environment's inherited 1% sampling.

@Eigenwise Eigenwise left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks for reworking this, it resolves what I raised: it's built on main's JSON Pointer resolution, a property called schema keeps its name, and additionalProperties: false no longer turns into a hard reject.

Checked on current main with this merged: the 58 new tests pass and 43 of them fail on main's source, and the core suite is otherwise unchanged. I also ran a schema generated from ordinary Pydantic models through it: a recursive model validates its nested children, a model with extra="allow" keeps the extra keys, and a field aliased to _id loads and is sent as _id.

@Eigenwise
Eigenwise merged commit 2417d1f into Eigenwise:main Nov 17, 2026
3 checks passed
Eigenwise added a commit that referenced this pull request Nov 17, 2026
…he map (#492)

#389 changed how MCP schemas become models. Checked on main with a schema
generated from Pydantic models: a recursive model rejects a bad nested child,
an extra='allow' object keeps an undeclared key, a top-level unknown key is
ignored, a field aliased to _id is accepted and dumped as _id, and a property
named schema stays readable as .schema.

Co-authored-by: Kenny Vaneetvelde <kenny@eigenwise.io>
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants