Skip to content

Commit 5944942

Browse files
committed
Refactor metaschema URI handling for Windows compatibility in input and output schema validation
1 parent ef2323d commit 5944942

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lib/mcp/tool/input_schema.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

33
require "json-schema"
4+
require "uri"
45

56
module MCP
67
class Tool
@@ -50,9 +51,12 @@ def validate_schema!
5051
accept_uri: false,
5152
accept_file: ->(path) { path.to_s.start_with?(Gem.loaded_specs["json-schema"].full_gem_path) },
5253
)
54+
# Get the metaschema for the draft4 validator
5355
metaschema_path = Pathname.new(JSON::Validator.validator_for_name("draft4").metaschema)
54-
metaschema_uri = URI::File.build(host: "", path: metaschema_path.expand_path.cleanpath.to_s.tr("\\", "/"))
56+
# Converts metaschema to a file URI for Windows compatibility
57+
metaschema_uri = JSON::Util::URI.file_uri(metaschema_path.expand_path.cleanpath.to_s.tr("\\", "/"))
5558
metaschema = metaschema_uri.to_s
59+
# Validates the input returning any errors
5660
errors = JSON::Validator.fully_validate(metaschema, schema, schema_reader: schema_reader)
5761
if errors.any?
5862
raise ArgumentError, "Invalid JSON Schema: #{errors.join(", ")}"

lib/mcp/tool/output_schema.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,12 @@ def validate_schema!
4242
accept_uri: false,
4343
accept_file: ->(path) { path.to_s.start_with?(Gem.loaded_specs["json-schema"].full_gem_path) },
4444
)
45+
# Get the metaschema for the draft4 validator
4546
metaschema_path = Pathname.new(JSON::Validator.validator_for_name("draft4").metaschema)
46-
metaschema_uri = URI::File.build(host: "", path: metaschema_path.expand_path.cleanpath.to_s.tr("\\", "/"))
47+
# Converts metaschema to a file URI for Windows compatibility
48+
metaschema_uri = JSON::Util::URI.file_uri(metaschema_path.expand_path.cleanpath.to_s.tr("\\", "/"))
4749
metaschema = metaschema_uri.to_s
50+
# Validates the output returning any errors
4851
errors = JSON::Validator.fully_validate(metaschema, schema, schema_reader: schema_reader)
4952
if errors.any?
5053
raise ArgumentError, "Invalid JSON Schema: #{errors.join(", ")}"

0 commit comments

Comments
 (0)