-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommit.ts
More file actions
79 lines (70 loc) · 1.79 KB
/
commit.ts
File metadata and controls
79 lines (70 loc) · 1.79 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { z } from "zod";
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { execDocker, errorResponse } from "../utils/docker-api.js";
const inputSchema = {
containerId: z
.string()
.min(1)
.describe("Container name or ID to commit"),
repository: z
.string()
.optional()
.describe("Repository name for the new image (e.g. 'myapp')"),
tag: z
.string()
.optional()
.describe("Tag for the new image (e.g. 'v1.0')"),
message: z
.string()
.optional()
.describe("Commit message"),
author: z
.string()
.optional()
.describe("Author (e.g. 'Name <email>')"),
pause: z
.boolean()
.optional()
.default(true)
.describe("Pause container during commit (default: true)"),
};
export function register(server: McpServer): void {
server.tool(
"docker_commit",
"Create a new image from a container's changes",
inputSchema,
async (args) => {
try {
const cmdArgs = ["commit"];
if (args.message) {
cmdArgs.push("-m", args.message);
}
if (args.author) {
cmdArgs.push("-a", args.author);
}
if (!args.pause) {
cmdArgs.push("--pause=false");
}
cmdArgs.push(args.containerId);
if (args.repository) {
const target = args.tag
? `${args.repository}:${args.tag}`
: args.repository;
cmdArgs.push(target);
}
const output = await execDocker(cmdArgs);
const imageId = output.trim();
return {
content: [
{
type: "text" as const,
text: `Image created: ${imageId}`,
},
],
};
} catch (error) {
return errorResponse(error);
}
},
);
}