Description
json_schema_to_type() in src/fastmcp/utilities/json_schema_type.py crashes on several valid JSON Schema inputs that commonly appear in OpenAPI-generated tool output schemas:
- Python keyword property names (
class, return, import) — TypeError: Field names must not be keywords
- Boolean schemas (
True / False) — AttributeError: 'bool' object has no attribute 'get'
- Empty enum (
{"enum": []}) — AssertionError: literal "expected" cannot be empty
- Sanitized name collisions (
foo-bar + foo_bar both become foo_bar) — TypeError: Field name duplicated
- Empty/whitespace property names (
"", " ") — same duplicate field crash
These all cause the client to crash when parsing structured tool output from servers that use these schema patterns.
Reproduction
from fastmcp.utilities.json_schema_type import json_schema_to_type
# 1. Python keywords
json_schema_to_type({"type": "object", "properties": {"class": {"type": "string"}}})
# TypeError: Field names must not be keywords: 'class'
# 2. Boolean schema
json_schema_to_type(True)
# AttributeError: 'bool' object has no attribute 'get'
# 3. Empty enum
from pydantic import TypeAdapter
T = json_schema_to_type({"type": "object", "properties": {"x": {"enum": []}}})
TypeAdapter(T) # AssertionError
# 4. Name collision
json_schema_to_type({"type": "object", "properties": {"foo-bar": {"type": "string"}, "foo_bar": {"type": "string"}}})
# TypeError: Field name duplicated: 'foo_bar'
Expected behavior
All of these should produce usable Python types without crashing.
Description
json_schema_to_type()insrc/fastmcp/utilities/json_schema_type.pycrashes on several valid JSON Schema inputs that commonly appear in OpenAPI-generated tool output schemas:class,return,import) —TypeError: Field names must not be keywordsTrue/False) —AttributeError: 'bool' object has no attribute 'get'{"enum": []}) —AssertionError: literal "expected" cannot be emptyfoo-bar+foo_barboth becomefoo_bar) —TypeError: Field name duplicated""," ") — same duplicate field crashThese all cause the client to crash when parsing structured tool output from servers that use these schema patterns.
Reproduction
Expected behavior
All of these should produce usable Python types without crashing.