Skip to content

fix(core): resolve and preserve MCP tool inputSchema $defs/$ref definitions - #395

Open
asyncsquadlabs wants to merge 1 commit into
lessweb:mainfrom
asyncsquadlabs:fix/mcp-input-schema-defs-refs
Open

asyncsquadlabs wants to merge 1 commit into
lessweb:mainfrom
asyncsquadlabs:fix/mcp-input-schema-defs-refs

Conversation

@asyncsquadlabs

Copy link
Copy Markdown

Summary

When MCP servers (such as @runpod/mcp-server) return tool inputSchema objects containing JSON Schema $ref pointers (e.g., "$ref": "#/$defs/CreateDelegationRequest" or "$ref": "#/definitions/..."), McpManager.getMcpToolDefinitions() previously copied only properties, required, and additionalProperties from inputSchema, dropping $defs and definitions.

As a result, the LLM API rejected requests with:

HTTP 400: Invalid schema for function 'mcp__runpod__create-delegation': Pointer '/$defs/CreateDelegationRequest' does not exist

Changes

  • Added normalizeMcpInputSchema() in packages/core/src/mcp/mcp-manager.ts to:
    1. Recursively inline local #/$defs/<Key> and #/definitions/<Key> $ref pointers (merging sibling keywords and flattening single-element allOf wrappers, with cycle detection).
    2. Preserve $defs and definitions on parameters when any unresolved/cyclic $ref remains.
  • Updated McpToolDefinition and ToolDefinition types to include optional $defs and definitions.
  • Added unit tests in packages/core/src/tests/mcp-client.test.ts covering both inlined $defs/definitions references and cyclic $ref preservation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant