Sake.Tool behaviour (Sake v0.1.0)

Copy Markdown View Source

A tool: use Sake.Tool with options, arg lines, an optional output block, and execute/2.

defmodule MyApp.MCP.SearchIssues do
  use Sake.Tool, name: "search_issues", description: "Search issues", scope: "issues:read"
  arg :query, :string, required: true
  @impl true
  def execute(%{query: q}, ctx), do: {:ok, Issues.search(ctx.scope, q)}
end

Options: name (default: the module's last segment in snake case), title, description, icons, scope (one or many), annotations (read_only, destructive, idempotent, open_world), stream, ttl, meta, input_schema (a schema map instead of arg lines).

Summary

Functions

Declares an argument (or, inside output, an output property).

Declares the output schema with arg lines.

Callbacks

complete(arg, partial, ctx)

(optional)
@callback complete(arg :: String.t(), partial :: String.t(), ctx :: Sake.Context.t()) ::
  {:ok, [String.t()]} | {:ok, [String.t()], keyword()}

execute(args, ctx)

@callback execute(args :: map(), ctx :: Sake.Context.t()) ::
  {:ok, term()} | {:ok, term(), keyword()} | {:error, String.t()}

spec()

@callback spec() :: Sake.Tool.Spec.t()

Functions

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

(macro)

Declares an argument (or, inside output, an output property).

output(list)

(macro)

Declares the output schema with arg lines.