Skip to content

PluginTool

Record in Oadm.Sdk.Plugins · Oadm.Sdk.dll

One tool of a core plugin (SDK 0.13.0, ICorePlugin.Tools): a step a program, such as an assistant, may take in the plugin without its page, described once so that a caller can read what it takes and what it answers. The tool knows nothing of the channel that calls it; the host lists it only while the plugin is on and the caller’s role has its permission, checks the arguments against the input schema, and calls the plugin’s own ICorePlugin.InvokeAsync with the caller (the methods PluginTool.Method, PluginTool.PreviewMethod and PluginTool.RunMethod), so every rule of the plugin’s page applies.

public sealed record PluginTool(string Name, string Title, string Description)

Parameters

  • Name: What the tool does, in lower case words with underscores (“certificates”, “certificate_create”); the host adds the plugin’s area in front.
  • Title: The name for a person (“Certificate list”).
  • Description: One to three short sentences: what the tool does and when to call it. Never a text of a device or a user.
string? Area { get; init; }

The area of this tool’s name instead of the plugin’s ICorePlugin.ToolArea, lower case words with underscores: VAPIX Commander’s request tool is oadm_device_request. Null: the plugin’s area. A name a host tool has is never taken over.

bool Changes { get; init; }

The tool changes something: the host makes two tools of it, <name>_preview (calls PluginTool.PreviewMethod, which checks everything and never writes) and <name>_run (takes only the handle of a preview and calls PluginTool.RunMethod, which checks everything again).

string Description { get; init; }

One to three short sentences: what the tool does and when to call it. Never a text of a device or a user.

bool Destructive { get; init; }

A change that removes something or cannot be taken back (an honest hint for the caller).

bool DeviceFilter { get; init; }

The tool works on devices the caller chooses: the host adds filter (the device filter of the host’s device tools, with the assistant’s selection) to the input, finds the matching devices of the caller’s view (at most PluginTool.MaxDevices, by address) and hands the plugin device_ids and devices_total instead of the filter (read them with PluginToolDevices.Of). The input type has no property of these names.

bool? Idempotent { get; init; }

Calling again with the same arguments changes nothing more; default true for a read, false for a change.

string? InputSchema { get; init; }

The input as JSON Schema text instead of PluginTool.InputType: an object with additionalProperties: false.

Type? InputType { get; init; }

The record of the arguments. The host exports its JSON Schema with the plugin’s PluginTool.JsonOptions (descriptions and validation attributes become the schema’s words; objects take no other properties; text, number and list have a bound). Null together with PluginTool.InputSchema: the tool takes no argument. A type with a secret property is never offered.

JsonSerializerOptions? JsonOptions { get; init; }

The serializer options of the input and output types (their names and enum texts); null: PluginJson.CreateOptions.

string Method { get; }

The method of ICorePlugin.InvokeAsync a read calls, and the run of a change: tool.<name>.

string Name { get; init; }

What the tool does, in lower case words with underscores (“certificates”, “certificate_create”); the host adds the plugin’s area in front.

string? OutputSchema { get; init; }

The answer as JSON Schema text instead of PluginTool.OutputType.

Type? OutputType { get; init; }

The record of the answer (a JSON object) of PluginTool.Method for a read, of PluginTool.PreviewMethod for a change (the plan the host adds handle and expires to, so the type has no property of these names).

bool Paged { get; init; }

A list: the host adds limit (1 to PluginTool.MaxRows, default PluginTool.DefaultRows) and cursor to the input, reads the cursor and hands the plugin limit and after (the sort key of the last row of the page before, see PluginToolPage); the answer’s next (the sort key of the last row, null at the end) becomes next_cursor. The output type has total and next.

string? Permission { get; init; }

A right of the plugin (a key of ICorePlugin.Permissions, or PermissionKeys.Show) the caller needs on top of what the plugin asks for the method (ICorePlugin.RequiredRole, ICorePlugin.RequiredPermission); null: the method’s own rule is the permission.

string PreviewMethod { get; }

The method of the preview of a change: tool.<name>.preview. It never writes.

bool ReturnsFile { get; init; }

The answer may hand the caller a file (SDK 0.13.0): a property file of type PluginToolFile (null when there is none) names one of the plugin’s downloads (ICorePluginDownloads) and its payload. The host never passes the bytes through the answer: it replaces file with a file reference the caller turns into a one-time download link (an agent) or a file card with Save (the assistant). The bytes are read only then, through PluginService.Download as the caller (the download’s permission, device group and audit). Never a backup, a private key or a PKCS#12 file, except a key backup protected with a password from the secret channel (PKI’s CA key backup).

string RunMethod { get; }

The method of the run of a change (the same as PluginTool.Method).

string? RunOutputSchema { get; init; }

The answer of PluginTool.RunMethod as JSON Schema text instead of PluginTool.RunOutputType.

Type? RunOutputType { get; init; }

The record of the answer of PluginTool.RunMethod (a change).

IReadOnlyList<PluginToolSecret> Secrets { get; init; }

Secrets the run of a change may need (SDK 0.13.0, docs/spec/mcp.md “Secrets”): a password, a shared secret. They never pass through a model or an argument. The preview’s plan chooses which the run needs with PluginToolPlan.SecretsNeeded (some of these, or secrets it names itself, such as one per saved command); a plan that names none needs all of these. The host declares them on the preview’s handle, the person enters them in their own shell or the assistant’s card, the preview method checks each entered value (a field error at secrets.<name> refuses it), and the run gets them in PluginToolInput<TArgs>.Secrets. A change only; at most 8 per preview.

string? TaskPlugin { get; init; }

The id of a task plugin of the same package whose dialog reads what this tool reads: the host lists the tool only for a caller with at least one permission of that task, like the reads of its dialog (TaskService.Query). A page call reaches the method without this check, so the plugin checks it again with ICallContext.Has. Null: none.

string Title { get; init; }

The name for a person (“Certificate list”).

bool Calls(string method)

True when method is one of this tool’s methods.

static JsonSerializerOptions CreateJsonOptions()

New serializer options in the style of the host’s own tools: names in snake_case (“next_cursor”), enums by their snake_case name, nulls written, names read in any case. Keep them in a static field of the plugin (PluginJson.CreateOptions).

static bool IsPreviewMethod(string? method)

True when method only reads or previews (never writes): every tool method but the run of a change.

static bool IsToolMethod(string? method)

True when method belongs to a tool of the host (a plugin names its tool methods with it).

const int DefaultRows = 50

Rows of a list by default (PluginTool.Paged).

const int MaxDevices = 500

Devices a tool with PluginTool.DeviceFilter gets at most (the first by address; PluginToolDevices.Total says how many matched).

const int MaxNameLength = 40

The longest name.

const int MaxRows = 200

Rows of a list at most (PluginTool.Paged).