-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnodePs.ts
More file actions
28 lines (26 loc) · 1.07 KB
/
nodePs.ts
File metadata and controls
28 lines (26 loc) · 1.07 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
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().optional().describe("Node ID or hostname (defaults to current node)"),
filter: z.array(z.string()).optional().describe("Filters (e.g. ['desired-state=running'])"),
format: z.string().optional().default("json").describe("Output format (default: json)"),
};
export function register(server: McpServer): void {
server.tool(
"docker_nodePs",
"List tasks running on a Docker Swarm node",
inputSchema,
async (args) => {
try {
const cmdArgs = ["node", "ps", "--format", args.format ?? "json"];
if (args.filter) for (const f of args.filter) cmdArgs.push("--filter", f);
if (args.node) cmdArgs.push(args.node);
const output = await execDocker(cmdArgs);
return { content: [{ type: "text" as const, text: output.trim() || "No tasks found" }] };
} catch (error) {
return errorResponse(error);
}
},
);
}