Skip to content

fix: pass through JSON Schemas without a "properties" key in create_sdk_mcp_server#1091

Open
Otis0408 wants to merge 1 commit into
anthropics:mainfrom
Otis0408:fix/sdk-mcp-schema-without-properties
Open

fix: pass through JSON Schemas without a "properties" key in create_sdk_mcp_server#1091
Otis0408 wants to merge 1 commit into
anthropics:mainfrom
Otis0408:fix/sdk-mcp-schema-without-properties

Conversation

@Otis0408

@Otis0408 Otis0408 commented Jul 8, 2026

Copy link
Copy Markdown

Summary

tool() documents that input_schema may be "A JSON Schema dictionary for full validation", and create_sdk_mcp_server's _build_schema has a dedicated passthrough branch for it (covered by test_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:

tool("t", "d", {"type": "object", "additionalProperties": True})
# inputSchema the model sees today:
# {'type': 'object',
#  'properties': {'type': {'type': 'string'},
#                 'additionalProperties': {'type': 'string'}},
#  'required': ['type', 'additionalProperties']}

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 type alone; drop the extra "properties" requirement. A {name: type} param mapping never matches this, because its values are Python types — isinstance(input_schema["type"], str) is False even when a param is literally named type (its value is the str type, 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 named type still 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.

1064 passed, 5 skipped
ruff check: All checks passed!
mypy src: Success: no issues found in 24 source files

@Otis0408 Otis0408 force-pushed the fix/sdk-mcp-schema-without-properties branch from 9a9f64e to 978fd75 Compare July 9, 2026 05:50
…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.
@Otis0408 Otis0408 force-pushed the fix/sdk-mcp-schema-without-properties branch from 978fd75 to 30c8b98 Compare July 9, 2026 07:47
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.

1 participant