43 lines
3.3 KiB
C#
43 lines
3.3 KiB
C#
using System.ComponentModel;
|
|
using ModelContextProtocol.Server;
|
|
using System.Text.Json.Nodes;
|
|
|
|
namespace PLCSharp.Mcp;
|
|
|
|
[McpServerToolType]
|
|
internal sealed class ProjectTools(ProjectGateway gateway)
|
|
{
|
|
[McpServerTool(Name = "preview_variable_rename"), Description("Preview renaming a recipe user variable by ID. Compile rewritten workflows, and report dynamic or uncertain references for review. Apply the returned draft ID after review.")]
|
|
public string PreviewVariableRename(string id, string newName) => gateway.Call("previewRename", new() { ["id"] = id, ["newName"] = newName });
|
|
|
|
[McpServerTool(Name = "preview_undo"), Description("Preview reversal of a saved variable rename from this session. Apply the new draft ID to confirm undo.")]
|
|
public string PreviewUndo(string draftId) => gateway.Call("previewUndo", new() { ["draftId"] = draftId });
|
|
|
|
[McpServerTool(Name = "preview_workflow_script"), Description("Preview replacement C# source for a workflow ID. Returns a line diff, Roslyn diagnostics, entry-point validation and draft ID. No code runs. Apply a valid draft with apply_changes; a local WPF confirmation is required.")]
|
|
public string PreviewWorkflowScript(string id, string code) =>
|
|
gateway.Call("previewScript", new() { ["id"] = id, ["code"] = code });
|
|
|
|
[McpServerTool(Name = "preview_changes"), Description("Preview a comment change to one recipe, variable or workflow. Returns a draft ID and before/after values. No file is written.")]
|
|
public string PreviewChanges(string kind, string id, string comment) =>
|
|
gateway.Call("preview", new() { ["kind"] = kind, ["id"] = id, ["comment"] = comment });
|
|
|
|
[McpServerTool(Name = "apply_changes"), Description("Save an existing preview using its draft ID. Requires write-enabled launch. An open editor requests user confirmation.")]
|
|
public string ApplyChanges(string draftId) => gateway.Call("apply", new() { ["draftId"] = draftId });
|
|
|
|
[McpServerTool(Name = "get_change_status", ReadOnly = true), Description("Inspect a pending, rejected or saved draft.")]
|
|
public string GetChangeStatus(string draftId) => gateway.Call("status", new() { ["draftId"] = draftId });
|
|
|
|
[McpServerTool(Name = "find_references", ReadOnly = true), Description("Find C# references to a Variables, SystemVariables or Workflows ID within its recipe. Dynamic hits require human review.")]
|
|
public string FindReferences(string kind, string id) => gateway.Call("references", new() { ["kind"] = kind, ["id"] = id });
|
|
|
|
[McpServerTool(Name = "get_project_summary", ReadOnly = true), Description("Read the bound PLCSharp project, default recipe and available object kinds.")]
|
|
public string Summary() => gateway.Call("summary", new());
|
|
|
|
[McpServerTool(Name = "list_objects", ReadOnly = true), Description("List one object kind from the summary, optionally scoped to a recipe. Pages start at offset zero.")]
|
|
public string ListObjects(string kind, string recipeId = null, int offset = 0, int limit = 50) =>
|
|
gateway.Call("list", new() { ["kind"] = kind, ["recipeId"] = recipeId, ["offset"] = offset, ["limit"] = limit });
|
|
|
|
[McpServerTool(Name = "get_object", ReadOnly = true), Description("Read one project object by kind and stable ID, including source for workflows.")]
|
|
public string GetObject(string kind, string id) => gateway.Call("get", new() { ["kind"] = kind, ["id"] = id });
|
|
}
|