-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Description
Describe the bug
When MCP tool (AI function) contains repetitive or recursive parts of the schema that uses $ref to definitions or $defs property, this part of the schema is missing in the LLM call, and the schema is invalid/incomplete
To Reproduce
Steps to reproduce the behavior:
- Use MCP server with AI agent https://devblogs.microsoft.com/semantic-kernel/integrating-model-context-protocol-tools-with-semantic-kernel-a-step-by-step-guide/
- Use MCP server with tool(s) that have complex schema (recursive or repetitive) and use
definitionsor$defsin the schema, e.g. https://github.com/kontent-ai/mcp-server withadd-taxonomy-group-mapitool - Initiate any agent action so that LLM call is made with the tools loaded from the MCP server
- See the LLM payload, the tool schema contains
$ref: "#/definitions/..."butdefinitionsis missing in the tool schema
LLM that validates the schema consistency (Claude recently, but they have seem to reverted it for now) throws HTTP 400 on missing definitions
Expected behavior
Schema of MCP tool should be passed to the LLM as it is, or preserve all well-defined properties of the schema according to its RFC at https://json-schema.org/
Screenshots
Here is a screenshot of Claude HTTP 400 error that we were getting for last several days. It seems they added validation for $ref targets on January 6th
But as (I assume) it probably backfired, they seem to removed it again on January 8th so now it doesn't throw the error anymore.
Having said that, it doesn't change the fact that the schema is sent to the LLM incomplete and the issue may reoccur anytime later...
Platform
- Language: C#
- Source:
- AI model: Claude Sonnet 4.5 (doesn't matter, the data is incomplete)
- IDE: Rider (doesn't matter)
- OS: Windows, Mac (doesn't matter)
Additional context
AIFunctionKernelFunction.MapParameterMetadatadoes not readdefinitions/$defsfrom the source schemaBuildFunctionSchema.BuildFunctionSchema(re)builds the schema only fromParametersKernelFunctionSchemaModelis missingdefinitionsproperty- Kernel
Pluginsonly acceptKernelFunctions as input AIFunctionKernelFunctionissealed internalso it cannot be overriden on our sideKernelFunctionis public, but hasinternalconstructor, so it cannot be overriden on our side
Zod library that is most often used to build MCP tool schemas in TS produces definitions / $defs for repetitive / recursive parts of the tool schema, following https://json-schema.org/ standard
Anthropic docs refer to https://json-schema.org/ for schema format https://platform.claude.com/docs/en/agents-and-tools/tool-use/implement-tool-use#specifying-client-tools
Open AI docs refer to https://json-schema.org/ for schema format https://platform.openai.com/docs/guides/function-calling#defining-functions
I believe that in order to fully support today's MCP servers with complete and complex tool schema, the processed schema should either fully adhere to the https://json-schema.org specifications, or there should be (ideally a built-in) way to pass schema returned by MCP server unchanged to the tools in LLM request...