Repository navigation
Conversation
Eigenwise
left a comment
There was a problem hiding this comment.
The bug is real: an inline object becomes Dict[str, ...] and loses its properties and required. The trouble with the fix is that the nested model drops every key the schema doesn't declare.
I ran it against a live server. Sending {"mode": "x", "extra": 5} to a tool whose inline object only declares mode, the server receives extra on main and doesn't with this PR. It's the same on the way back: a server-only key in structuredContent gets stripped.
Could you:
- Build the nested model's
extrasetting fromadditionalProperties. Absent,trueor{}allows extras.falseforbids them, and the emitted schema keepsadditionalProperties: false. A schema value either validates the extras against it or keeps today'sDictmapping. - Put that in one helper used by both the inline path and
_resolve_ref, with the same condition in both places. The$refpath drops extras today too, so this fixes both. - Add tests for absent /
true/false/ schema-valuedadditionalPropertieswith an undeclared key, plus a structured-output round trip that keeps a server-only key. - Drop the comment that restates the code.
#357 just landed in the same function, so this will need a rebase.
c33b127 to
ba7d876
Compare
Eigenwise
left a comment
There was a problem hiding this comment.
The extras handling and the shared helper for inline and referenced objects look right. One regression blocks it, though: nested property names now go straight into create_model, so a name Pydantic won't accept as a field fails the whole tool.
schema = {
"type": "object",
"required": ["filter"],
"properties": {
"filter": {"type": "object", "required": ["_id"], "properties": {"_id": {"type": "integer"}}}
},
}
SchemaTransformer.create_model_from_schema(schema, "Probe", "probe")On main this builds, and filter={"_id": 5} round-trips as a dict. On this branch it raises NameError: Fields must not use names with leading underscores, and the factory then skips the tool. _id is common in MongoDB-style tools, so this would drop tools that work today.
Please keep an inline object as a plain dict (or alias the field) when one of its property names can't be a Pydantic field, and add a test for the _id case. A top-level _id already fails on main; that's a separate problem and not something to fix here.
It also needs a rebase now: #335 changed _resolve_ref and the two conflict in schema_transformer.py. Please keep #335's full-pointer lookup when you resolve it. #363 is in as well, so constraints inside an inline object with declared properties should still apply after the rebase; a test for that would be welcome.
Honor additionalProperties for inline and referenced objects. Keep reserved Pydantic property names as dictionaries and cover input/output round trips. Preserve full JSON pointer resolution and nested scalar/array constraints.
ba7d876 to
da45a7d
Compare
|
Before I push the rebase onto current main, two of the requested behaviors now conflict with what #389 merged, so I'd like to check which way you want them:
I'll update the branch once the direction is settled. |
SchemaTransformer.json_to_pydantic_fieldmaps every"type": "object"schema toDict[str, ...]and only looks atadditionalProperties. An inline nested object therefore loses itspropertiesandrequired: the tool schema sent to the model has no nested field names or enums, and nested values are not validated before they reach the MCP server. The same object referenced through$refalready becomes a nested model via_create_nested_model.This builds a nested model for inline object schemas that declare
properties, the same way the$refpath does (the model name is the schematitle, orNestedObject). Objects withoutpropertieskeep the existingDictmapping, sotest_object_typeis unchanged. This also covers inline objects used as arrayitems.Tests: added
test_inline_object_properties_are_validated(inline object with an enum and a required field, and an array of inline objects). It fails before the change and passes after it;tests/connectors/mcppasses (410 passed).black --checkandflake8pass on the changed files.