Class: MCP::Elicitation::EnumSchema
- Inherits:
-
Object
- Object
- MCP::Elicitation::EnumSchema
- Defined in:
- lib/mcp/elicitation/enum_schema.rb
Overview
Builds the four enum schema variants defined by MCP 2025-11-25 (SEP-1330) plus the legacy enumNames form
retained for backward compatibility.
Each class method returns an EnumSchema instance; call to_h to get the property-value Hash and
pass it through requested_schema to ServerSession#create_form_elicitation.
Class Method Summary collapse
-
.legacy_titled(values:, value_titles:, default: nil, title: nil, description: nil) ⇒ Object
Legacy single-select retained for backward compatibility with clients implementing the pre-SEP-1330 form:
{ enum, enumNames }. -
.titled_multi_select(options:, default: nil, title: nil, description: nil) ⇒ Object
Multi-select with display titles per option:
{ type: "array", items: { anyOf: [{ const, title }, ...] } }. -
.titled_single_select(options:, default: nil, title: nil, description: nil) ⇒ Object
Single-select with display titles per option:
{ type: "string", oneOf: [{ const, title }, ...] }. -
.untitled_multi_select(values:, default: nil, title: nil, description: nil) ⇒ Object
Multi-select with plain string values:
{ type: "array", items: { type: "string", enum: [...] } }. -
.untitled_single_select(values:, default: nil, title: nil, description: nil) ⇒ Object
Single-select with plain string values:
{ type: "string", enum: [...] }.
Instance Method Summary collapse
-
#initialize(type:, extras:, default: nil, title: nil, description: nil) ⇒ EnumSchema
constructor
A new instance of EnumSchema.
- #to_h ⇒ Object
Constructor Details
#initialize(type:, extras:, default: nil, title: nil, description: nil) ⇒ EnumSchema
Returns a new instance of EnumSchema.
104 105 106 107 108 109 110 |
# File 'lib/mcp/elicitation/enum_schema.rb', line 104 def initialize(type:, extras:, default: nil, title: nil, description: nil) @type = type @extras = extras @default = default @title = title @description = description end |
Class Method Details
.legacy_titled(values:, value_titles:, default: nil, title: nil, description: nil) ⇒ Object
Legacy single-select retained for backward compatibility with clients implementing
the pre-SEP-1330 form: { enum, enumNames }.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/mcp/elicitation/enum_schema.rb', line 68 def legacy_titled(values:, value_titles:, default: nil, title: nil, description: nil) validate_values!(values) unless value_titles.is_a?(Array) && value_titles.length == values.length raise ArgumentError, "value_titles must be an Array of the same length as values" end new( type: "string", extras: { enum: values, enumNames: value_titles }, default: default, title: title, description: description, ) end |
.titled_multi_select(options:, default: nil, title: nil, description: nil) ⇒ Object
Multi-select with display titles per option: { type: "array", items: { anyOf: [{ const, title }, ...] } }.
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/mcp/elicitation/enum_schema.rb', line 53 def titled_multi_select(options:, default: nil, title: nil, description: nil) () items_anyof = .map { |o| { const: o[:value], title: o[:title] } } new( type: "array", extras: { items: { anyOf: items_anyof } }, default: default, title: title, description: description, ) end |
.titled_single_select(options:, default: nil, title: nil, description: nil) ⇒ Object
Single-select with display titles per option: { type: "string", oneOf: [{ const, title }, ...] }.
options is an Array of { value:, title: } hashes.
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/mcp/elicitation/enum_schema.rb', line 27 def titled_single_select(options:, default: nil, title: nil, description: nil) () new( type: "string", extras: { oneOf: .map { |o| { const: o[:value], title: o[:title] } } }, default: default, title: title, description: description, ) end |
.untitled_multi_select(values:, default: nil, title: nil, description: nil) ⇒ Object
Multi-select with plain string values: { type: "array", items: { type: "string", enum: [...] } }.
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/mcp/elicitation/enum_schema.rb', line 40 def untitled_multi_select(values:, default: nil, title: nil, description: nil) validate_values!(values) new( type: "array", extras: { items: { type: "string", enum: values } }, default: default, title: title, description: description, ) end |
.untitled_single_select(values:, default: nil, title: nil, description: nil) ⇒ Object
Single-select with plain string values: { type: "string", enum: [...] }.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/mcp/elicitation/enum_schema.rb', line 13 def untitled_single_select(values:, default: nil, title: nil, description: nil) validate_values!(values) new( type: "string", extras: { enum: values }, default: default, title: title, description: description, ) end |
Instance Method Details
#to_h ⇒ Object
112 113 114 115 116 117 118 |
# File 'lib/mcp/elicitation/enum_schema.rb', line 112 def to_h hash = { type: @type }.merge(@extras) hash[:title] = @title if @title hash[:description] = @description if @description hash[:default] = @default unless @default.nil? hash end |