π The fast, Pythonic way to build MCP servers and clients.
fix: keep additionalProperties on object schemas without a type (#6127)
zgy2a8f33373706
diff --git a/fastmcp_slim/fastmcp/utilities/json_schema_type.py b/fastmcp_slim/fastmcp/utilities/json_schema_type.pyindex 4fbc6d699..967391afa 100644--- a/fastmcp_slim/fastmcp/utilities/json_schema_type.py+++ b/fastmcp_slim/fastmcp/utilities/json_schema_type.py@@ -842,6 +842,13 @@ def _convert_schema(return objectif "type" not in schema and "properties" in schema:+ # A schema with properties but no "type" is still an object schema. When+ # it allows additional properties, take the object path so unknown keys+ # are kept, exactly as if "type": "object" were spelled out.+ if schema.get("additionalProperties"):+ return _object_schema_to_type(+ schema, schemas, resolving_refs=resolving_refs+ )return _create_dataclass(schema, schema.get("title", "<unknown>"), schemas)# Handle references firstdiff --git a/tests/utilities/json_schema_type/test_advanced.py b/tests/utilities/json_schema_type/test_advanced.pyindex dbbbf7c42..d7554ee5b 100644--- a/tests/utilities/json_schema_type/test_advanced.py+++ b/tests/utilities/json_schema_type/test_advanced.py@@ -983,6 +983,22 @@ class TestAdditionalProperties:assert result == dataassert isinstance(result, dict)+ def test_untyped_object_with_additional_keeps_extra_fields(self):+ """A properties-only object without "type" still honours additionalProperties"""+ schema_type = json_schema_to_type(+ {"properties": {"name": {"type": "string"}}, "additionalProperties": True}+ )+ result = TypeAdapter(schema_type).validate_python({"name": "x", "extra": 1})+ assert result.name == "x" # type: ignore[attr-defined]+ assert result.extra == 1 # type: ignore[attr-defined]++ def test_untyped_empty_properties_with_additional_returns_dict(self):+ """An empty properties map with additionalProperties=True keeps unknown keys"""+ schema_type = json_schema_to_type(+ {"properties": {}, "additionalProperties": True}+ )+ assert schema_type == dict[str, Any]+def test_properties_with_additional_returns_basemodel(self, properties_with_additional):