Skip to content

Reject omitted and empty-object additionalProperties in MCP schema validator - #2557

Merged
mstomar125 merged 1 commit into
mainfrom
issue-2553-mcp-schema-additionalproperties
Sep 10, 2026
Merged

mstomar125 merged 1 commit into
mainfrom
issue-2553-mcp-schema-additionalproperties

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

Summary

validate_tool_schema's check_schema_depth (packages/cli/src/commands/mcp.rs) enforces ADR-038's "no unbounded additionalProperties" requirement, but previously only rejected the explicit additionalProperties: true case.

Per the JSON Schema spec, an omitted additionalProperties key defaults to true (unbounded), and additionalProperties: {} (an unconstrained schema) is equally unbounded. Neither was caught before this change.

  • check_schema_depth now rejects true, {}, and an omitted key on any schema fragment that describes a JSON object ("type": "object" or a properties map) — via a new describes_object_schema helper. The omitted-key case is scoped to object-describing fragments only, so a leaf like {"type": "string"} isn't wrongly required to carry an additionalProperties key.
  • The real passthrough tool schema (tools_list_result) and its matching "accepts the real passthrough schema" test now carry an explicit additionalProperties: false, since it previously relied on the now-closed omitted-key loophole.
  • The existing nesting-depth test fixtures (..._rejects_excessive_nesting_depth, ..._accepts_nesting_at_exactly_the_bound) gained explicit additionalProperties: false at each level so they continue to exercise only the depth check, not the new unbounded check.
  • Added 4 new tests: omitted-key and empty-object cases, each at the top level and nested inside properties.

Test plan

  • cargo test -p nodespace-cli --lib commands::mcp:: — all 43 tests pass
  • Mutation-tested all 4 new tests individually (reverted each branch of the new logic in turn, confirmed each corresponding test fails, then reverted the mutation) — all 4 caught their target regression
  • bun run quality:fix — clean
  • bun run test:all — full suite green (239 vitest files + full Rust workspace incl. the mcp_integration end-to-end test)

Closes #2553

🤖 Generated with Claude Code

…lidator

check_schema_depth (validate_tool_schema's recursive worker in
packages/cli/src/commands/mcp.rs) only rejected additionalProperties: true.
Per the JSON Schema spec an omitted additionalProperties key defaults to
true, and additionalProperties: {} is an unconstrained schema -- both are
equally unbounded and were previously accepted.

check_schema_depth now flags true, {}, and an omitted key (on any fragment
that describes a JSON object, via describes_object_schema) as unbounded.
The real passthrough tool schema and its matching test fixture now carry
an explicit additionalProperties: false to stay valid under the tightened
check. Existing nesting-depth test fixtures gained explicit
additionalProperties: false at each level so they continue to exercise
only the depth check. Adds coverage for the omitted-key and empty-object
cases at both the top level and nested inside properties.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@mstomar125

Copy link
Copy Markdown
Contributor Author

Reviewed (adversarial pass): describes_object_schema's heuristic confirmed correct for this codebase's actual schema-authoring patterns (traced the untouched anyOf/items nesting tests through the new logic, no false positives). The real-schema consequence independently confirmed genuine — pre-PR tools_list_result() had type:object + properties + required but no additionalProperties key at all, so the loophole was real, and the added additionalProperties:false is semantically correct since extract_tool_call only ever reads arguments.args. Both spot-checked new tests confirmed to genuinely regress the old logic by hand-tracing. Scope clean, worktree-local gaps correctly excluded from the diff. Merging.

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.

MCP schema validator's additionalProperties check misses the omitted-key and empty-object equivalents of unbounded

1 participant