Class: MCP::Tool::Schema

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

Direct Known Subclasses

InputSchema, OutputSchema

Defined Under Namespace

Classes: ValidationCache

Constant Summary collapse

VALIDATION_CACHE =
ValidationCache.new
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.



47
48
49
50
51
# File 'lib/mcp/tool/schema.rb', line 47

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.



45
46
47
# File 'lib/mcp/tool/schema.rb', line 45

def schema
  @schema
end

Instance Method Details

#==(other) ⇒ Object



53
54
55
# File 'lib/mcp/tool/schema.rb', line 53

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

#to_hObject



57
58
59
60
61
# File 'lib/mcp/tool/schema.rb', line 57

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

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