Skip to content

PluginPageTools<TOwner>

Class in Oadm.Sdk.Plugins · Oadm.Sdk.dll

Page methods of a core plugin offered as tools (SDK 0.13.0, docs/spec/mcp.md “Plugins”): each entry wraps one method of the plugin’s page with a typed, strict input (the record TArgs; its JSON Schema is the tool’s input), so a caller does on the page what a user does, with the page’s own checks and rights. A change is a preview that runs the page’s validation and never writes, and a run that validates again and calls the page’s code with the caller. A read, or a start the page does without asking (a check, a scan), is one tool. Never a way to call any page method: only the entries declared here are tools.

public sealed class PluginPageTools<TOwner>

Type parameters

Parameters

Keep one instance in a static field of the plugin and hand its PluginPageTools<TOwner>.Tools to ICorePlugin.Tools. In the plugin’s rules (ICorePlugin.RequiredRole, ICorePlugin.RequiredPermission, ICorePlugin.RequiresAllDevices, ICorePlugin.IsAudited) read a tool method as its page method (PluginPageTools<TOwner>.RulesMethodOf), so a tool has exactly the rights of the page; a preview is never audited (PluginTool.IsPreviewMethod).

PluginPageTools(JsonSerializerOptions? json = null)

Page methods of a core plugin offered as tools (SDK 0.13.0, docs/spec/mcp.md “Plugins”): each entry wraps one method of the plugin’s page with a typed, strict input (the record TArgs; its JSON Schema is the tool’s input), so a caller does on the page what a user does, with the page’s own checks and rights. A change is a preview that runs the page’s validation and never writes, and a run that validates again and calls the page’s code with the caller. A read, or a start the page does without asking (a check, a scan), is one tool. Never a way to call any page method: only the entries declared here are tools.

Parameters

Type parameters

Keep one instance in a static field of the plugin and hand its PluginPageTools<TOwner>.Tools to ICorePlugin.Tools. In the plugin’s rules (ICorePlugin.RequiredRole, ICorePlugin.RequiredPermission, ICorePlugin.RequiresAllDevices, ICorePlugin.IsAudited) read a tool method as its page method (PluginPageTools<TOwner>.RulesMethodOf), so a tool has exactly the rights of the page; a preview is never audited (PluginTool.IsPreviewMethod).

JsonSerializerOptions Json { get; }

The serializer options of every tool here.

IReadOnlyList<PluginTool> Tools { get; }

The tools, in the order they were added.

PluginPageTools<TOwner> Change<TArgs, TPlan, TResult>(PluginTool tool, string pageMethod, Func<TOwner, ICallContext, PluginToolInput<TArgs>, CancellationToken, Task<TPlan>> check, Func<TOwner, ICallContext, PluginToolInput<TArgs>, TPlan, CancellationToken, Task<TResult>> run)

A change: the host offers <name>_preview and <name>_run. The preview calls check, the page’s validation, which answers the plan and never writes. The run calls check again and then run, the page’s code, with the caller and the plan. Let the plan derive from PluginToolPlan so the confirmation card counts what changes.

Parameters

  • tool: The tool’s name, title (“Delete reader”) and description; PluginTool.Destructive for a delete.
  • pageMethod: The page method whose rules the tool has (the one run does).
  • check: Validates the arguments as the page does and answers what the run will do; never writes. Field errors: PluginToolInputException; another refusal: InvalidOperationException with the page’s text.
  • run: Does it, as the page does.
bool Handles(string? method)

True when method is a method of a tool here (a read, a preview or a run).

Task<string> InvokeAsync(TOwner owner, ICallContext caller, string method, string? payloadJson, CancellationToken ct)

Answers a tool method: reads the arguments (no text reads like {}, broken JSON is refused), checks their validation attributes (a field error per property, in the JSON names), and calls the handler with the caller. Field errors come back as PluginToolErrors.Answer.

string? PageMethodOf(string? method)

The page method whose rules a tool method has; null when method is no tool here.

PluginPageTools<TOwner> Read<TArgs, TAnswer>(PluginTool tool, string pageMethod, Func<TOwner, ICallContext, PluginToolInput<TArgs>, CancellationToken, Task<TAnswer>> read)

A read, or a start the page does without asking (a check, a read of devices): one tool tool.<name> that calls read with the caller. tool gives name, title and description (and PluginTool.Permission, PluginTool.DeviceFilter, PluginTool.Paged); input and output come from the type arguments.

Parameters

  • tool: The tool’s name, title and description.
  • pageMethod: The page method whose rules the tool has.
  • read: Answers the call; throws PluginToolInputException for an invalid argument, InvalidOperationException with the page’s text for any other refusal.
string RulesMethodOf(string method)

The method to apply the plugin’s rules to: the page method of a tool method here, else method itself.

PluginTool? ToolOf(string? method)

The tool of a method here; null when there is none.