`dereference_refs` inlines local `$ref` pointers when tools and resource templates are listed (`dereference_schemas=True`). Inlining is a good default for ordinary schemas, but some definition graphs are far larger once fully expanded than they are as written. For those, keeping `$defs` is the better result for clients and for the server.
`dereference_refs` now measures the expanded size before inlining, checks the structure `jsonref` builds, and checks the final text size. Schemas that would exceed 100,000 nodes, 128 levels or about 5 million characters use the existing behavior for circular schemas: the root `$ref` is resolved, and `$defs` and nested `$ref` pointers are kept. Sibling keywords are now merged from the definition each pointer resolves to. Typical Pydantic and MCP schemas are well under these limits; the largest MCP protocol model schema measures about 25,000 nodes.
Co-authored-by: Bill Easton <williamseaston@gmail.com>
Co-authored-by: Claude <noreply@anthropic.com>