Snodo.Tool.Simple (snodo v0.2.0)

Copy Markdown View Source

Opt-in argument DSL for tools with straightforward object input schemas.

Snodo.Tool.Simple builds the same raw JSON Schema returned by Snodo.Tool and leaves call/2 untouched. Argument maps therefore retain protocol-native string keys, and simple tools register in Snodo.Router exactly like raw tools.

defmodule Search do
  use Snodo.Tool.Simple,
    name: "search",
    description: "Search packages",
    additional_properties: false

  argument("query", :string, required: true, min_length: 1)
  argument("page", :integer, minimum: 1)
  argument("sort", :string, enum: ["name", "downloads"])
  argument("tags", {:array, :string}, unique_items: true)

  @impl true
  def call(%{"query" => query} = arguments, _context) do
    {:ok, Snodo.Result.text("searching for #{query} on page #{arguments["page"] || 1}")}
  end
end

An argument type may be one of the JSON primitive atoms, {:array, type}, or a raw property-schema map. The :schema option merges arbitrary JSON Schema keywords into a generated property, providing a local escape hatch without abandoning the concise form. The raw Snodo.Tool DSL remains available when the input root itself needs complete hand-authored control.

Summary

Functions

Declares one property of the tool's input schema.

Functions

argument(name, type, opts \\ [])

(macro)

Declares one property of the tool's input schema.

name is the property name as a string. type is a JSON type atom (:string, :integer, :number, :boolean, :array, :object, or :null), {:array, type} for an array whose "items" has that type, or a raw property-schema map.

Options:

  • :required - when true, adds name to the schema's "required" list. Defaults to false.
  • :description, :default, :enum, :pattern - set the JSON Schema keyword of the same name.
  • :min_length, :max_length, :min_items, :max_items, :minimum, :maximum, :exclusive_minimum, :exclusive_maximum, :unique_items - set the camel-case JSON Schema keyword, such as "minLength".
  • :schema - a map of other JSON Schema keywords, merged into the property last, so it overrides the generated keys.

An empty or repeated name, an unknown or repeated option, or an option value of the wrong type is a compile error.