fix(mcp): preserve 'definitions' as a property name in tool schemas - #30491
Closed
MattKotsenas wants to merge 1 commit into
Closed
fix(mcp): preserve 'definitions' as a property name in tool schemas#30491MattKotsenas wants to merge 1 commit into
MattKotsenas wants to merge 1 commit into
Conversation
The MCP input-schema normalizer in _normalize_mcp_input_schema promotes the
legacy JSON Schema 'definitions' meta-keyword to '$defs' (draft 2019-09+)
so local '$ref' resolution works downstream. The previous walk renamed
*any* key named 'definitions' anywhere in the tree, including inside
'properties' dicts. That turned user-facing parameter names into '$defs',
producing property keys that contain '$', which Anthropic and OpenAI
both reject with HTTP 400 (pattern '^[a-zA-Z0-9_.-]{1,64}$').
Real-world repro: an MCP server that exposes a CI/pipelines tool whose
'definitions' parameter is an array of pipeline-definition IDs. Such a tool
is enough on its own to break every conversation, because the full tools
array is sent on every request.
Fix: when descending into a 'properties' or 'patternProperties' mapping,
iterate property-name -> schema pairs directly, leaving the property names
verbatim. Ordinary JSON Schema semantics resume inside each property's
schema, so a legitimately nested 'definitions' meta-keyword inside a
property's schema is still promoted.
Adds two regression tests:
- test_definitions_as_property_name_is_preserved (the property-name case)
- test_definitions_property_and_meta_keyword_coexist (both forms in one
schema; the property name stays, the meta-keyword promotes)
Collaborator
This was referenced Jun 29, 2026
teknium1
added a commit
that referenced
this pull request
Jul 1, 2026
Contributor
|
Merged via #56150 — your commit was cherry-picked onto current Confirmed the bug on current main and E2E-verified the fix across three schema shapes: Clean, well-scoped fix with exactly the right tests. Thanks for the contribution! |
waefrebeorn
pushed a commit
to waefrebeorn/slermes
that referenced
this pull request
Jul 2, 2026
Jasper6439
pushed a commit
to Jasper6439/hermes-agent
that referenced
this pull request
Jul 5, 2026
habarmc1223-sudo
pushed a commit
to habarmc1223-sudo/hermes-agent-fluxmem
that referenced
this pull request
Jul 8, 2026
santhreal
pushed a commit
to santhreal/hermes-agent
that referenced
this pull request
Jul 13, 2026
Gravezzz
pushed a commit
to Gravezzz/hermes-agent
that referenced
this pull request
Jul 21, 2026
leewenjie
pushed a commit
to leewenjie/hermes-agent
that referenced
this pull request
Aug 7, 2026
melon-xf
added a commit
to melon-xf/hermes-agent
that referenced
this pull request
Sep 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
The MCP input-schema normalizer in
_normalize_mcp_input_schemapromotes the legacy JSON Schemadefinitionsmeta-keyword to$defs(draft 2019-09+) so local$refresolution works downstream. The previous walk renamed any key nameddefinitionsanywhere in the tree, including insidepropertiesdicts. That turned user-facing parameter names into$defs, producing property keys that contain$, which Anthropic and OpenAI both reject with HTTP 400 (pattern^[a-zA-Z0-9_.-]{1,64}$).Real-world repro: a CI MCP server exposes a
pipelines_buildtool whosedefinitionsparameter is an array of pipeline-definition IDs. Because the full tools array is sent on every request, the broken schema poisons every conversation, not just calls to that one tool.Fix: when descending into a
propertiesorpatternPropertiesmapping, iterate property-name → schema pairs directly, leaving the property names verbatim. Ordinary JSON Schema semantics resume inside each property's schema, so a legitimately nesteddefinitionsmeta-keyword inside a property's schema is still promoted.Adds two regression tests:
test_definitions_as_property_name_is_preserved(the regression case)test_definitions_property_and_meta_keyword_coexist(both forms in one schema; the property stays, the meta-keyword promotes)Related Issue
None filed. Happy to open one if you'd prefer the issue-first flow; the PR title and body are otherwise the canonical description.
Type of Change
Changes Made
tools/mcp_tool.py: in_normalize_mcp_input_schema._rewrite_local_refs, special-case descent throughproperties/patternPropertiesso keys at that level are treated as property names rather than schema keywords. Thedefinitions→$defsrename and the#/definitions/...→#/$defs/...$refrewrite continue to apply everywhere else.tests/tools/test_mcp_tool.py: two new regression tests covering (1)definitionsas a sole property name, and (2) the both-forms-in-one-schema case where the meta-keyword promotion must still happen.How to Test
definitions. Before the fix, every conversation 400s withtools.N.custom.input_schema.properties: Property keys should match pattern '^[a-zA-Z0-9_.-]{1,64}$'. After the fix, the same conversation succeeds; the affected tool's input schema arrives at the provider with"definitions"preserved as a property key.Checklist
Code
fix(mcp): ...)pytest tests/tools/test_mcp_tool.py tests/agent/test_moonshot_schema.py tests/tools/test_schema_sanitizer.py -qand all 279 tests pass (did not run the fulltests/suite; happy to if a maintainer wants it)Documentation & Housekeeping
docs/, docstrings) - docstring on_rewrite_local_refsrewritten to spell out the contextual-rename rule and the failure mode it preventscli-config.yaml.exampleif I added/changed config keys - N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows - N/AScreenshots / Logs
Provider 400 before the fix (Anthropic-via-Copilot proxy; same wording on Anthropic direct and OpenAI):
Inspecting the offending tool definition in the request body shows
properties: {..., "$defs": {...}, "top": {...}}where the MCP server actually emitsproperties: {..., "definitions": {...}, "top": {...}}. After this change, the wire format matches the server's input.