Alternera.Plugin.Provisional.Tools behaviour (alternera_plugin_sdk v0.9.0)

Copy Markdown View Source

Provisional: added for the Camel step's written routes, and a change to it needs a changelog line but no new major (docs/USER_PLUGINS_DESIGN.md). The namespace has nothing to do with the context's :provisional? key.

Tools a plugin adds to the proxy's MCP server, for agents writing its steps: checking what a step holds against the plugin's outside world, or reading what that world offers. The proxy reads tools/0 when it compiles, from every plugin the build knows (shipped, experimental and configured), and offers a plugin's tools only while the plugin is installed. A tool runs in the calling tenant, through run_tool/3.

A tool's name starts with the plugin's id and an underscore (camel_check_route), in lower case letters, digits and underscores; the proxy refuses to compile a tool named otherwise or named twice.

access says what a tool reads or does, which decides who may call it and whether the in-app assistant may:

  • :config reads configuration and nothing a request carried: offered to every role and to the assistant.
  • :data reads or returns what traffic carried, or a live answer from outside: every role, and the assistant only where the tenant lets it read data.
  • :editing writes nothing but acts as an editor of pipelines does, on text the caller chooses (a check that resolves the tenant's secrets into it and hands it to an outside process): a tenant admin, and the assistant without asking.
  • :card changes something: a tenant admin, and the assistant asks the user first.

Summary

Types

An argument: its type (:string, :integer, :boolean, :map, or a list of strings or maps), what it is for, and whether a call must give it.

Callbacks

Runs tool name with arguments (string keys, only those the call gave) for context's :tenant_id: {:ok, answer}, a map the proxy returns as JSON, or {:error, message}, which the caller reads.

The plugin's tools.

Types

access()

@type access() :: :config | :data | :editing | :card

argument()

@type argument() :: %{
  :name => String.t(),
  :type => :string | :integer | :boolean | :map | {:array, :string | :map},
  :description => String.t(),
  optional(:required?) => boolean()
}

An argument: its type (:string, :integer, :boolean, :map, or a list of strings or maps), what it is for, and whether a call must give it.

tool()

@type tool() :: %{
  name: String.t(),
  description: String.t(),
  arguments: [argument()],
  access: access()
}

Callbacks

run_tool(name, arguments, context)

@callback run_tool(
  name :: String.t(),
  arguments :: map(),
  context :: %{tenant_id: term()}
) ::
  {:ok, map()} | {:error, String.t()}

Runs tool name with arguments (string keys, only those the call gave) for context's :tenant_id: {:ok, answer}, a map the proxy returns as JSON, or {:error, message}, which the caller reads.

tools()

@callback tools() :: [tool()]

The plugin's tools.