Module: MicroMcp::Schema

Defined in:
lib/micro_mcp/schema.rb

Defined Under Namespace

Classes: RequiredBuilder, SchemaBuilder

Class Method Summary collapse

Class Method Details

.array(items_type = nil, description = nil) ⇒ Object



91
92
93
94
95
96
# File 'lib/micro_mcp/schema.rb', line 91

def self.array(items_type = nil, description = nil)
  schema = {type: "array"}
  schema[:items] = items_type if items_type
  schema[:description] = description if description
  SchemaBuilder.new(schema)
end

.boolean(description = nil) ⇒ Object



85
86
87
88
89
# File 'lib/micro_mcp/schema.rb', line 85

def self.boolean(description = nil)
  schema = {type: "boolean"}
  schema[:description] = description if description
  SchemaBuilder.new(schema)
end

.integer(description = nil) ⇒ Object

Helper methods for common schema patterns with builder support



67
68
69
70
71
# File 'lib/micro_mcp/schema.rb', line 67

def self.integer(description = nil)
  schema = {type: "integer"}
  schema[:description] = description if description
  SchemaBuilder.new(schema)
end

.number(description = nil) ⇒ Object



79
80
81
82
83
# File 'lib/micro_mcp/schema.rb', line 79

def self.number(description = nil)
  schema = {type: "number"}
  schema[:description] = description if description
  SchemaBuilder.new(schema)
end

.object(**properties) ⇒ Object

Create object schema with properties and required fields



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/micro_mcp/schema.rb', line 99

def self.object(**properties)
  required_fields = []
  schema_properties = {}

  properties.each do |key, value|
    if value.is_a?(Hash) && value[:required] == true
      required_fields << key.to_s
      value = value.dup
      value.delete(:required)
    end
    schema_properties[key] = value
  end

  schema = {
    type: "object",
    properties: schema_properties
  }
  schema[:required] = required_fields unless required_fields.empty?
  schema
end

.requiredObject

Entry point for required-first syntax



121
122
123
# File 'lib/micro_mcp/schema.rb', line 121

def self.required
  RequiredBuilder.new
end

.string(description = nil) ⇒ Object



73
74
75
76
77
# File 'lib/micro_mcp/schema.rb', line 73

def self.string(description = nil)
  schema = {type: "string"}
  schema[:description] = description if description
  SchemaBuilder.new(schema)
end