Schema DSL for defining parameters in Component modules.
Provides a simple schema do ... end block with field declarations
that generate both JSON Schema (for MCP client introspection) and
NimbleOptions schemas (for server-side runtime validation).
Example
defmodule MyApp.Echo do
use ConduitMcp.Component, type: :tool, description: "Echoes text"
schema do
field :text, :string, "The text to echo", required: true, max_length: 150
field :count, :integer, "Repeat count", default: 1, min: 1, max: 10
end
@impl true
def execute(%{text: text, count: count}, _conn) do
text(String.duplicate(text, count))
end
endSupported Types
:string— String values:integer— Integer values:number— Numeric values (float):boolean— Boolean values:object— Nested objects (use block form with nestedfieldcalls):array/{:array, item_type}— Arrays
Field Options
required: true— Mark as required (default: false)default: value— Default valueenum: [...]— Allowed valuesmin: n/max: n— Numeric constraintsmin_length: n/max_length: n— String length constraintsvalidator: fn— Custom validator function
Summary
Functions
Defines a field in the component schema.
Examples
# Simple field
field :name, :string, "User's name", required: true
# Field with options
field :age, :integer, "User's age", min: 0, max: 150
# Field without description (uses opts keyword)
field :tags, {:array, :string}, "Tag list"
# Nested object field
field :address, :object, "Mailing address", required: true do
field :street, :string, "Street", required: true
field :city, :string, "City", required: true
end
Defines the parameter schema for a component.
Wraps field declarations and accumulates them into @component_fields.