Class: Hitch::MCP::Internal::SchemaContract

Inherits:
Object
  • Object
show all
Defined in:
app/models/hitch/mcp/internal/schema_contract.rb

Overview

Admission-time contract for a tool's input or output schema: a bounded, copied, frozen JSON Schema 2020-12 document with only same-document references.

Constant Summary collapse

MAX_SCHEMA_DEPTH =
64
MAX_SCHEMA_OBJECTS =
10_000
MAX_SCHEMA_BYTES =
1_048_576
JSON_SCHEMA_2020_12 =
"https://json-schema.org/draft/2020-12/schema"
REFERENCE_KEYS =
%w[$ref $dynamicRef].freeze

Instance Method Summary collapse

Constructor Details

#initialize(value, label:) ⇒ SchemaContract

Returns a new instance of SchemaContract.



20
21
22
23
# File 'app/models/hitch/mcp/internal/schema_contract.rb', line 20

def initialize(value, label:)
  @label = label
  @schema = copy_schema(value)
end

Instance Method Details

#callObject



25
26
27
28
29
30
31
32
33
# File 'app/models/hitch/mcp/internal/schema_contract.rb', line 25

def call
  invalid!("must be a JSON object") unless @schema.instance_of?(Hash)
  invalid!("exceeds #{MAX_SCHEMA_BYTES} serialized bytes") if serialized_bytes > MAX_SCHEMA_BYTES

  validate_dialects_and_references!
  validate_json_schema!

  @schema
end