File tree Expand file tree Collapse file tree 2 files changed +9
-2
lines changed
Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Original file line number Diff line number Diff line change 11# frozen_string_literal: true
22
33require "json-schema"
4+ require "uri"
45
56module 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 ( ", " ) } "
Original file line number Diff line number Diff 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 ( ", " ) } "
You can’t perform that action at this time.
0 commit comments