Class: MCP::Tool::Schema

Inherits:
Object
  • Object
show all
Defined in:
lib/mcp/tool/schema.rb

Direct Known Subclasses

InputSchema, OutputSchema

Constant Summary collapse

JSON_SCHEMA_2020_12_URI =

JSON Schema 2020-12 is the default dialect for MCP schema definitions per MCP 2025-11-25 (SEP-1613). Note: emission only — runtime validation is still performed against the JSON Schema draft-04 metaschema because the ‘json-schema` gem does not yet support 2020-12.

"https://json-schema.org/draft/2020-12/schema"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema = {}) ⇒ Schema

Returns a new instance of Schema.



16
17
18
19
20
# File 'lib/mcp/tool/schema.rb', line 16

def initialize(schema = {})
  @schema = JSON.parse(JSON.dump(schema), symbolize_names: true)
  @schema[:type] ||= "object"
  validate_schema!
end

Instance Attribute Details

#schemaObject (readonly)

Returns the value of attribute schema.



14
15
16
# File 'lib/mcp/tool/schema.rb', line 14

def schema
  @schema
end

Instance Method Details

#==(other) ⇒ Object



22
23
24
# File 'lib/mcp/tool/schema.rb', line 22

def ==(other)
  other.is_a?(self.class) && schema == other.schema
end

#to_hObject



26
27
28
29
30
# File 'lib/mcp/tool/schema.rb', line 26

def to_h
  return @schema if @schema.key?(:"$schema")

  { "$schema": JSON_SCHEMA_2020_12_URI }.merge(@schema)
end