Inline MCP tool $ref/$defs schemas for Anthropic agent tool calls#5786
Open
sanidhyasin wants to merge 1 commit into
Open
Inline MCP tool $ref/$defs schemas for Anthropic agent tool calls#5786sanidhyasin wants to merge 1 commit into
sanidhyasin wants to merge 1 commit into
Conversation
Anthropic's `input_schema` does not resolve local JSON-Schema references, so MCP tools that describe nested parameters with `$ref`/`$defs` (e.g. Pydantic v2 nested models) were forwarded with dangling pointers, crashing the agent. Inline local references and strip the definition blocks before building `input_schema` so the schema is self-contained. Flat schemas are unchanged. Recursive models collapse to a generic object and unresolvable references are dropped rather than forwarded. Resolves Mintplex-Labs#3938
Contributor
Author
|
@timothycarambat friendly ping — this inlines MCP tool |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request Type
Relevant Issues
resolves #3938
Description
MCP tools whose
inputSchemadescribes nested object parameters (for example tools defined with Pydantic v2 nested models) emit JSON Schema that uses$ref/$defs:{ "type": "object", "properties": { "pagination": { "$ref": "#/$defs/PaginationParams" } }, "$defs": { "PaginationParams": { "type": "object", "properties": { "page": { "type": "integer" }, "limit": { "type": "integer" } } } } }When building the Anthropic
input_schema,#formatFunctionscopied onlytype,properties, andrequired— dropping the$defsblock. The forwarded schema then contained a$refpointing at a definition that no longer existed. Anthropic does not resolve local references on its end, so the dangling pointer rejected the request and crashed the entire agent session. Flat (non-nested) tools were unaffected, which is why this only surfaced for nested-parameter MCP servers.Fix
Added a small, pure helper
dereferenceSchema()that inlines local$refs using the schema's$defs/definitionsand strips the definition blocks, producing a self-contained schema before it is handed to Anthropic.input_schemaas before — this keeps the change scoped and avoids altering every tool call.objectschema instead of recursing forever.This was the concern raised on the earlier attempt (#3939) — that spreading the whole schema would change behavior for every tool. By inlining references and leaving flat schemas byte-for-byte identical, this approach works for all cases without that side effect, so flattening the MCP tool definition by hand is no longer required.
Visuals (if applicable)
N/A
Additional Information
The dereference logic lives in
server/utils/agents/aibitat/providers/helpers/dereferenceSchema.jsand is covered by unit tests inserver/__tests__/utils/agents/aibitat/providers/helpers/dereferenceSchema.test.js.Developer Validations
yarn lintfrom the root of the repo & committed changesFiles were formatted with the repo's Prettier config (
.prettierrc); all three passprettier --check.Focused validation run: