What happened?
DereferenceRefsMiddleware crashes with a RecursionError when schemas contain circular $ref using JSON Pointer style (e.g. #/properties/nodes/items) instead of $defs-based style (e.g. #/$defs/Node).
This is the format emitted by .NET/C# MCP servers using System.Text.Json's schema generator. There is no $defs section, and $ref pointers reference locations directly within the schema tree.
C#'s System.Text.Json schema generator uses JSON Pointer $ref in two cases:
- Recursive types (e.g. a Node with Children: IReadOnlyList) → circular $ref
- Shared types (e.g. the same complex type appearing in multiple properties) → non-circular $ref
As a workaround, we disable the built-in middleware (dereference_schemas=False).
Example Code
from fastmcp.utilities.json_schema import dereference_refs
schema = {
"type": "object",
"properties": {
"nodes": {
"type": "array",
"items": {
"type": "object",
"properties": {
"value": {"type": "string"},
"children": {
"type": "array",
"items": {"$ref": "#/properties/nodes/items"},
},
},
},
},
},
}
dereference_refs(schema) # RecursionError
Version Information
- fastmcp 3.2.0
- jsonref 1.1.0
- Python 3.13
- Upstream MCP server: C# ModelContextProtocol.AspNetCore 1.2.0
What happened?
DereferenceRefsMiddleware crashes with a RecursionError when schemas contain circular $ref using JSON Pointer style (e.g. #/properties/nodes/items) instead of $defs-based style (e.g. #/$defs/Node).
This is the format emitted by .NET/C# MCP servers using System.Text.Json's schema generator. There is no $defs section, and $ref pointers reference locations directly within the schema tree.
C#'s System.Text.Json schema generator uses JSON Pointer $ref in two cases:
As a workaround, we disable the built-in middleware (dereference_schemas=False).
Example Code
Version Information