Skip to content

Conversation

codenamev
Copy link
Contributor

Added comprehensive support for optional JSON Schema validation of tool outputs according to the MCP specification.

Motivation and Context

This implements the Tool's outputSchema according the the latest specification.

How Has This Been Tested?

Extensive tests have been added mirroring those of the input_schema which follow very similar structure and rules.

Breaking Changes

None. This is fully backwards-compatible.

Types of changes

  • Add MCP::Tool::OutputSchema class mirroring InputSchema functionality
  • Support output_schema in class definitions, Tool.define, and OutputSchema objects
  • Include validate_result method to support runtime validation
  • Update MCP::Client::Tool to track output schemas
  • Update documentation with dedicated Tool Output Schemas section
  • Follow MCP spec requirements for server/client validation

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

This commit implements optional JSON Schema validation for tool outputs according to the MCP specification:

- Add MCP::Tool::OutputSchema class mirroring InputSchema functionality
- Support output_schema in class definitions, Tool.define, and OutputSchema objects
- Include validate_result method for runtime validation
- Update MCP::Client::Tool to track output schemas
- Add comprehensive test coverage with 249 passing tests
- Update README with dedicated Tool Output Schemas section
- Follow MCP spec requirements for server/client validation
accept_uri: false,
accept_file: ->(path) { path.to_s.start_with?(Gem.loaded_specs["json-schema"].full_gem_path) },
)
metaschema = JSON::Validator.validator_for_name("draft4").metaschema
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could use the same fix in #132 to work on Windows

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it can be a follow-up

@atesgoral
Copy link
Contributor

This is awesome!

@koic
Copy link
Member

koic commented Sep 14, 2025

It looks like a merge commit has been added. It might be better to undo this merge commit (e.g., git reset HEAD^).
If incorporating the latest main branch is needed for verification, rebase on the latest main branch would usually be sufficient instead of merging (it would be nice if GitHub's UI supported that, but, unfortunately I haven't seen that yet 😅). This approach helps ensure your own commits are not included in the review, allowing you to merge it yourself after approval.
That aside, since the v0.3.0 release is coming up, let's merge this as a topic for the future. Thank you!

@koic koic merged commit bdd6995 into modelcontextprotocol:main Sep 14, 2025
5 checks passed
@koic
Copy link
Member

koic commented Sep 14, 2025

it would be nice if GitHub's UI supported that, but, unfortunately I haven't seen that yet

There is the "Update with rebase" option 😅. This might resolve it. That said, I think in most cases it will not result in implicit feature conflicts.

update-with-rebase

@atesgoral
Copy link
Contributor

@koic Ah I wasn't aware GitHub was defaulting to merging instead of doing a regular rebase when the UI is used. Good to know for the future!

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.

3 participants