Skip to content

Allow $ref in Tool::Schema for protocol version 2025-11-25#242

Merged
koic merged 1 commit intomodelcontextprotocol:mainfrom
koic:support_ref_in_tool_schema
Mar 1, 2026
Merged

Allow $ref in Tool::Schema for protocol version 2025-11-25#242
koic merged 1 commit intomodelcontextprotocol:mainfrom
koic:support_ref_in_tool_schema

Conversation

@koic
Copy link
Member

@koic koic commented Feb 27, 2026

Motivation and Context

Tool::Schema rejected $ref with an ArgumentError. Earlier MCP spec versions (2024-11-05 through 2025-06-18) did not define a JSON Schema dialect or reference the $ref keyword. inputSchema was described only as "JSON Schema defining expected parameters" with no further constraints:

The MCP spec 2025-11-25 introduced a "JSON Schema Usage" section that adopts JSON Schema 2020-12 as the default dialect. Since $ref is a core keyword in 2020-12, it is now allowed for protocol version 2025-11-25 and later.

How Has This Been Tested?

Added a repro test to verify the fix and prevent regression.

Breaking Changes

None. For backward compatibility with older protocol versions (2025-06-18 and earlier), Server#validate! continues to raise ArgumentError when a tool input schema contains $ref. This preserves the existing behavior for servers targeting those spec versions.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

`Tool::Schema` rejected `$ref` with an `ArgumentError`.
Earlier MCP spec versions (2024-11-05 through 2025-06-18) did not define
a JSON Schema dialect or reference the `$ref` keyword. `inputSchema` was described
only as "JSON Schema defining expected parameters" with no further constraints:

- https://modelcontextprotocol.io/specification/2024-11-05/server/tools
- https://modelcontextprotocol.io/specification/2025-06-18/server/tools

The MCP spec 2025-11-25 introduced a "JSON Schema Usage" section that adopts
JSON Schema 2020-12 as the default dialect. Since `$ref` is a core keyword in 2020-12,
it is now allowed for protocol version 2025-11-25 and later.

- https://modelcontextprotocol.io/specification/2025-11-25/basic#json-schema-usage
- https://modelcontextprotocol.io/specification/2025-11-25/server/tools
- https://json-schema.org/draft/2020-12/release-notes

For backward compatibility with older protocol versions (2025-06-18 and earlier),
`Server#validate!` continues to raise `ArgumentError` when a tool input schema contains `$ref`.
This preserves the existing behavior for servers targeting those spec versions.
@koic koic merged commit 145dc1f into modelcontextprotocol:main Mar 1, 2026
10 checks passed
@koic koic deleted the support_ref_in_tool_schema branch March 1, 2026 08:16
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