Skip to content

Preserve explicit MCP object extension policies - #393

Closed
Afloat16 wants to merge 1 commit into
Eigenwise:mainfrom
Afloat16:fix/mcp-explicit-extra-properties-20261113
Closed

Afloat16 wants to merge 1 commit into
Eigenwise:mainfrom
Afloat16:fix/mcp-explicit-extra-properties-20261113

Conversation

@Afloat16

Copy link
Copy Markdown
Contributor

MCP object models currently use Pydantic's default extra="ignore", even when the server explicitly advertises additionalProperties. A named-field object that permits extension keys silently drops those keys from both tool arguments and typed results. A closed object also accepts unadvertised keys by discarding them.

Apply the explicit object extension policy when building top-level and referenced object models. true preserves arbitrary extra values, a schema validates and serializes extra values through Pydantic's typed extra dictionary, and false forbids unknown keys. Existing behavior for schemas that omit this keyword stays unchanged. The generated JSON Schema carries the same explicit policy.

This covers named-field objects, closed empty objects, and extra values that reference another structured record. It complements the existing dictionary conversion for objects without named properties.

Validation

  • 18 new regression cases: 14 fail against the unchanged upstream base; all 18 pass with the fix. Four cases are passing controls for required fields and omitted policies.
  • Real MCP server and ClientSession over the SDK's in-memory transport preserve extension arguments and JSON-text/structured output. No external model calls are needed.
  • Full core suite: 1,170 passed, 14 skipped.
  • MCP 1.8 compatibility: 17 passed, 1 skipped; the skipped case requires structured tool output introduced after that version.
  • Repository-wide Black and Flake8, wheel build, and git diff --check pass.

The remote commit tree matches the locally tested tree.

@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.

The additionalProperties: true half fixes real data loss: extra keys the server allows are dropped today. The false half makes generated models reject extra keys that main quietly drops, and zod-based servers commonly send additionalProperties: false at the top level, so that changes behavior for a lot of existing tools with no bug behind it. Please keep the allow and typed-extras branches and drop the forbid branch.

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

Copy link
Copy Markdown
Contributor Author

Consolidated into #389, which is rebased onto current main. That patch preserves allowed/typed extensions and removes the new forbid behavior: additionalProperties: false continues to ignore extra values. The extension and real-transport regressions are retained there. Closing this overlapping PR under the contribution guide's same-module rule.

@Afloat16 Afloat16 closed this Nov 17, 2026
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