-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnodeUpdate.ts
More file actions
31 lines (29 loc) · 1.27 KB
/
nodeUpdate.ts
File metadata and controls
31 lines (29 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { z } from "zod";
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { execDocker, errorResponse } from "../utils/docker-api.js";
const inputSchema = {
node: z.string().min(1).describe("Node ID or hostname"),
availability: z.enum(["active", "pause", "drain"]).optional().describe("Node availability"),
role: z.enum(["worker", "manager"]).optional().describe("Node role"),
labels: z.array(z.string()).optional().describe("Labels to add (e.g. ['env=production', 'region=us-east'])"),
};
export function register(server: McpServer): void {
server.tool(
"docker_nodeUpdate",
"Update metadata on a Docker Swarm node (availability, role, labels)",
inputSchema,
async (args) => {
try {
const cmdArgs = ["node", "update"];
if (args.availability) cmdArgs.push("--availability", args.availability);
if (args.role) cmdArgs.push("--role", args.role);
if (args.labels) for (const l of args.labels) cmdArgs.push("--label-add", l);
cmdArgs.push(args.node);
const output = await execDocker(cmdArgs);
return { content: [{ type: "text" as const, text: output.trim() || `Node '${args.node}' updated` }] };
} catch (error) {
return errorResponse(error);
}
},
);
}