-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpull.ts
More file actions
52 lines (45 loc) · 1.24 KB
/
pull.ts
File metadata and controls
52 lines (45 loc) · 1.24 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { z } from "zod";
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { execDocker, errorResponse } from "../utils/docker-api.js";
const inputSchema = {
image: z
.string()
.min(1)
.describe("Image to pull (e.g. 'nginx:alpine', 'ubuntu:22.04', 'ghcr.io/org/app:latest')"),
platform: z
.string()
.optional()
.describe("Platform to pull (e.g. 'linux/amd64', 'linux/arm64')"),
allTags: z
.boolean()
.optional()
.default(false)
.describe("Pull all tagged images in the repository"),
};
export function register(server: McpServer): void {
server.tool(
"docker_pull",
"Pull an image or repository from a registry",
inputSchema,
async (args) => {
try {
const cmdArgs = ["pull"];
if (args.platform) {
cmdArgs.push("--platform", args.platform);
}
if (args.allTags) {
cmdArgs.push("--all-tags");
}
cmdArgs.push(args.image);
const output = await execDocker(cmdArgs, { timeout: 300_000 });
return {
content: [
{ type: "text" as const, text: output.trim() },
],
};
} catch (error) {
return errorResponse(error);
}
},
);
}