Skip to content

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

Merged
qorzj merged 2 commits into
lessweb:mainfrom
asyncsquadlabs:fix/mcp-input-schema-defs-refs
Nov 4, 2026
Merged

qorzj merged 2 commits 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.

@qorzj

qorzj commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator

Updated the PR to preserve schema references and constraints, and address #396 with tuple compatibility conversion. Affected tools validate arguments against the original schema before MCP calls, without coercing values, adding defaults, or removing fields.

@qorzj
qorzj merged commit adafe15 into lessweb:main Nov 4, 2026
6 checks passed
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.

2 participants