-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnodeExec.ts
More file actions
35 lines (32 loc) · 1 KB
/
Copy pathnodeExec.ts
File metadata and controls
35 lines (32 loc) · 1 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
32
33
34
35
import { z } from "zod";
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { execSSH, errorResponse } from "../utils/ssh-api.js";
import { confirmParam, confirmCancelled } from "../utils/confirm-param.js";
const inputSchema = {
node: z.string().min(1).describe("Target node name from the node registry"),
command: z.string().min(1).describe("Shell command to execute on the node"),
...confirmParam,
};
export function register(server: McpServer): void {
server.tool(
"homelab_nodeExec",
"Execute a shell command on a specific node by name",
inputSchema,
async (args) => {
if (!args.confirm) {
return confirmCancelled("Execution");
}
try {
const output = await execSSH(args.command, args.node);
return {
content: [{
type: "text" as const,
text: output || "(command produced no output)",
}],
};
} catch (error) {
return errorResponse(error);
}
},
);
}