Repository navigation
Recognize a root $dynamicRef when defaulting an output schema to an object - #649
Merged
koic merged 1 commit intoNov 2, 2026
Conversation
…bject ## Motivation and Context An output schema whose root has none of the keywords in `ROOT_SCHEMA_KEYWORDS` is defaulted to `type: "object"`, which keeps the wire output of the common `properties`-only shape while SEP-2106 lets an output schema be any JSON Schema 2020-12 document. That list named `$ref` but not `$dynamicRef`, although `Tool::Schema` already treats both as the reference keywords it restricts to the same document. A schema whose root is a `$dynamicRef` to an array or a primitive was therefore advertised with an extra `type: "object"` and rejected its own valid results: with result validation on, `tools/call` answered -32603 where the same schema written with `$ref` passed. The list now takes both reference keywords from `Tool::Schema::REFERENCE_KEYWORDS`, so the two cannot drift apart again, and the tools page names `$dynamicRef` among the keywords that keep the default off and beside `$ref` in the same-document rule, which the code has always applied to both. Closes modelcontextprotocol#647 ## How Has This Been Tested? test/mcp/tool/output_schema_test.rb and test/mcp/server_test.rb. Before the fix, the `$dynamicRef` root schema gained `type: "object"` in `to_h` and in the `tools/list` entry, `validate_result([1, 2])` raised "value at root is not an object", and `tools/call` answered -32603 "Internal error". ## Breaking Changes None. A schema whose root is a `$dynamicRef` is now advertised as written; every other root shape is unchanged.
2 of 3 tasks
atesgoral
approved these changes
Nov 2, 2026
koic
deleted the
recognize_a_root_dynamic_ref_when_defaulting_an_output_schema
branch
November 2, 2026 14:21
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.
Motivation and Context
An output schema whose root has none of the keywords in
ROOT_SCHEMA_KEYWORDSis defaulted totype: "object", which keeps the wire output of the commonproperties-only shape while SEP-2106 lets an output schema be any JSON Schema 2020-12 document. That list named$refbut not$dynamicRef, althoughTool::Schemaalready treats both as the reference keywords it restricts to the same document. A schema whose root is a$dynamicRefto an array or a primitive was therefore advertised with an extratype: "object"and rejected its own valid results: with result validation on,tools/callanswered -32603 where the same schema written with$refpassed.The list now takes both reference keywords from
Tool::Schema::REFERENCE_KEYWORDS, so the two cannot drift apart again, and the tools page names$dynamicRefamong the keywords that keep the default off and beside$refin the same-document rule, which the code has always applied to both.Closes #647
How Has This Been Tested?
test/mcp/tool/output_schema_test.rb and test/mcp/server_test.rb. Before the fix, the
$dynamicRefroot schema gainedtype: "object"into_hand in thetools/listentry,validate_result([1, 2])raised "value at root is not an object", andtools/callanswered -32603 "Internal error".Breaking Changes
None. A schema whose root is a
$dynamicRefis now advertised as written; every other root shape is unchanged.Types of changes
Checklist