Make $ref dereferencing optional via FastMCP(dereference_refs=...) (#3151)

Co-authored-by: marvin-context-protocol[bot] <225465937+marvin-context-protocol[bot]@users.noreply.github.com>
This commit is contained in:
Jeremiah Lowin 2026-02-11 13:45:37 -05:00 committed by GitHub
commit fe57c3d689
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 460 additions and 128 deletions

View file

@ -205,10 +205,11 @@ async def test_hidden_param_prunes_defs():
schema = new_tool.parameters
# Only 'a' should be visible
assert list(schema["properties"].keys()) == ["a"]
# Schema should be fully dereferenced (no $defs)
assert "$defs" not in schema
# VisibleType should be inlined in the property
assert schema["properties"]["a"] == {
# HiddenType should be pruned from $defs
assert "HiddenType" not in schema.get("$defs", {})
# VisibleType should remain in $defs and be referenced via $ref
assert schema["properties"]["a"] == {"$ref": "#/$defs/VisibleType"}
assert schema["$defs"]["VisibleType"] == {
"properties": {"x": {"type": "integer"}},
"required": ["x"],
"type": "object",
@ -396,10 +397,8 @@ def test_transform_args_with_parent_defaults():
new_tool = Tool.from_tool(tool)
# Both tools should have the same dereferenced schema
# Both tools should have the same schema (with $ref/$defs preserved)
assert new_tool.parameters == tool.parameters
# Schema should be fully dereferenced (no $defs)
assert "$defs" not in new_tool.parameters
def test_transform_args_validation_unknown_arg(add_tool):