fix: pass through JSON Schemas without a "properties" key in create_sdk_mcp_server#1091
Open
Otis0408 wants to merge 1 commit into
Open
fix: pass through JSON Schemas without a "properties" key in create_sdk_mcp_server#1091Otis0408 wants to merge 1 commit into
Otis0408 wants to merge 1 commit into
Conversation
9a9f64e to
978fd75
Compare
…dk_mcp_server
tool()/create_sdk_mcp_server document that input_schema may be "A JSON Schema
dictionary for full validation", and _build_schema has a passthrough branch for
it. But it only recognized a dict as a pre-built JSON Schema when it contained
BOTH "type" AND "properties". A valid JSON Schema that omits "properties" -
e.g. {"type": "object"}, an open object
{"type": "object", "additionalProperties": true}, or an array schema
{"type": "array", "items": {...}} - failed that test and was misinterpreted as
a {param_name: python_type} mapping, turning its schema keywords into fake
required string parameters. The model then saw a corrupted tool schema.
Detect a JSON Schema by a string-valued "type" alone. "properties" is optional
in JSON Schema, and a {name: type} mapping never matches because its values are
Python types (isinstance(input_schema["type"], str) is False even for a param
literally named "type"). Adds regression tests for the passthrough cases and a
guard test for the "param named type" edge case.
978fd75 to
30c8b98
Compare
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.
Summary
tool()documents thatinput_schemamay be "A JSON Schema dictionary for full validation", andcreate_sdk_mcp_server's_build_schemahas a dedicated passthrough branch for it (covered bytest_json_schema_dict_passthrough).But it only recognized a dict as a pre-built JSON Schema when it contained both
"type"and"properties"."properties"is optional in JSON Schema — open objects, arrays, and non-object schemas legitimately omit it — so a valid schema without it was misinterpreted as a{param_name: python_type}mapping and mangled:The schema's own keywords (
type,additionalProperties,items, ...) become fake required string parameters, so the model is told the tool needs inputs it doesn't — breaking tool calls. Affected inputs include{"type": "object"},{"type": "object", "additionalProperties": true}(open/arbitrary-object tools), and{"type": "array", "items": {...}}.Fix
Detect a JSON Schema by a string-valued
typealone; drop the extra"properties"requirement. A{name: type}param mapping never matches this, because its values are Python types —isinstance(input_schema["type"], str)isFalseeven when a param is literally namedtype(its value is thestrtype, not the string"object").Tests
test_json_schema_without_properties_passthrough—{"type": "object"}, open-object, and array schemas now pass through unchanged (parametrized).test_param_mapping_with_param_named_type_still_expands— a mapping with a param namedtypestill expands correctly, guarding the disambiguation the fix relies on.Verified the passthrough tests fail on
main(schema mangled) and pass with the fix; the "param named type" test passes both ways.