Use symbolize_names: true in JSON.parse calls
Replace custom `deep_transform_keys` in `Tool::Schema` and string key access in `StreamableHTTPTransport` with the `symbolize_names: true` option of `JSON.parse`. This aligns `StreamableHTTPTransport` with `StdioTransport`, which already uses `symbolize_names: true`.
This commit is contained in:
parent
03a78f9344
commit
3a68937bb7
1 changed files with 5 additions and 18 deletions
|
|
@ -8,7 +8,7 @@ module MCP
|
|||
attr_reader :schema
|
||||
|
||||
def initialize(schema = {})
|
||||
@schema = deep_transform_keys(JSON.parse(JSON.dump(schema)), &:to_sym)
|
||||
@schema = JSON.parse(JSON.dump(schema), symbolize_names: true)
|
||||
@schema[:type] ||= "object"
|
||||
validate_schema!
|
||||
end
|
||||
|
|
@ -27,19 +27,6 @@ module MCP
|
|||
JSON::Validator.fully_validate(to_h, data)
|
||||
end
|
||||
|
||||
def deep_transform_keys(schema, &block)
|
||||
case schema
|
||||
when Hash
|
||||
schema.each_with_object({}) do |(key, value), result|
|
||||
result[yield(key)] = deep_transform_keys(value, &block)
|
||||
end
|
||||
when Array
|
||||
schema.map { |e| deep_transform_keys(e, &block) }
|
||||
else
|
||||
schema
|
||||
end
|
||||
end
|
||||
|
||||
def validate_schema!
|
||||
schema = to_h
|
||||
gem_path = File.realpath(Gem.loaded_specs["json-schema"].full_gem_path)
|
||||
|
|
|
|||
Loading…
Reference in a new issue