Skip to content

Conversation

dr03ramos
Copy link

Added a "file://" prefix to prevent the JSON library from not identifying the URI correctly.

Motivation and Context

Fixes #131. The lib wasn't working for STDIO servers on any Windows environment i tested.

How Has This Been Tested?

Tested on Windows and Linux.
(The issue was occuring only on Windows, but i wanted to see if it would break Linux and it didn't.

Breaking Changes

Not expected.

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

Additional context

Fixes modelcontextprotocol#131.
Tested on Windows and Linux.

Added a "file://" prefix to prevent the JSON library from not identifying the URI correctly.
@@ -50,7 +50,7 @@ def validate_schema!
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
metaschema = "file://#{JSON::Validator.validator_for_name("draft4").metaschema}"
Copy link
Contributor

@atesgoral atesgoral Sep 13, 2025

Choose a reason for hiding this comment

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

Using string interpolation with "file://#{…}" works most of the time, but it’s a bit fragile. A safer, cross-platform approach is to let Ruby build the file: URI:

path = Pathname.new(JSON::Validator.validator_for_name("draft4").metaschema)
uri  = URI::File.build(host: "", path: path.expand_path.cleanpath.to_s.tr("\\", "/"))

metaschema = uri.to_s

Two reasons this is safer:

  • Windows compatibility: Pathname#to_s returns backslashes on Windows (C:\…). URI::File.build expects forward slashes, so .tr("\\", "/") ensures we get a standards-compliant file:///C:/… form.
  • Path normalization: expand_path.cleanpath removes . / .. components and guarantees an absolute path.

The gem’s own metaschema files don’t contain spaces or special characters, so escaping isn’t critical here, but this makes the URI building step robust and RFC-compliant.

@koic
Copy link
Member

koic commented Sep 16, 2025

It would be helpful to add source code comments explaining what kind of issues on Windows environments the added logic is intended to address. It would also be preferable to add regression tests to input_schema_test.rb and output_schema_test.rb.

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.

JSON validation error on Windows
3 participants