Class: MCP::Tool::Schema
- Inherits:
-
Object
- Object
- MCP::Tool::Schema
- Defined in:
- lib/mcp/tool/schema.rb
Direct Known Subclasses
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), and SEP-2106 requires tool schemas to conform to the full 2020-12 vocabulary. Both emission and runtime validation use this dialect. Because MCP mandates 2020-12, the SDK validates against it regardless of any ‘$schema` a document embeds; for compliant schemas this is the same dialect the Python SDK’s ‘jsonschema.validate` resolves to.
"https://json-schema.org/draft/2020-12/schema"- MAX_SCHEMA_DEPTH =
Resource bounds for schema compilation, mirroring the TypeScript SDK’s schema bounds (SEP-2106): schemas may use the full JSON Schema 2020-12 vocabulary including composition keywords and ‘$ref`, so adversarial documents must be rejected before they can cause excessive validation cost. Only same-document references (starting with `#`) are accepted, so schema handling can never trigger network or file access.
64- MAX_SUBSCHEMA_COUNT =
10_000- REFERENCE_KEYWORDS =
Reference keywords whose targets the SDK refuses to dereference. Both ‘$ref` and `$dynamicRef` may carry an absolute URI under JSON Schema 2020-12, so a non-same-document value is an external reference.
[:"$ref", :"$dynamicRef"].freeze
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(schema = {}) ⇒ Schema
constructor
A new instance of Schema.
- #to_h ⇒ Object
Constructor Details
#initialize(schema = {}) ⇒ Schema
Returns a new instance of Schema.
58 59 60 61 62 63 |
# File 'lib/mcp/tool/schema.rb', line 58 def initialize(schema = {}) @schema = JSON.parse(JSON.dump(schema), symbolize_names: true) apply_default_root_type! validate_schema_bounds! validate_schema! end |
Instance Method Details
#==(other) ⇒ Object
65 66 67 |
# File 'lib/mcp/tool/schema.rb', line 65 def ==(other) other.is_a?(self.class) && @schema == other.instance_variable_get(:@schema) end |
#to_h ⇒ Object
69 70 71 72 73 |
# File 'lib/mcp/tool/schema.rb', line 69 def to_h return @schema if @schema.key?(:"$schema") { "$schema": JSON_SCHEMA_2020_12_URI }.merge(@schema) end |