dokploy-mcp-server 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,1775 @@
1
+ import dotenv from "dotenv";
2
+ import { FastMCP } from "fastmcp";
3
+ import { z } from "zod";
4
+
5
+ //#region src/client/dokploy-client.ts
6
+ var DokployClient = class {
7
+ baseUrl;
8
+ apiKey;
9
+ constructor(baseUrl, apiKey) {
10
+ this.baseUrl = baseUrl.replace(/\/+$/, "");
11
+ this.apiKey = apiKey;
12
+ }
13
+ async get(path, params) {
14
+ return this.request(path, {
15
+ method: "GET",
16
+ params
17
+ });
18
+ }
19
+ async post(path, body) {
20
+ return this.request(path, {
21
+ method: "POST",
22
+ body
23
+ });
24
+ }
25
+ async request(path, options) {
26
+ const url = new URL(`/api/${path}`, this.baseUrl);
27
+ if (options.params) {
28
+ for (const [key, value] of Object.entries(options.params)) if (value !== void 0) url.searchParams.set(key, String(value));
29
+ }
30
+ const headers = {
31
+ "x-api-key": this.apiKey,
32
+ Accept: "application/json"
33
+ };
34
+ const init = {
35
+ method: options.method,
36
+ headers
37
+ };
38
+ if (options.body) {
39
+ headers["Content-Type"] = "application/json";
40
+ init.body = JSON.stringify(options.body);
41
+ }
42
+ const response = await fetch(url.toString(), init);
43
+ if (!response.ok) {
44
+ const errorText = await response.text().catch(() => "Unknown error");
45
+ throw new Error(`Dokploy API error (${response.status} ${response.statusText}) on ${options.method} /${path}: ${errorText}`);
46
+ }
47
+ const text = await response.text();
48
+ if (!text) return;
49
+ return JSON.parse(text);
50
+ }
51
+ };
52
+ let client;
53
+ function initializeDokployClient(baseUrl, apiKey) {
54
+ client = new DokployClient(baseUrl, apiKey);
55
+ return client;
56
+ }
57
+ function getDokployClient() {
58
+ if (!client) throw new Error("Dokploy client not initialized. Ensure DOKPLOY_URL and DOKPLOY_API_KEY environment variables are set.");
59
+ return client;
60
+ }
61
+
62
+ //#endregion
63
+ //#region src/utils/formatters.ts
64
+ function formatDate(dateStr) {
65
+ if (!dateStr) return "N/A";
66
+ try {
67
+ return new Date(dateStr).toISOString().replace("T", " ").replace(/\.\d+Z$/, " UTC");
68
+ } catch {
69
+ return dateStr;
70
+ }
71
+ }
72
+ function statusIcon(status) {
73
+ const s = status.toLowerCase();
74
+ if (s === "running" || s === "done" || s === "idle") return "[RUNNING]";
75
+ if (s === "error" || s === "failed") return "[ERROR]";
76
+ if (s === "stopped") return "[STOPPED]";
77
+ return `[${status.toUpperCase()}]`;
78
+ }
79
+ function formatProject(project) {
80
+ var _project$environments;
81
+ const envCount = ((_project$environments = project.environments) === null || _project$environments === void 0 ? void 0 : _project$environments.length) ?? 0;
82
+ return `- **${project.name}** (ID: ${project.projectId})
83
+ Description: ${project.description || "None"}
84
+ Environments: ${envCount}
85
+ Created: ${formatDate(project.createdAt)}`;
86
+ }
87
+ function formatProjectList(projects) {
88
+ if (projects.length === 0) return "No projects found.";
89
+ return `# Projects (${projects.length})\n\n${projects.map(formatProject).join("\n\n")}`;
90
+ }
91
+ function formatEnvironment(env) {
92
+ return `- **${env.name}** (ID: ${env.environmentId})
93
+ Description: ${env.description || "None"}
94
+ Project: ${env.projectId}
95
+ Created: ${formatDate(env.createdAt)}`;
96
+ }
97
+ function formatEnvironmentList(envs) {
98
+ if (envs.length === 0) return "No environments found.";
99
+ return `# Environments (${envs.length})\n\n${envs.map(formatEnvironment).join("\n\n")}`;
100
+ }
101
+ function formatApplication(app) {
102
+ return `- **${app.name}** ${statusIcon(app.applicationStatus)} (ID: ${app.applicationId})
103
+ App Name: ${app.appName}
104
+ Description: ${app.description || "None"}
105
+ Build Type: ${app.buildType || "N/A"}
106
+ Source: ${app.sourceType || "N/A"}
107
+ Auto Deploy: ${app.autoDeploy ?? "N/A"}
108
+ Created: ${formatDate(app.createdAt)}`;
109
+ }
110
+ function formatDeployment(dep) {
111
+ return `- ${statusIcon(dep.status)} **${dep.title || "Deployment"}** (ID: ${dep.deploymentId})
112
+ Status: ${dep.status}
113
+ Description: ${dep.description || "None"}
114
+ Created: ${formatDate(dep.createdAt)}`;
115
+ }
116
+ function formatDeploymentList(deployments) {
117
+ if (deployments.length === 0) return "No deployments found.";
118
+ return `# Deployments (${deployments.length})\n\n${deployments.map(formatDeployment).join("\n\n")}`;
119
+ }
120
+ function formatCompose(compose) {
121
+ return `- **${compose.name}** ${statusIcon(compose.composeStatus)} (ID: ${compose.composeId})
122
+ App Name: ${compose.appName}
123
+ Description: ${compose.description || "None"}
124
+ Type: ${compose.composeType || "N/A"}
125
+ Source: ${compose.sourceType || "N/A"}
126
+ Created: ${formatDate(compose.createdAt)}`;
127
+ }
128
+ function formatDomain(domain) {
129
+ return `- **${domain.https ? "https" : "http"}://${domain.host}${domain.path || ""}** (ID: ${domain.domainId})
130
+ Port: ${domain.port ?? "default"}
131
+ HTTPS: ${domain.https}
132
+ Certificate: ${domain.certificateType || "None"}
133
+ Type: ${domain.domainType || "N/A"}
134
+ Service: ${domain.serviceName || "N/A"}`;
135
+ }
136
+ function formatDomainList(domains) {
137
+ if (domains.length === 0) return "No domains found.";
138
+ return `# Domains (${domains.length})\n\n${domains.map(formatDomain).join("\n\n")}`;
139
+ }
140
+ function formatServer(server) {
141
+ return `- **${server.name}** (ID: ${server.serverId})
142
+ Description: ${server.description || "None"}
143
+ IP: ${server.ipAddress}:${server.port}
144
+ User: ${server.username}
145
+ Type: ${server.serverType}
146
+ Created: ${formatDate(server.createdAt)}`;
147
+ }
148
+ function formatServerList(servers) {
149
+ if (servers.length === 0) return "No servers found.";
150
+ return `# Servers (${servers.length})\n\n${servers.map(formatServer).join("\n\n")}`;
151
+ }
152
+ function formatDatabase(db, dbType) {
153
+ return `- **${db.name}** ${statusIcon(db.applicationStatus)} (ID: ${db.databaseId})
154
+ Type: ${dbType}
155
+ App Name: ${db.appName}
156
+ Description: ${db.description || "None"}
157
+ Database Name: ${db.databaseName || "N/A"}
158
+ Image: ${db.dockerImage || "default"}
159
+ External Port: ${db.externalPort ?? "None"}
160
+ Created: ${formatDate(db.createdAt)}`;
161
+ }
162
+ function formatContainer(container) {
163
+ var _container$state;
164
+ return `- **${container.name}** [${((_container$state = container.state) === null || _container$state === void 0 ? void 0 : _container$state.toUpperCase()) || "UNKNOWN"}]
165
+ ID: ${container.containerId}
166
+ Image: ${container.image}
167
+ Status: ${container.status}
168
+ Ports: ${container.ports || "None"}`;
169
+ }
170
+ function formatContainerList(containers) {
171
+ if (containers.length === 0) return "No containers found.";
172
+ return `# Containers (${containers.length})\n\n${containers.map(formatContainer).join("\n\n")}`;
173
+ }
174
+ function formatBackup(backup) {
175
+ return `- **${backup.prefix}** (ID: ${backup.backupId})
176
+ Schedule: ${backup.schedule}
177
+ Enabled: ${backup.enabled ?? true}
178
+ Database: ${backup.database}
179
+ Type: ${backup.databaseType}
180
+ Destination: ${backup.destinationId}
181
+ Keep Latest: ${backup.keepLatestCount ?? "unlimited"}`;
182
+ }
183
+
184
+ //#endregion
185
+ //#region src/tools/application-tools.ts
186
+ function registerApplicationTools(server) {
187
+ server.addTool({
188
+ name: "dokploy_application_create",
189
+ description: "Create a new application in an environment",
190
+ parameters: z.object({
191
+ name: z.string().describe("Application name"),
192
+ environmentId: z.string().describe("Environment ID to create the application in"),
193
+ description: z.string().optional().describe("Application description"),
194
+ serverId: z.string().optional().describe("Server ID to deploy on (optional for remote servers)")
195
+ }),
196
+ execute: async (args) => {
197
+ return `# Application Created\n\n${formatApplication(await getDokployClient().post("application.create", {
198
+ name: args.name,
199
+ environmentId: args.environmentId,
200
+ ...args.description && { description: args.description },
201
+ ...args.serverId && { serverId: args.serverId }
202
+ }))}`;
203
+ }
204
+ });
205
+ server.addTool({
206
+ name: "dokploy_application_get",
207
+ description: "Get details for a specific application",
208
+ parameters: z.object({ applicationId: z.string().describe("The application ID") }),
209
+ execute: async (args) => {
210
+ return `# Application Details\n\n${formatApplication(await getDokployClient().get("application.one", { applicationId: args.applicationId }))}`;
211
+ }
212
+ });
213
+ server.addTool({
214
+ name: "dokploy_application_deploy",
215
+ description: "Deploy an application (trigger a new deployment)",
216
+ parameters: z.object({
217
+ applicationId: z.string().describe("The application ID to deploy"),
218
+ title: z.string().optional().describe("Deployment title"),
219
+ description: z.string().optional().describe("Deployment description")
220
+ }),
221
+ execute: async (args) => {
222
+ await getDokployClient().post("application.deploy", {
223
+ applicationId: args.applicationId,
224
+ ...args.title && { title: args.title },
225
+ ...args.description && { description: args.description }
226
+ });
227
+ return `Deployment triggered for application ${args.applicationId}.`;
228
+ }
229
+ });
230
+ server.addTool({
231
+ name: "dokploy_application_redeploy",
232
+ description: "Redeploy an application",
233
+ parameters: z.object({
234
+ applicationId: z.string().describe("The application ID to redeploy"),
235
+ title: z.string().optional().describe("Deployment title"),
236
+ description: z.string().optional().describe("Deployment description")
237
+ }),
238
+ execute: async (args) => {
239
+ await getDokployClient().post("application.redeploy", {
240
+ applicationId: args.applicationId,
241
+ ...args.title && { title: args.title },
242
+ ...args.description && { description: args.description }
243
+ });
244
+ return `Redeployment triggered for application ${args.applicationId}.`;
245
+ }
246
+ });
247
+ server.addTool({
248
+ name: "dokploy_application_start",
249
+ description: "Start a stopped application",
250
+ parameters: z.object({ applicationId: z.string().describe("The application ID to start") }),
251
+ execute: async (args) => {
252
+ await getDokployClient().post("application.start", { applicationId: args.applicationId });
253
+ return `Application ${args.applicationId} started.`;
254
+ }
255
+ });
256
+ server.addTool({
257
+ name: "dokploy_application_stop",
258
+ description: "Stop a running application",
259
+ parameters: z.object({ applicationId: z.string().describe("The application ID to stop") }),
260
+ execute: async (args) => {
261
+ await getDokployClient().post("application.stop", { applicationId: args.applicationId });
262
+ return `Application ${args.applicationId} stopped.`;
263
+ }
264
+ });
265
+ server.addTool({
266
+ name: "dokploy_application_delete",
267
+ description: "Delete an application permanently",
268
+ parameters: z.object({ applicationId: z.string().describe("The application ID to delete") }),
269
+ execute: async (args) => {
270
+ await getDokployClient().post("application.delete", { applicationId: args.applicationId });
271
+ return `Application ${args.applicationId} deleted.`;
272
+ }
273
+ });
274
+ server.addTool({
275
+ name: "dokploy_application_update",
276
+ description: "Update application configuration (name, description, docker image, build settings, resources, etc.)",
277
+ parameters: z.object({
278
+ applicationId: z.string().describe("The application ID to update"),
279
+ name: z.string().optional().describe("New application name"),
280
+ description: z.string().optional().describe("New description"),
281
+ dockerImage: z.string().optional().describe("Docker image to use"),
282
+ command: z.string().optional().describe("Custom command"),
283
+ memoryLimit: z.number().optional().describe("Memory limit in MB"),
284
+ cpuLimit: z.number().optional().describe("CPU limit"),
285
+ replicas: z.number().optional().describe("Number of replicas"),
286
+ autoDeploy: z.boolean().optional().describe("Enable auto-deploy on push")
287
+ }),
288
+ execute: async (args) => {
289
+ const client = getDokployClient();
290
+ const { applicationId, ...updates } = args;
291
+ const body = { applicationId };
292
+ for (const [key, value] of Object.entries(updates)) if (value !== void 0) body[key] = value;
293
+ await client.post("application.update", body);
294
+ return `Application ${applicationId} updated.`;
295
+ }
296
+ });
297
+ server.addTool({
298
+ name: "dokploy_application_saveEnvironment",
299
+ description: "Save environment variables for an application",
300
+ parameters: z.object({
301
+ applicationId: z.string().describe("The application ID"),
302
+ env: z.string().optional().describe("Environment variables (KEY=VALUE format, newline separated)"),
303
+ buildArgs: z.string().optional().describe("Build arguments"),
304
+ createEnvFile: z.boolean().describe("Whether to create a .env file in the container")
305
+ }),
306
+ execute: async (args) => {
307
+ await getDokployClient().post("application.saveEnvironment", {
308
+ applicationId: args.applicationId,
309
+ createEnvFile: args.createEnvFile,
310
+ ...args.env !== void 0 && { env: args.env },
311
+ ...args.buildArgs !== void 0 && { buildArgs: args.buildArgs }
312
+ });
313
+ return `Environment saved for application ${args.applicationId}.`;
314
+ }
315
+ });
316
+ server.addTool({
317
+ name: "dokploy_application_saveBuildType",
318
+ description: "Configure the build type for an application (dockerfile, nixpacks, heroku, etc.)",
319
+ parameters: z.object({
320
+ applicationId: z.string().describe("The application ID"),
321
+ buildType: z.string().describe("Build type (dockerfile, nixpacks, heroku, buildpacks, railpack, static)"),
322
+ dockerfile: z.string().optional().describe("Dockerfile path"),
323
+ dockerContextPath: z.string().optional().describe("Docker context path"),
324
+ dockerBuildStage: z.string().optional().describe("Docker build stage"),
325
+ publishDirectory: z.string().optional().describe("Publish directory for static builds")
326
+ }),
327
+ execute: async (args) => {
328
+ await getDokployClient().post("application.saveBuildType", {
329
+ applicationId: args.applicationId,
330
+ buildType: args.buildType,
331
+ dockerContextPath: args.dockerContextPath || ".",
332
+ dockerBuildStage: args.dockerBuildStage || "",
333
+ ...args.dockerfile && { dockerfile: args.dockerfile },
334
+ ...args.publishDirectory && { publishDirectory: args.publishDirectory }
335
+ });
336
+ return `Build type set to "${args.buildType}" for application ${args.applicationId}.`;
337
+ }
338
+ });
339
+ server.addTool({
340
+ name: "dokploy_application_readMonitoring",
341
+ description: "Read monitoring metrics for an application",
342
+ parameters: z.object({ appName: z.string().describe("The internal app name") }),
343
+ execute: async (args) => {
344
+ const data = await getDokployClient().get("application.readAppMonitoring", { appName: args.appName });
345
+ return `# Monitoring Data for ${args.appName}\n\n\`\`\`json\n${JSON.stringify(data, null, 2)}\n\`\`\``;
346
+ }
347
+ });
348
+ server.addTool({
349
+ name: "dokploy_application_readTraefikConfig",
350
+ description: "Read the Traefik configuration for an application",
351
+ parameters: z.object({ applicationId: z.string().describe("The application ID") }),
352
+ execute: async (args) => {
353
+ const config = await getDokployClient().get("application.readTraefikConfig", { applicationId: args.applicationId });
354
+ return `# Traefik Config for ${args.applicationId}\n\n\`\`\`yaml\n${config}\n\`\`\``;
355
+ }
356
+ });
357
+ server.addTool({
358
+ name: "dokploy_application_updateTraefikConfig",
359
+ description: "Update the Traefik configuration for an application",
360
+ parameters: z.object({
361
+ applicationId: z.string().describe("The application ID"),
362
+ traefikConfig: z.string().describe("The Traefik configuration content")
363
+ }),
364
+ execute: async (args) => {
365
+ await getDokployClient().post("application.updateTraefikConfig", {
366
+ applicationId: args.applicationId,
367
+ traefikConfig: args.traefikConfig
368
+ });
369
+ return `Traefik config updated for application ${args.applicationId}.`;
370
+ }
371
+ });
372
+ server.addTool({
373
+ name: "dokploy_application_reload",
374
+ description: "Reload an application without a full redeploy",
375
+ parameters: z.object({
376
+ applicationId: z.string().describe("The application ID"),
377
+ appName: z.string().describe("The internal app name")
378
+ }),
379
+ execute: async (args) => {
380
+ await getDokployClient().post("application.reload", {
381
+ applicationId: args.applicationId,
382
+ appName: args.appName
383
+ });
384
+ return `Application ${args.applicationId} reloaded.`;
385
+ }
386
+ });
387
+ server.addTool({
388
+ name: "dokploy_application_markRunning",
389
+ description: "Manually mark an application as running",
390
+ parameters: z.object({ applicationId: z.string().describe("The application ID") }),
391
+ execute: async (args) => {
392
+ await getDokployClient().post("application.markRunning", { applicationId: args.applicationId });
393
+ return `Application ${args.applicationId} marked as running.`;
394
+ }
395
+ });
396
+ server.addTool({
397
+ name: "dokploy_application_refreshToken",
398
+ description: "Refresh the webhook token for an application",
399
+ parameters: z.object({ applicationId: z.string().describe("The application ID") }),
400
+ execute: async (args) => {
401
+ await getDokployClient().post("application.refreshToken", { applicationId: args.applicationId });
402
+ return `Webhook token refreshed for application ${args.applicationId}.`;
403
+ }
404
+ });
405
+ server.addTool({
406
+ name: "dokploy_application_cleanQueues",
407
+ description: "Clean the build/deploy queues for an application",
408
+ parameters: z.object({ applicationId: z.string().describe("The application ID") }),
409
+ execute: async (args) => {
410
+ await getDokployClient().post("application.cleanQueues", { applicationId: args.applicationId });
411
+ return `Queues cleaned for application ${args.applicationId}.`;
412
+ }
413
+ });
414
+ server.addTool({
415
+ name: "dokploy_application_killBuild",
416
+ description: "Kill a running build process for an application",
417
+ parameters: z.object({ applicationId: z.string().describe("The application ID") }),
418
+ execute: async (args) => {
419
+ await getDokployClient().post("application.killBuild", { applicationId: args.applicationId });
420
+ return `Build killed for application ${args.applicationId}.`;
421
+ }
422
+ });
423
+ server.addTool({
424
+ name: "dokploy_application_move",
425
+ description: "Move an application to a different environment",
426
+ parameters: z.object({
427
+ applicationId: z.string().describe("The application ID"),
428
+ targetEnvironmentId: z.string().describe("The target environment ID")
429
+ }),
430
+ execute: async (args) => {
431
+ await getDokployClient().post("application.move", {
432
+ applicationId: args.applicationId,
433
+ targetEnvironmentId: args.targetEnvironmentId
434
+ });
435
+ return `Application ${args.applicationId} moved to environment ${args.targetEnvironmentId}.`;
436
+ }
437
+ });
438
+ server.addTool({
439
+ name: "dokploy_application_cancelDeployment",
440
+ description: "Cancel an ongoing deployment for an application",
441
+ parameters: z.object({ applicationId: z.string().describe("The application ID") }),
442
+ execute: async (args) => {
443
+ await getDokployClient().post("application.cancelDeployment", { applicationId: args.applicationId });
444
+ return `Deployment cancelled for application ${args.applicationId}.`;
445
+ }
446
+ });
447
+ }
448
+
449
+ //#endregion
450
+ //#region src/tools/backup-tools.ts
451
+ function registerBackupTools(server) {
452
+ server.addTool({
453
+ name: "dokploy_backup_create",
454
+ description: "Create a scheduled backup for a database or compose service",
455
+ parameters: z.object({
456
+ schedule: z.string().describe("Cron schedule expression (e.g., '0 2 * * *' for daily at 2AM)"),
457
+ prefix: z.string().describe("Backup file prefix"),
458
+ destinationId: z.string().describe("Backup destination ID"),
459
+ database: z.string().describe("Database name to backup"),
460
+ databaseType: z.string().describe("Database type (postgres, mysql, mariadb, mongo)"),
461
+ enabled: z.boolean().optional().describe("Whether the backup is enabled"),
462
+ keepLatestCount: z.number().optional().describe("Number of backups to keep"),
463
+ postgresId: z.string().optional().describe("Postgres database ID"),
464
+ mysqlId: z.string().optional().describe("MySQL database ID"),
465
+ mariadbId: z.string().optional().describe("MariaDB database ID"),
466
+ mongoId: z.string().optional().describe("MongoDB database ID"),
467
+ composeId: z.string().optional().describe("Compose service ID (for compose backups)"),
468
+ serviceName: z.string().optional().describe("Service name within compose")
469
+ }),
470
+ execute: async (args) => {
471
+ const client = getDokployClient();
472
+ const body = {};
473
+ for (const [key, value] of Object.entries(args)) if (value !== void 0) body[key] = value;
474
+ return `# Backup Created\n\n${formatBackup(await client.post("backup.create", body))}`;
475
+ }
476
+ });
477
+ server.addTool({
478
+ name: "dokploy_backup_get",
479
+ description: "Get details for a backup configuration",
480
+ parameters: z.object({ backupId: z.string().describe("The backup ID") }),
481
+ execute: async (args) => {
482
+ return `# Backup Details\n\n${formatBackup(await getDokployClient().get("backup.one", { backupId: args.backupId }))}`;
483
+ }
484
+ });
485
+ server.addTool({
486
+ name: "dokploy_backup_update",
487
+ description: "Update a backup configuration",
488
+ parameters: z.object({
489
+ backupId: z.string().describe("The backup ID"),
490
+ schedule: z.string().describe("Cron schedule"),
491
+ prefix: z.string().describe("Backup file prefix"),
492
+ destinationId: z.string().describe("Destination ID"),
493
+ database: z.string().describe("Database name"),
494
+ serviceName: z.string().describe("Service name"),
495
+ databaseType: z.string().describe("Database type"),
496
+ enabled: z.boolean().optional().describe("Enable/disable"),
497
+ keepLatestCount: z.number().optional().describe("Number of backups to keep")
498
+ }),
499
+ execute: async (args) => {
500
+ const client = getDokployClient();
501
+ const body = {};
502
+ for (const [key, value] of Object.entries(args)) if (value !== void 0) body[key] = value;
503
+ await client.post("backup.update", body);
504
+ return `Backup ${args.backupId} updated.`;
505
+ }
506
+ });
507
+ server.addTool({
508
+ name: "dokploy_backup_remove",
509
+ description: "Remove a backup configuration",
510
+ parameters: z.object({ backupId: z.string().describe("The backup ID to remove") }),
511
+ execute: async (args) => {
512
+ await getDokployClient().post("backup.remove", { backupId: args.backupId });
513
+ return `Backup ${args.backupId} removed.`;
514
+ }
515
+ });
516
+ server.addTool({
517
+ name: "dokploy_backup_listFiles",
518
+ description: "List available backup files for a destination",
519
+ parameters: z.object({
520
+ destinationId: z.string().describe("The backup destination ID"),
521
+ search: z.string().optional().describe("Search filter"),
522
+ serverId: z.string().optional().describe("Server ID")
523
+ }),
524
+ execute: async (args) => {
525
+ const files = await getDokployClient().get("backup.listBackupFiles", {
526
+ destinationId: args.destinationId,
527
+ ...args.search && { search: args.search },
528
+ ...args.serverId && { serverId: args.serverId }
529
+ });
530
+ return `# Backup Files\n\n\`\`\`json\n${JSON.stringify(files, null, 2)}\n\`\`\``;
531
+ }
532
+ });
533
+ server.addTool({
534
+ name: "dokploy_backup_manualBackup",
535
+ description: "Trigger a manual backup immediately. Works for postgres, mysql, mariadb, mongo, and compose services.",
536
+ parameters: z.object({
537
+ backupId: z.string().describe("The backup configuration ID to trigger"),
538
+ backupType: z.enum([
539
+ "postgres",
540
+ "mysql",
541
+ "mariadb",
542
+ "mongo",
543
+ "compose"
544
+ ]).describe("Type of backup to trigger")
545
+ }),
546
+ execute: async (args) => {
547
+ const client = getDokployClient();
548
+ const endpoint = {
549
+ postgres: "backup.manualBackupPostgres",
550
+ mysql: "backup.manualBackupMySql",
551
+ mariadb: "backup.manualBackupMariadb",
552
+ mongo: "backup.manualBackupMongo",
553
+ compose: "backup.manualBackupCompose"
554
+ }[args.backupType];
555
+ await client.post(endpoint, { backupId: args.backupId });
556
+ return `Manual ${args.backupType} backup triggered for backup config ${args.backupId}.`;
557
+ }
558
+ });
559
+ }
560
+
561
+ //#endregion
562
+ //#region src/tools/compose-tools.ts
563
+ function registerComposeTools(server) {
564
+ server.addTool({
565
+ name: "dokploy_compose_create",
566
+ description: "Create a new Docker Compose service in an environment",
567
+ parameters: z.object({
568
+ name: z.string().describe("Compose service name"),
569
+ environmentId: z.string().describe("Environment ID"),
570
+ description: z.string().optional().describe("Description"),
571
+ composeType: z.string().optional().describe("Compose type (docker-compose, stack)"),
572
+ composeFile: z.string().optional().describe("Docker Compose file content"),
573
+ serverId: z.string().optional().describe("Server ID for remote deployment")
574
+ }),
575
+ execute: async (args) => {
576
+ return `# Compose Service Created\n\n${formatCompose(await getDokployClient().post("compose.create", {
577
+ name: args.name,
578
+ environmentId: args.environmentId,
579
+ ...args.description && { description: args.description },
580
+ ...args.composeType && { composeType: args.composeType },
581
+ ...args.composeFile && { composeFile: args.composeFile },
582
+ ...args.serverId && { serverId: args.serverId }
583
+ }))}`;
584
+ }
585
+ });
586
+ server.addTool({
587
+ name: "dokploy_compose_get",
588
+ description: "Get details for a Docker Compose service",
589
+ parameters: z.object({ composeId: z.string().describe("The compose service ID") }),
590
+ execute: async (args) => {
591
+ return `# Compose Details\n\n${formatCompose(await getDokployClient().get("compose.one", { composeId: args.composeId }))}`;
592
+ }
593
+ });
594
+ server.addTool({
595
+ name: "dokploy_compose_update",
596
+ description: "Update a Docker Compose service configuration",
597
+ parameters: z.object({
598
+ composeId: z.string().describe("The compose service ID"),
599
+ name: z.string().optional().describe("New name"),
600
+ description: z.string().optional().describe("New description"),
601
+ composeFile: z.string().optional().describe("Updated Docker Compose file content"),
602
+ env: z.string().optional().describe("Environment variables"),
603
+ command: z.string().optional().describe("Custom command")
604
+ }),
605
+ execute: async (args) => {
606
+ const client = getDokployClient();
607
+ const { composeId, ...updates } = args;
608
+ const body = { composeId };
609
+ for (const [key, value] of Object.entries(updates)) if (value !== void 0) body[key] = value;
610
+ await client.post("compose.update", body);
611
+ return `Compose service ${composeId} updated.`;
612
+ }
613
+ });
614
+ server.addTool({
615
+ name: "dokploy_compose_delete",
616
+ description: "Delete a Docker Compose service",
617
+ parameters: z.object({
618
+ composeId: z.string().describe("The compose service ID"),
619
+ deleteVolumes: z.boolean().describe("Whether to also delete associated volumes")
620
+ }),
621
+ execute: async (args) => {
622
+ await getDokployClient().post("compose.delete", {
623
+ composeId: args.composeId,
624
+ deleteVolumes: args.deleteVolumes
625
+ });
626
+ return `Compose service ${args.composeId} deleted.`;
627
+ }
628
+ });
629
+ server.addTool({
630
+ name: "dokploy_compose_deploy",
631
+ description: "Deploy a Docker Compose service",
632
+ parameters: z.object({
633
+ composeId: z.string().describe("The compose service ID"),
634
+ title: z.string().optional().describe("Deployment title"),
635
+ description: z.string().optional().describe("Deployment description")
636
+ }),
637
+ execute: async (args) => {
638
+ await getDokployClient().post("compose.deploy", {
639
+ composeId: args.composeId,
640
+ ...args.title && { title: args.title },
641
+ ...args.description && { description: args.description }
642
+ });
643
+ return `Deployment triggered for compose service ${args.composeId}.`;
644
+ }
645
+ });
646
+ server.addTool({
647
+ name: "dokploy_compose_redeploy",
648
+ description: "Redeploy a Docker Compose service",
649
+ parameters: z.object({
650
+ composeId: z.string().describe("The compose service ID"),
651
+ title: z.string().optional().describe("Deployment title"),
652
+ description: z.string().optional().describe("Deployment description")
653
+ }),
654
+ execute: async (args) => {
655
+ await getDokployClient().post("compose.redeploy", {
656
+ composeId: args.composeId,
657
+ ...args.title && { title: args.title },
658
+ ...args.description && { description: args.description }
659
+ });
660
+ return `Redeployment triggered for compose service ${args.composeId}.`;
661
+ }
662
+ });
663
+ server.addTool({
664
+ name: "dokploy_compose_start",
665
+ description: "Start a stopped Docker Compose service",
666
+ parameters: z.object({ composeId: z.string().describe("The compose service ID") }),
667
+ execute: async (args) => {
668
+ await getDokployClient().post("compose.start", { composeId: args.composeId });
669
+ return `Compose service ${args.composeId} started.`;
670
+ }
671
+ });
672
+ server.addTool({
673
+ name: "dokploy_compose_stop",
674
+ description: "Stop a running Docker Compose service",
675
+ parameters: z.object({ composeId: z.string().describe("The compose service ID") }),
676
+ execute: async (args) => {
677
+ await getDokployClient().post("compose.stop", { composeId: args.composeId });
678
+ return `Compose service ${args.composeId} stopped.`;
679
+ }
680
+ });
681
+ server.addTool({
682
+ name: "dokploy_compose_loadServices",
683
+ description: "Load the list of services defined in a Docker Compose file",
684
+ parameters: z.object({
685
+ composeId: z.string().describe("The compose service ID"),
686
+ type: z.string().optional().describe("Service type filter")
687
+ }),
688
+ execute: async (args) => {
689
+ const services = await getDokployClient().get("compose.loadServices", {
690
+ composeId: args.composeId,
691
+ ...args.type && { type: args.type }
692
+ });
693
+ return `# Compose Services\n\n\`\`\`json\n${JSON.stringify(services, null, 2)}\n\`\`\``;
694
+ }
695
+ });
696
+ server.addTool({
697
+ name: "dokploy_compose_loadMounts",
698
+ description: "Load mounts for a specific service in a Docker Compose setup",
699
+ parameters: z.object({
700
+ composeId: z.string().describe("The compose service ID"),
701
+ serviceName: z.string().describe("The service name within the compose")
702
+ }),
703
+ execute: async (args) => {
704
+ const mounts = await getDokployClient().get("compose.loadMountsByService", {
705
+ composeId: args.composeId,
706
+ serviceName: args.serviceName
707
+ });
708
+ return `# Mounts for ${args.serviceName}\n\n\`\`\`json\n${JSON.stringify(mounts, null, 2)}\n\`\`\``;
709
+ }
710
+ });
711
+ server.addTool({
712
+ name: "dokploy_compose_getDefaultCommand",
713
+ description: "Get the default docker compose command for a service",
714
+ parameters: z.object({ composeId: z.string().describe("The compose service ID") }),
715
+ execute: async (args) => {
716
+ return `Default command: ${await getDokployClient().get("compose.getDefaultCommand", { composeId: args.composeId })}`;
717
+ }
718
+ });
719
+ server.addTool({
720
+ name: "dokploy_compose_move",
721
+ description: "Move a Docker Compose service to a different environment",
722
+ parameters: z.object({
723
+ composeId: z.string().describe("The compose service ID"),
724
+ targetEnvironmentId: z.string().describe("The target environment ID")
725
+ }),
726
+ execute: async (args) => {
727
+ await getDokployClient().post("compose.move", {
728
+ composeId: args.composeId,
729
+ targetEnvironmentId: args.targetEnvironmentId
730
+ });
731
+ return `Compose service ${args.composeId} moved to environment ${args.targetEnvironmentId}.`;
732
+ }
733
+ });
734
+ }
735
+
736
+ //#endregion
737
+ //#region src/types.ts
738
+ const DB_TYPES = [
739
+ "postgres",
740
+ "mysql",
741
+ "mariadb",
742
+ "mongo",
743
+ "redis"
744
+ ];
745
+ const DB_ID_FIELDS = {
746
+ postgres: "postgresId",
747
+ mysql: "mysqlId",
748
+ mariadb: "mariadbId",
749
+ mongo: "mongoId",
750
+ redis: "redisId"
751
+ };
752
+
753
+ //#endregion
754
+ //#region src/tools/database-tools.ts
755
+ const dbTypeSchema = z.enum(DB_TYPES).describe("Database type (postgres, mysql, mariadb, mongo, redis)");
756
+ function dbIdField(dbType) {
757
+ return DB_ID_FIELDS[dbType];
758
+ }
759
+ function dbBody(dbType, databaseId) {
760
+ return { [dbIdField(dbType)]: databaseId };
761
+ }
762
+ function registerDatabaseTools(server) {
763
+ server.addTool({
764
+ name: "dokploy_database_create",
765
+ description: "Create a new database service (supports postgres, mysql, mariadb, mongo, redis). Required fields vary by type: all need name + environmentId, relational DBs need databaseName/User/Password, redis needs databasePassword, mongo needs databaseUser/Password.",
766
+ parameters: z.object({
767
+ dbType: dbTypeSchema,
768
+ name: z.string().describe("Database service name"),
769
+ environmentId: z.string().describe("Environment ID"),
770
+ databaseName: z.string().optional().describe("Database name (required for postgres, mysql, mariadb)"),
771
+ databaseUser: z.string().optional().describe("Database user (required for postgres, mysql, mariadb, mongo)"),
772
+ databasePassword: z.string().optional().describe("Database password (required for all types)"),
773
+ databaseRootPassword: z.string().optional().describe("Root password (optional, mysql/mariadb only)"),
774
+ dockerImage: z.string().optional().describe("Custom Docker image"),
775
+ description: z.string().optional().describe("Description"),
776
+ serverId: z.string().optional().describe("Server ID for remote deployment")
777
+ }),
778
+ execute: async (args) => {
779
+ const client = getDokployClient();
780
+ const { dbType, ...rest } = args;
781
+ const body = {};
782
+ for (const [key, value] of Object.entries(rest)) if (value !== void 0) body[key] = value;
783
+ return `# Database Created\n\n${formatDatabase(await client.post(`${dbType}.create`, body), dbType)}`;
784
+ }
785
+ });
786
+ server.addTool({
787
+ name: "dokploy_database_get",
788
+ description: "Get details for a database service",
789
+ parameters: z.object({
790
+ dbType: dbTypeSchema,
791
+ databaseId: z.string().describe("The database ID")
792
+ }),
793
+ execute: async (args) => {
794
+ return `# Database Details\n\n${formatDatabase(await getDokployClient().get(`${args.dbType}.one`, { [dbIdField(args.dbType)]: args.databaseId }), args.dbType)}`;
795
+ }
796
+ });
797
+ server.addTool({
798
+ name: "dokploy_database_deploy",
799
+ description: "Deploy a database service",
800
+ parameters: z.object({
801
+ dbType: dbTypeSchema,
802
+ databaseId: z.string().describe("The database ID")
803
+ }),
804
+ execute: async (args) => {
805
+ await getDokployClient().post(`${args.dbType}.deploy`, dbBody(args.dbType, args.databaseId));
806
+ return `Database ${args.databaseId} (${args.dbType}) deployment triggered.`;
807
+ }
808
+ });
809
+ server.addTool({
810
+ name: "dokploy_database_start",
811
+ description: "Start a stopped database service",
812
+ parameters: z.object({
813
+ dbType: dbTypeSchema,
814
+ databaseId: z.string().describe("The database ID")
815
+ }),
816
+ execute: async (args) => {
817
+ await getDokployClient().post(`${args.dbType}.start`, dbBody(args.dbType, args.databaseId));
818
+ return `Database ${args.databaseId} (${args.dbType}) started.`;
819
+ }
820
+ });
821
+ server.addTool({
822
+ name: "dokploy_database_stop",
823
+ description: "Stop a running database service",
824
+ parameters: z.object({
825
+ dbType: dbTypeSchema,
826
+ databaseId: z.string().describe("The database ID")
827
+ }),
828
+ execute: async (args) => {
829
+ await getDokployClient().post(`${args.dbType}.stop`, dbBody(args.dbType, args.databaseId));
830
+ return `Database ${args.databaseId} (${args.dbType}) stopped.`;
831
+ }
832
+ });
833
+ server.addTool({
834
+ name: "dokploy_database_remove",
835
+ description: "Remove a database service",
836
+ parameters: z.object({
837
+ dbType: dbTypeSchema,
838
+ databaseId: z.string().describe("The database ID")
839
+ }),
840
+ execute: async (args) => {
841
+ await getDokployClient().post(`${args.dbType}.remove`, dbBody(args.dbType, args.databaseId));
842
+ return `Database ${args.databaseId} (${args.dbType}) removed.`;
843
+ }
844
+ });
845
+ server.addTool({
846
+ name: "dokploy_database_reload",
847
+ description: "Reload a database service",
848
+ parameters: z.object({
849
+ dbType: dbTypeSchema,
850
+ databaseId: z.string().describe("The database ID"),
851
+ appName: z.string().describe("The internal app name")
852
+ }),
853
+ execute: async (args) => {
854
+ await getDokployClient().post(`${args.dbType}.reload`, {
855
+ ...dbBody(args.dbType, args.databaseId),
856
+ appName: args.appName
857
+ });
858
+ return `Database ${args.databaseId} (${args.dbType}) reloaded.`;
859
+ }
860
+ });
861
+ server.addTool({
862
+ name: "dokploy_database_update",
863
+ description: "Update database service configuration (name, image, resources, etc.)",
864
+ parameters: z.object({
865
+ dbType: dbTypeSchema,
866
+ databaseId: z.string().describe("The database ID"),
867
+ name: z.string().optional().describe("New name"),
868
+ description: z.string().optional().describe("New description"),
869
+ dockerImage: z.string().optional().describe("Docker image"),
870
+ command: z.string().optional().describe("Custom command"),
871
+ memoryLimit: z.number().optional().describe("Memory limit in MB"),
872
+ cpuLimit: z.number().optional().describe("CPU limit")
873
+ }),
874
+ execute: async (args) => {
875
+ const client = getDokployClient();
876
+ const { dbType, databaseId, ...updates } = args;
877
+ const body = { [dbIdField(dbType)]: databaseId };
878
+ for (const [key, value] of Object.entries(updates)) if (value !== void 0) body[key] = value;
879
+ await client.post(`${dbType}.update`, body);
880
+ return `Database ${databaseId} (${dbType}) updated.`;
881
+ }
882
+ });
883
+ server.addTool({
884
+ name: "dokploy_database_rebuild",
885
+ description: "Rebuild a database service container",
886
+ parameters: z.object({
887
+ dbType: dbTypeSchema,
888
+ databaseId: z.string().describe("The database ID")
889
+ }),
890
+ execute: async (args) => {
891
+ await getDokployClient().post(`${args.dbType}.rebuild`, dbBody(args.dbType, args.databaseId));
892
+ return `Database ${args.databaseId} (${args.dbType}) rebuild triggered.`;
893
+ }
894
+ });
895
+ server.addTool({
896
+ name: "dokploy_database_move",
897
+ description: "Move a database service to a different environment",
898
+ parameters: z.object({
899
+ dbType: dbTypeSchema,
900
+ databaseId: z.string().describe("The database ID"),
901
+ targetEnvironmentId: z.string().describe("Target environment ID")
902
+ }),
903
+ execute: async (args) => {
904
+ await getDokployClient().post(`${args.dbType}.move`, {
905
+ ...dbBody(args.dbType, args.databaseId),
906
+ targetEnvironmentId: args.targetEnvironmentId
907
+ });
908
+ return `Database ${args.databaseId} (${args.dbType}) moved to environment ${args.targetEnvironmentId}.`;
909
+ }
910
+ });
911
+ server.addTool({
912
+ name: "dokploy_database_changeStatus",
913
+ description: "Change the application status of a database service",
914
+ parameters: z.object({
915
+ dbType: dbTypeSchema,
916
+ databaseId: z.string().describe("The database ID"),
917
+ applicationStatus: z.string().describe("New status (idle, running, done, error)")
918
+ }),
919
+ execute: async (args) => {
920
+ await getDokployClient().post(`${args.dbType}.changeStatus`, {
921
+ ...dbBody(args.dbType, args.databaseId),
922
+ applicationStatus: args.applicationStatus
923
+ });
924
+ return `Database ${args.databaseId} (${args.dbType}) status changed to ${args.applicationStatus}.`;
925
+ }
926
+ });
927
+ server.addTool({
928
+ name: "dokploy_database_saveEnvironment",
929
+ description: "Save environment variables for a database service",
930
+ parameters: z.object({
931
+ dbType: dbTypeSchema,
932
+ databaseId: z.string().describe("The database ID"),
933
+ env: z.string().optional().describe("Environment variables (KEY=VALUE, newline separated)")
934
+ }),
935
+ execute: async (args) => {
936
+ await getDokployClient().post(`${args.dbType}.saveEnvironment`, {
937
+ ...dbBody(args.dbType, args.databaseId),
938
+ ...args.env !== void 0 && { env: args.env }
939
+ });
940
+ return `Environment saved for database ${args.databaseId} (${args.dbType}).`;
941
+ }
942
+ });
943
+ server.addTool({
944
+ name: "dokploy_database_saveExternalPort",
945
+ description: "Set or update the external port for a database service",
946
+ parameters: z.object({
947
+ dbType: dbTypeSchema,
948
+ databaseId: z.string().describe("The database ID"),
949
+ externalPort: z.number().describe("External port number")
950
+ }),
951
+ execute: async (args) => {
952
+ await getDokployClient().post(`${args.dbType}.saveExternalPort`, {
953
+ ...dbBody(args.dbType, args.databaseId),
954
+ externalPort: args.externalPort
955
+ });
956
+ return `External port set to ${args.externalPort} for database ${args.databaseId} (${args.dbType}).`;
957
+ }
958
+ });
959
+ }
960
+
961
+ //#endregion
962
+ //#region src/tools/deployment-tools.ts
963
+ function registerDeploymentTools(server) {
964
+ server.addTool({
965
+ name: "dokploy_deployment_list",
966
+ description: "List all deployments for an application",
967
+ parameters: z.object({ applicationId: z.string().describe("The application ID") }),
968
+ execute: async (args) => {
969
+ return formatDeploymentList(await getDokployClient().get("deployment.all", { applicationId: args.applicationId }));
970
+ }
971
+ });
972
+ server.addTool({
973
+ name: "dokploy_deployment_listByCompose",
974
+ description: "List all deployments for a Docker Compose service",
975
+ parameters: z.object({ composeId: z.string().describe("The compose service ID") }),
976
+ execute: async (args) => {
977
+ return formatDeploymentList(await getDokployClient().get("deployment.allByCompose", { composeId: args.composeId }));
978
+ }
979
+ });
980
+ server.addTool({
981
+ name: "dokploy_deployment_listByServer",
982
+ description: "List all deployments for a specific server",
983
+ parameters: z.object({ serverId: z.string().describe("The server ID") }),
984
+ execute: async (args) => {
985
+ return formatDeploymentList(await getDokployClient().get("deployment.allByServer", { serverId: args.serverId }));
986
+ }
987
+ });
988
+ server.addTool({
989
+ name: "dokploy_deployment_listByType",
990
+ description: "List all deployments by resource type and ID",
991
+ parameters: z.object({
992
+ id: z.string().describe("The resource ID"),
993
+ type: z.string().describe("The resource type (application, compose, postgres, mysql, mariadb, mongo, redis)")
994
+ }),
995
+ execute: async (args) => {
996
+ return formatDeploymentList(await getDokployClient().get("deployment.allByType", {
997
+ id: args.id,
998
+ type: args.type
999
+ }));
1000
+ }
1001
+ });
1002
+ server.addTool({
1003
+ name: "dokploy_deployment_killProcess",
1004
+ description: "Kill a running deployment process",
1005
+ parameters: z.object({ deploymentId: z.string().describe("The deployment ID to kill") }),
1006
+ execute: async (args) => {
1007
+ await getDokployClient().post("deployment.killProcess", { deploymentId: args.deploymentId });
1008
+ return `Deployment process ${args.deploymentId} killed.`;
1009
+ }
1010
+ });
1011
+ }
1012
+
1013
+ //#endregion
1014
+ //#region src/tools/docker-tools.ts
1015
+ function registerDockerTools(server) {
1016
+ server.addTool({
1017
+ name: "dokploy_docker_getContainers",
1018
+ description: "List all Docker containers, optionally filtered by server",
1019
+ parameters: z.object({ serverId: z.string().optional().describe("Server ID to filter containers (optional)") }),
1020
+ execute: async (args) => {
1021
+ return formatContainerList(await getDokployClient().get("docker.getContainers", { ...args.serverId && { serverId: args.serverId } }));
1022
+ }
1023
+ });
1024
+ server.addTool({
1025
+ name: "dokploy_docker_restartContainer",
1026
+ description: "Restart a specific Docker container",
1027
+ parameters: z.object({ containerId: z.string().describe("The container ID to restart") }),
1028
+ execute: async (args) => {
1029
+ await getDokployClient().post("docker.restartContainer", { containerId: args.containerId });
1030
+ return `Container ${args.containerId} restarted.`;
1031
+ }
1032
+ });
1033
+ server.addTool({
1034
+ name: "dokploy_docker_getConfig",
1035
+ description: "Get the Docker configuration/inspect data for a container",
1036
+ parameters: z.object({
1037
+ containerId: z.string().describe("The container ID"),
1038
+ serverId: z.string().optional().describe("Server ID if on a remote server")
1039
+ }),
1040
+ execute: async (args) => {
1041
+ const config = await getDokployClient().get("docker.getConfig", {
1042
+ containerId: args.containerId,
1043
+ ...args.serverId && { serverId: args.serverId }
1044
+ });
1045
+ return `# Container Config\n\n\`\`\`json\n${JSON.stringify(config, null, 2)}\n\`\`\``;
1046
+ }
1047
+ });
1048
+ server.addTool({
1049
+ name: "dokploy_docker_getByAppNameMatch",
1050
+ description: "Get containers matching an application name pattern",
1051
+ parameters: z.object({
1052
+ appName: z.string().describe("Application name to match"),
1053
+ appType: z.string().optional().describe("Application type filter"),
1054
+ serverId: z.string().optional().describe("Server ID")
1055
+ }),
1056
+ execute: async (args) => {
1057
+ return formatContainerList(await getDokployClient().get("docker.getContainersByAppNameMatch", {
1058
+ appName: args.appName,
1059
+ ...args.appType && { appType: args.appType },
1060
+ ...args.serverId && { serverId: args.serverId }
1061
+ }));
1062
+ }
1063
+ });
1064
+ server.addTool({
1065
+ name: "dokploy_docker_getByAppLabel",
1066
+ description: "Get containers by application label",
1067
+ parameters: z.object({
1068
+ appName: z.string().describe("Application name label"),
1069
+ type: z.string().describe("Label type"),
1070
+ serverId: z.string().optional().describe("Server ID")
1071
+ }),
1072
+ execute: async (args) => {
1073
+ return formatContainerList(await getDokployClient().get("docker.getContainersByAppLabel", {
1074
+ appName: args.appName,
1075
+ type: args.type,
1076
+ ...args.serverId && { serverId: args.serverId }
1077
+ }));
1078
+ }
1079
+ });
1080
+ server.addTool({
1081
+ name: "dokploy_docker_getStackContainers",
1082
+ description: "Get containers for a Docker stack by application name",
1083
+ parameters: z.object({
1084
+ appName: z.string().describe("Application name"),
1085
+ serverId: z.string().optional().describe("Server ID")
1086
+ }),
1087
+ execute: async (args) => {
1088
+ return formatContainerList(await getDokployClient().get("docker.getStackContainersByAppName", {
1089
+ appName: args.appName,
1090
+ ...args.serverId && { serverId: args.serverId }
1091
+ }));
1092
+ }
1093
+ });
1094
+ server.addTool({
1095
+ name: "dokploy_docker_getServiceContainers",
1096
+ description: "Get containers for a specific Docker service by application name",
1097
+ parameters: z.object({
1098
+ appName: z.string().describe("Application name"),
1099
+ serverId: z.string().optional().describe("Server ID")
1100
+ }),
1101
+ execute: async (args) => {
1102
+ return formatContainerList(await getDokployClient().get("docker.getServiceContainersByAppName", {
1103
+ appName: args.appName,
1104
+ ...args.serverId && { serverId: args.serverId }
1105
+ }));
1106
+ }
1107
+ });
1108
+ }
1109
+
1110
+ //#endregion
1111
+ //#region src/tools/domain-tools.ts
1112
+ function registerDomainTools(server) {
1113
+ server.addTool({
1114
+ name: "dokploy_domain_create",
1115
+ description: "Create a domain for an application or compose service",
1116
+ parameters: z.object({
1117
+ host: z.string().describe("Domain hostname (e.g., app.example.com)"),
1118
+ applicationId: z.string().optional().describe("Application ID (for application domains)"),
1119
+ composeId: z.string().optional().describe("Compose service ID (for compose domains)"),
1120
+ serviceName: z.string().optional().describe("Service name within a compose service"),
1121
+ path: z.string().optional().describe("URL path prefix"),
1122
+ port: z.number().optional().describe("Target port"),
1123
+ https: z.boolean().optional().describe("Enable HTTPS"),
1124
+ certificateType: z.string().optional().describe("Certificate type (letsencrypt, none)"),
1125
+ domainType: z.string().optional().describe("Domain type")
1126
+ }),
1127
+ execute: async (args) => {
1128
+ const client = getDokployClient();
1129
+ const body = { host: args.host };
1130
+ for (const [key, value] of Object.entries(args)) if (key !== "host" && value !== void 0) body[key] = value;
1131
+ return `# Domain Created\n\n${formatDomain(await client.post("domain.create", body))}`;
1132
+ }
1133
+ });
1134
+ server.addTool({
1135
+ name: "dokploy_domain_listByApplication",
1136
+ description: "List all domains for an application",
1137
+ parameters: z.object({ applicationId: z.string().describe("The application ID") }),
1138
+ execute: async (args) => {
1139
+ return formatDomainList(await getDokployClient().get("domain.byApplicationId", { applicationId: args.applicationId }));
1140
+ }
1141
+ });
1142
+ server.addTool({
1143
+ name: "dokploy_domain_listByCompose",
1144
+ description: "List all domains for a Docker Compose service",
1145
+ parameters: z.object({ composeId: z.string().describe("The compose service ID") }),
1146
+ execute: async (args) => {
1147
+ return formatDomainList(await getDokployClient().get("domain.byComposeId", { composeId: args.composeId }));
1148
+ }
1149
+ });
1150
+ server.addTool({
1151
+ name: "dokploy_domain_get",
1152
+ description: "Get details for a specific domain",
1153
+ parameters: z.object({ domainId: z.string().describe("The domain ID") }),
1154
+ execute: async (args) => {
1155
+ return `# Domain Details\n\n${formatDomain(await getDokployClient().get("domain.one", { domainId: args.domainId }))}`;
1156
+ }
1157
+ });
1158
+ server.addTool({
1159
+ name: "dokploy_domain_update",
1160
+ description: "Update a domain's configuration",
1161
+ parameters: z.object({
1162
+ domainId: z.string().describe("The domain ID"),
1163
+ host: z.string().describe("Domain hostname"),
1164
+ path: z.string().optional().describe("URL path prefix"),
1165
+ port: z.number().optional().describe("Target port"),
1166
+ https: z.boolean().optional().describe("Enable HTTPS"),
1167
+ certificateType: z.string().optional().describe("Certificate type")
1168
+ }),
1169
+ execute: async (args) => {
1170
+ const client = getDokployClient();
1171
+ const body = {
1172
+ domainId: args.domainId,
1173
+ host: args.host
1174
+ };
1175
+ for (const [key, value] of Object.entries(args)) if (key !== "domainId" && key !== "host" && value !== void 0) body[key] = value;
1176
+ await client.post("domain.update", body);
1177
+ return `Domain ${args.domainId} updated.`;
1178
+ }
1179
+ });
1180
+ server.addTool({
1181
+ name: "dokploy_domain_delete",
1182
+ description: "Delete a domain",
1183
+ parameters: z.object({ domainId: z.string().describe("The domain ID to delete") }),
1184
+ execute: async (args) => {
1185
+ await getDokployClient().post("domain.delete", { domainId: args.domainId });
1186
+ return `Domain ${args.domainId} deleted.`;
1187
+ }
1188
+ });
1189
+ server.addTool({
1190
+ name: "dokploy_domain_generateDomain",
1191
+ description: "Auto-generate a domain for an application (e.g., using traefik.me)",
1192
+ parameters: z.object({
1193
+ appName: z.string().describe("The internal application name"),
1194
+ serverId: z.string().optional().describe("Server ID")
1195
+ }),
1196
+ execute: async (args) => {
1197
+ const result = await getDokployClient().post("domain.generateDomain", {
1198
+ appName: args.appName,
1199
+ ...args.serverId && { serverId: args.serverId }
1200
+ });
1201
+ return `# Generated Domain\n\n\`\`\`json\n${JSON.stringify(result, null, 2)}\n\`\`\``;
1202
+ }
1203
+ });
1204
+ server.addTool({
1205
+ name: "dokploy_domain_canGenerateTraefikMe",
1206
+ description: "Check if traefik.me domains can be generated for a server",
1207
+ parameters: z.object({ serverId: z.string().optional().describe("Server ID to check") }),
1208
+ execute: async (args) => {
1209
+ return `Traefik.me domain generation: ${await getDokployClient().get("domain.canGenerateTraefikMeDomains", { ...args.serverId && { serverId: args.serverId } }) ? "Available" : "Not available"}`;
1210
+ }
1211
+ });
1212
+ server.addTool({
1213
+ name: "dokploy_domain_validate",
1214
+ description: "Validate that a domain's DNS is properly configured",
1215
+ parameters: z.object({
1216
+ domain: z.string().describe("The domain to validate"),
1217
+ serverIp: z.string().optional().describe("Expected server IP")
1218
+ }),
1219
+ execute: async (args) => {
1220
+ const result = await getDokployClient().post("domain.validateDomain", {
1221
+ domain: args.domain,
1222
+ ...args.serverIp && { serverIp: args.serverIp }
1223
+ });
1224
+ return `# Domain Validation: ${args.domain}\n\n\`\`\`json\n${JSON.stringify(result, null, 2)}\n\`\`\``;
1225
+ }
1226
+ });
1227
+ }
1228
+
1229
+ //#endregion
1230
+ //#region src/tools/environment-tools.ts
1231
+ function registerEnvironmentTools(server) {
1232
+ server.addTool({
1233
+ name: "dokploy_environment_create",
1234
+ description: "Create a new environment within a project",
1235
+ parameters: z.object({
1236
+ name: z.string().describe("Environment name"),
1237
+ projectId: z.string().describe("Project ID to create the environment in"),
1238
+ description: z.string().optional().describe("Environment description")
1239
+ }),
1240
+ execute: async (args) => {
1241
+ return `# Environment Created\n\n${formatEnvironment(await getDokployClient().post("environment.create", {
1242
+ name: args.name,
1243
+ projectId: args.projectId,
1244
+ ...args.description && { description: args.description }
1245
+ }))}`;
1246
+ }
1247
+ });
1248
+ server.addTool({
1249
+ name: "dokploy_environment_get",
1250
+ description: "Get details for a specific environment",
1251
+ parameters: z.object({ environmentId: z.string().describe("The environment ID") }),
1252
+ execute: async (args) => {
1253
+ return `# Environment Details\n\n${formatEnvironment(await getDokployClient().get("environment.one", { environmentId: args.environmentId }))}`;
1254
+ }
1255
+ });
1256
+ server.addTool({
1257
+ name: "dokploy_environment_listByProject",
1258
+ description: "List all environments for a project",
1259
+ parameters: z.object({ projectId: z.string().describe("The project ID") }),
1260
+ execute: async (args) => {
1261
+ return formatEnvironmentList(await getDokployClient().get("environment.byProjectId", { projectId: args.projectId }));
1262
+ }
1263
+ });
1264
+ server.addTool({
1265
+ name: "dokploy_environment_remove",
1266
+ description: "Remove an environment and all its services",
1267
+ parameters: z.object({ environmentId: z.string().describe("The environment ID to remove") }),
1268
+ execute: async (args) => {
1269
+ await getDokployClient().post("environment.remove", { environmentId: args.environmentId });
1270
+ return `Environment ${args.environmentId} removed.`;
1271
+ }
1272
+ });
1273
+ server.addTool({
1274
+ name: "dokploy_environment_update",
1275
+ description: "Update an environment's name or description",
1276
+ parameters: z.object({
1277
+ environmentId: z.string().describe("The environment ID"),
1278
+ name: z.string().optional().describe("New name"),
1279
+ description: z.string().optional().describe("New description")
1280
+ }),
1281
+ execute: async (args) => {
1282
+ await getDokployClient().post("environment.update", {
1283
+ environmentId: args.environmentId,
1284
+ ...args.name && { name: args.name },
1285
+ ...args.description !== void 0 && { description: args.description }
1286
+ });
1287
+ return `Environment ${args.environmentId} updated.`;
1288
+ }
1289
+ });
1290
+ server.addTool({
1291
+ name: "dokploy_environment_duplicate",
1292
+ description: "Duplicate an environment and its services",
1293
+ parameters: z.object({
1294
+ environmentId: z.string().describe("The source environment ID"),
1295
+ name: z.string().describe("Name for the duplicated environment"),
1296
+ description: z.string().optional().describe("Description for the duplicate")
1297
+ }),
1298
+ execute: async (args) => {
1299
+ await getDokployClient().post("environment.duplicate", {
1300
+ environmentId: args.environmentId,
1301
+ name: args.name,
1302
+ ...args.description && { description: args.description }
1303
+ });
1304
+ return `Environment duplicated as "${args.name}".`;
1305
+ }
1306
+ });
1307
+ }
1308
+
1309
+ //#endregion
1310
+ //#region src/tools/infrastructure-tools.ts
1311
+ function registerInfrastructureTools(server) {
1312
+ server.addTool({
1313
+ name: "dokploy_port_create",
1314
+ description: "Create a port mapping for an application",
1315
+ parameters: z.object({
1316
+ applicationId: z.string().describe("The application ID"),
1317
+ publishedPort: z.number().describe("Published (external) port"),
1318
+ targetPort: z.number().describe("Target (container) port"),
1319
+ protocol: z.string().optional().describe("Protocol (tcp, udp)"),
1320
+ publishMode: z.string().optional().describe("Publish mode")
1321
+ }),
1322
+ execute: async (args) => {
1323
+ const port = await getDokployClient().post("port.create", {
1324
+ applicationId: args.applicationId,
1325
+ publishedPort: args.publishedPort,
1326
+ targetPort: args.targetPort,
1327
+ ...args.protocol && { protocol: args.protocol },
1328
+ ...args.publishMode && { publishMode: args.publishMode }
1329
+ });
1330
+ return `Port mapping created: ${port.publishedPort} -> ${port.targetPort} (ID: ${port.portId})`;
1331
+ }
1332
+ });
1333
+ server.addTool({
1334
+ name: "dokploy_port_delete",
1335
+ description: "Delete a port mapping",
1336
+ parameters: z.object({ portId: z.string().describe("The port mapping ID to delete") }),
1337
+ execute: async (args) => {
1338
+ await getDokployClient().post("port.delete", { portId: args.portId });
1339
+ return `Port mapping ${args.portId} deleted.`;
1340
+ }
1341
+ });
1342
+ server.addTool({
1343
+ name: "dokploy_security_create",
1344
+ description: "Create basic auth credentials for an application",
1345
+ parameters: z.object({
1346
+ applicationId: z.string().describe("The application ID"),
1347
+ username: z.string().describe("Basic auth username"),
1348
+ password: z.string().describe("Basic auth password")
1349
+ }),
1350
+ execute: async (args) => {
1351
+ const security = await getDokployClient().post("security.create", {
1352
+ applicationId: args.applicationId,
1353
+ username: args.username,
1354
+ password: args.password
1355
+ });
1356
+ return `Basic auth created for application ${args.applicationId} (ID: ${security.securityId})`;
1357
+ }
1358
+ });
1359
+ server.addTool({
1360
+ name: "dokploy_security_delete",
1361
+ description: "Remove basic auth credentials",
1362
+ parameters: z.object({ securityId: z.string().describe("The security credentials ID") }),
1363
+ execute: async (args) => {
1364
+ await getDokployClient().post("security.delete", { securityId: args.securityId });
1365
+ return `Security credentials ${args.securityId} deleted.`;
1366
+ }
1367
+ });
1368
+ server.addTool({
1369
+ name: "dokploy_certificate_list",
1370
+ description: "List all SSL/TLS certificates",
1371
+ parameters: z.object({}),
1372
+ execute: async () => {
1373
+ const certs = await getDokployClient().get("certificates.all");
1374
+ if (certs.length === 0) return "No certificates found.";
1375
+ const lines = certs.map((c) => `- **${c.name}** (ID: ${c.certificateId}) | Auto-renew: ${c.autoRenew ?? "N/A"}`);
1376
+ return `# Certificates (${certs.length})\n\n${lines.join("\n")}`;
1377
+ }
1378
+ });
1379
+ server.addTool({
1380
+ name: "dokploy_certificate_get",
1381
+ description: "Get details for a specific certificate",
1382
+ parameters: z.object({ certificateId: z.string().describe("The certificate ID") }),
1383
+ execute: async (args) => {
1384
+ const cert = await getDokployClient().get("certificates.one", { certificateId: args.certificateId });
1385
+ return `# Certificate: ${cert.name}\n\n- ID: ${cert.certificateId}\n- Auto-renew: ${cert.autoRenew ?? "N/A"}`;
1386
+ }
1387
+ });
1388
+ server.addTool({
1389
+ name: "dokploy_certificate_create",
1390
+ description: "Upload a new SSL/TLS certificate",
1391
+ parameters: z.object({
1392
+ name: z.string().describe("Certificate name"),
1393
+ certificateData: z.string().describe("Certificate data (PEM format)"),
1394
+ privateKey: z.string().describe("Private key (PEM format)"),
1395
+ organizationId: z.string().describe("Organization ID"),
1396
+ autoRenew: z.boolean().optional().describe("Enable auto-renewal"),
1397
+ serverId: z.string().optional().describe("Server ID")
1398
+ }),
1399
+ execute: async (args) => {
1400
+ const client = getDokployClient();
1401
+ const body = {
1402
+ name: args.name,
1403
+ certificateData: args.certificateData,
1404
+ privateKey: args.privateKey,
1405
+ organizationId: args.organizationId
1406
+ };
1407
+ if (args.autoRenew !== void 0) body.autoRenew = args.autoRenew;
1408
+ if (args.serverId) body.serverId = args.serverId;
1409
+ const cert = await client.post("certificates.create", body);
1410
+ return `Certificate "${cert.name}" created (ID: ${cert.certificateId}).`;
1411
+ }
1412
+ });
1413
+ server.addTool({
1414
+ name: "dokploy_certificate_remove",
1415
+ description: "Remove an SSL/TLS certificate",
1416
+ parameters: z.object({ certificateId: z.string().describe("The certificate ID to remove") }),
1417
+ execute: async (args) => {
1418
+ await getDokployClient().post("certificates.remove", { certificateId: args.certificateId });
1419
+ return `Certificate ${args.certificateId} removed.`;
1420
+ }
1421
+ });
1422
+ }
1423
+
1424
+ //#endregion
1425
+ //#region src/tools/project-tools.ts
1426
+ function registerProjectTools(server) {
1427
+ server.addTool({
1428
+ name: "dokploy_project_list",
1429
+ description: "List all projects in Dokploy",
1430
+ parameters: z.object({}),
1431
+ execute: async () => {
1432
+ return formatProjectList(await getDokployClient().get("project.all"));
1433
+ }
1434
+ });
1435
+ server.addTool({
1436
+ name: "dokploy_project_get",
1437
+ description: "Get details for a specific project",
1438
+ parameters: z.object({ projectId: z.string().describe("The project ID") }),
1439
+ execute: async (args) => {
1440
+ return `# Project Details\n\n${formatProject(await getDokployClient().get("project.one", { projectId: args.projectId }))}`;
1441
+ }
1442
+ });
1443
+ server.addTool({
1444
+ name: "dokploy_project_create",
1445
+ description: "Create a new project",
1446
+ parameters: z.object({
1447
+ name: z.string().describe("Project name"),
1448
+ description: z.string().optional().describe("Project description")
1449
+ }),
1450
+ execute: async (args) => {
1451
+ return `# Project Created\n\n${formatProject(await getDokployClient().post("project.create", {
1452
+ name: args.name,
1453
+ ...args.description && { description: args.description }
1454
+ }))}`;
1455
+ }
1456
+ });
1457
+ server.addTool({
1458
+ name: "dokploy_project_update",
1459
+ description: "Update a project's name or description",
1460
+ parameters: z.object({
1461
+ projectId: z.string().describe("The project ID"),
1462
+ name: z.string().optional().describe("New project name"),
1463
+ description: z.string().optional().describe("New project description")
1464
+ }),
1465
+ execute: async (args) => {
1466
+ await getDokployClient().post("project.update", {
1467
+ projectId: args.projectId,
1468
+ ...args.name && { name: args.name },
1469
+ ...args.description !== void 0 && { description: args.description }
1470
+ });
1471
+ return `Project ${args.projectId} updated successfully.`;
1472
+ }
1473
+ });
1474
+ server.addTool({
1475
+ name: "dokploy_project_remove",
1476
+ description: "Delete a project and all its resources",
1477
+ parameters: z.object({ projectId: z.string().describe("The project ID to remove") }),
1478
+ execute: async (args) => {
1479
+ await getDokployClient().post("project.remove", { projectId: args.projectId });
1480
+ return `Project ${args.projectId} removed successfully.`;
1481
+ }
1482
+ });
1483
+ server.addTool({
1484
+ name: "dokploy_project_duplicate",
1485
+ description: "Duplicate an environment and its services into a new or existing project",
1486
+ parameters: z.object({
1487
+ sourceEnvironmentId: z.string().describe("The source environment ID to duplicate from"),
1488
+ name: z.string().describe("Name for the duplicated project/environment"),
1489
+ description: z.string().optional().describe("Description for the duplicate"),
1490
+ includeServices: z.boolean().optional().describe("Whether to include services"),
1491
+ duplicateInSameProject: z.boolean().optional().describe("Duplicate within the same project")
1492
+ }),
1493
+ execute: async (args) => {
1494
+ await getDokployClient().post("project.duplicate", {
1495
+ sourceEnvironmentId: args.sourceEnvironmentId,
1496
+ name: args.name,
1497
+ ...args.description && { description: args.description },
1498
+ ...args.includeServices !== void 0 && { includeServices: args.includeServices },
1499
+ ...args.duplicateInSameProject !== void 0 && { duplicateInSameProject: args.duplicateInSameProject }
1500
+ });
1501
+ return `Environment duplicated successfully as "${args.name}".`;
1502
+ }
1503
+ });
1504
+ }
1505
+
1506
+ //#endregion
1507
+ //#region src/tools/server-tools.ts
1508
+ function registerServerTools(server) {
1509
+ server.addTool({
1510
+ name: "dokploy_server_list",
1511
+ description: "List all remote servers configured in Dokploy",
1512
+ parameters: z.object({}),
1513
+ execute: async () => {
1514
+ return formatServerList(await getDokployClient().get("server.all"));
1515
+ }
1516
+ });
1517
+ server.addTool({
1518
+ name: "dokploy_server_get",
1519
+ description: "Get details for a specific server",
1520
+ parameters: z.object({ serverId: z.string().describe("The server ID") }),
1521
+ execute: async (args) => {
1522
+ return `# Server Details\n\n${formatServer(await getDokployClient().get("server.one", { serverId: args.serverId }))}`;
1523
+ }
1524
+ });
1525
+ server.addTool({
1526
+ name: "dokploy_server_create",
1527
+ description: "Add a new remote server to Dokploy",
1528
+ parameters: z.object({
1529
+ name: z.string().describe("Server name"),
1530
+ ipAddress: z.string().describe("Server IP address"),
1531
+ port: z.number().describe("SSH port"),
1532
+ username: z.string().describe("SSH username"),
1533
+ sshKeyId: z.string().describe("SSH key ID to use for connection"),
1534
+ serverType: z.string().describe("Server type (docker, swarm)"),
1535
+ description: z.string().optional().describe("Server description")
1536
+ }),
1537
+ execute: async (args) => {
1538
+ return `# Server Created\n\n${formatServer(await getDokployClient().post("server.create", {
1539
+ name: args.name,
1540
+ ipAddress: args.ipAddress,
1541
+ port: args.port,
1542
+ username: args.username,
1543
+ sshKeyId: args.sshKeyId,
1544
+ serverType: args.serverType,
1545
+ ...args.description && { description: args.description }
1546
+ }))}`;
1547
+ }
1548
+ });
1549
+ server.addTool({
1550
+ name: "dokploy_server_update",
1551
+ description: "Update a server's configuration",
1552
+ parameters: z.object({
1553
+ serverId: z.string().describe("The server ID"),
1554
+ name: z.string().describe("Server name"),
1555
+ ipAddress: z.string().describe("Server IP address"),
1556
+ port: z.number().describe("SSH port"),
1557
+ username: z.string().describe("SSH username"),
1558
+ sshKeyId: z.string().describe("SSH key ID"),
1559
+ serverType: z.string().describe("Server type"),
1560
+ description: z.string().optional().describe("Server description")
1561
+ }),
1562
+ execute: async (args) => {
1563
+ await getDokployClient().post("server.update", {
1564
+ serverId: args.serverId,
1565
+ name: args.name,
1566
+ ipAddress: args.ipAddress,
1567
+ port: args.port,
1568
+ username: args.username,
1569
+ sshKeyId: args.sshKeyId,
1570
+ serverType: args.serverType,
1571
+ ...args.description && { description: args.description }
1572
+ });
1573
+ return `Server ${args.serverId} updated.`;
1574
+ }
1575
+ });
1576
+ server.addTool({
1577
+ name: "dokploy_server_remove",
1578
+ description: "Remove a server from Dokploy",
1579
+ parameters: z.object({ serverId: z.string().describe("The server ID to remove") }),
1580
+ execute: async (args) => {
1581
+ await getDokployClient().post("server.remove", { serverId: args.serverId });
1582
+ return `Server ${args.serverId} removed.`;
1583
+ }
1584
+ });
1585
+ server.addTool({
1586
+ name: "dokploy_server_count",
1587
+ description: "Get the total number of servers",
1588
+ parameters: z.object({}),
1589
+ execute: async () => {
1590
+ return `Total servers: ${await getDokployClient().get("server.count")}`;
1591
+ }
1592
+ });
1593
+ server.addTool({
1594
+ name: "dokploy_server_publicIp",
1595
+ description: "Get the public IP address of the Dokploy host server",
1596
+ parameters: z.object({}),
1597
+ execute: async () => {
1598
+ return `Public IP: ${await getDokployClient().get("server.publicIp")}`;
1599
+ }
1600
+ });
1601
+ server.addTool({
1602
+ name: "dokploy_server_getMetrics",
1603
+ description: "Get resource metrics (CPU, memory, disk) for a server",
1604
+ parameters: z.object({
1605
+ url: z.string().describe("Metrics URL"),
1606
+ token: z.string().describe("Metrics auth token"),
1607
+ dataPoints: z.string().optional().describe("Number of data points")
1608
+ }),
1609
+ execute: async (args) => {
1610
+ const metrics = await getDokployClient().get("server.getServerMetrics", {
1611
+ url: args.url,
1612
+ token: args.token,
1613
+ ...args.dataPoints && { dataPoints: args.dataPoints }
1614
+ });
1615
+ return `# Server Metrics\n\n\`\`\`json\n${JSON.stringify(metrics, null, 2)}\n\`\`\``;
1616
+ }
1617
+ });
1618
+ }
1619
+
1620
+ //#endregion
1621
+ //#region src/tools/settings-tools.ts
1622
+ function registerSettingsTools(server) {
1623
+ server.addTool({
1624
+ name: "dokploy_settings_health",
1625
+ description: "Check the health status of the Dokploy instance",
1626
+ parameters: z.object({}),
1627
+ execute: async () => {
1628
+ const health = await getDokployClient().get("settings.health");
1629
+ return `# Dokploy Health\n\n\`\`\`json\n${JSON.stringify(health, null, 2)}\n\`\`\``;
1630
+ }
1631
+ });
1632
+ server.addTool({
1633
+ name: "dokploy_settings_getDokployVersion",
1634
+ description: "Get the current Dokploy version",
1635
+ parameters: z.object({}),
1636
+ execute: async () => {
1637
+ return `Dokploy version: ${await getDokployClient().get("settings.getDokployVersion")}`;
1638
+ }
1639
+ });
1640
+ server.addTool({
1641
+ name: "dokploy_settings_getIp",
1642
+ description: "Get the server IP address configured in Dokploy",
1643
+ parameters: z.object({}),
1644
+ execute: async () => {
1645
+ return `Server IP: ${await getDokployClient().get("settings.getIp")}`;
1646
+ }
1647
+ });
1648
+ server.addTool({
1649
+ name: "dokploy_settings_cleanAll",
1650
+ description: "Run all cleanup tasks (unused images, stopped containers, builder cache, etc.)",
1651
+ parameters: z.object({ serverId: z.string().optional().describe("Server ID to clean (optional, defaults to main server)") }),
1652
+ execute: async (args) => {
1653
+ await getDokployClient().post("settings.cleanAll", { ...args.serverId && { serverId: args.serverId } });
1654
+ return "All cleanup tasks completed.";
1655
+ }
1656
+ });
1657
+ server.addTool({
1658
+ name: "dokploy_settings_cleanUnusedImages",
1659
+ description: "Remove unused Docker images to free disk space",
1660
+ parameters: z.object({ serverId: z.string().optional().describe("Server ID (optional)") }),
1661
+ execute: async (args) => {
1662
+ await getDokployClient().post("settings.cleanUnusedImages", { ...args.serverId && { serverId: args.serverId } });
1663
+ return "Unused Docker images cleaned.";
1664
+ }
1665
+ });
1666
+ server.addTool({
1667
+ name: "dokploy_settings_reloadServer",
1668
+ description: "Reload the Dokploy server process",
1669
+ parameters: z.object({}),
1670
+ execute: async () => {
1671
+ await getDokployClient().post("settings.reloadServer");
1672
+ return "Dokploy server reloaded.";
1673
+ }
1674
+ });
1675
+ server.addTool({
1676
+ name: "dokploy_settings_reloadTraefik",
1677
+ description: "Reload the Traefik reverse proxy configuration",
1678
+ parameters: z.object({ serverId: z.string().optional().describe("Server ID (optional)") }),
1679
+ execute: async (args) => {
1680
+ await getDokployClient().post("settings.reloadTraefik", { ...args.serverId && { serverId: args.serverId } });
1681
+ return "Traefik configuration reloaded.";
1682
+ }
1683
+ });
1684
+ }
1685
+
1686
+ //#endregion
1687
+ //#region src/index.ts
1688
+ dotenv.config();
1689
+ const VERSION = "1.0.0";
1690
+ function setupDokployClient() {
1691
+ const baseUrl = process.env.DOKPLOY_URL;
1692
+ const apiKey = process.env.DOKPLOY_API_KEY;
1693
+ if (!baseUrl) {
1694
+ console.error("[Error] DOKPLOY_URL environment variable is required");
1695
+ console.error("[Error] Set it to your Dokploy instance URL (e.g., https://dokploy.example.com)");
1696
+ process.exit(1);
1697
+ }
1698
+ if (!apiKey) {
1699
+ console.error("[Error] DOKPLOY_API_KEY environment variable is required");
1700
+ console.error("[Error] Generate an API key in Dokploy Settings > API Keys");
1701
+ process.exit(1);
1702
+ }
1703
+ initializeDokployClient(baseUrl, apiKey);
1704
+ console.error(`[Setup] Dokploy client initialized for ${baseUrl}`);
1705
+ }
1706
+ const server = new FastMCP({
1707
+ name: "dokploy-mcp-server",
1708
+ version: VERSION,
1709
+ instructions: `A comprehensive Dokploy MCP server for managing deployments, applications, databases, domains, and infrastructure.
1710
+
1711
+ Available capabilities:
1712
+ - Projects: list, create, update, remove, duplicate
1713
+ - Applications: create, deploy, redeploy, start, stop, delete, configure builds, manage environment variables
1714
+ - Docker Compose: create, deploy, start, stop, manage services
1715
+ - Databases: unified tools for postgres, mysql, mariadb, mongo, redis (create, deploy, start, stop, manage)
1716
+ - Domains: create, configure, validate DNS, generate traefik.me domains
1717
+ - Docker: list containers, restart, inspect configuration
1718
+ - Servers: add, configure, monitor remote servers
1719
+ - Deployments: list, track, kill deployment processes
1720
+ - Backups: schedule, trigger manual backups, list backup files
1721
+ - Environments: create, duplicate, manage project environments
1722
+ - Infrastructure: ports, certificates, basic auth security
1723
+ - Settings: health checks, version info, cleanup, reload services`
1724
+ });
1725
+ registerProjectTools(server);
1726
+ registerApplicationTools(server);
1727
+ registerComposeTools(server);
1728
+ registerDeploymentTools(server);
1729
+ registerDockerTools(server);
1730
+ registerDomainTools(server);
1731
+ registerServerTools(server);
1732
+ registerSettingsTools(server);
1733
+ registerDatabaseTools(server);
1734
+ registerBackupTools(server);
1735
+ registerEnvironmentTools(server);
1736
+ registerInfrastructureTools(server);
1737
+ async function main() {
1738
+ try {
1739
+ setupDokployClient();
1740
+ const useHttp = process.env.TRANSPORT_TYPE === "httpStream" || process.env.TRANSPORT_TYPE === "http";
1741
+ const port = parseInt(process.env.PORT || "3000");
1742
+ const host = process.env.HOST || "0.0.0.0";
1743
+ if (useHttp) {
1744
+ console.error(`[Setup] Starting HTTP server on ${host}:${port}`);
1745
+ await server.start({
1746
+ transportType: "httpStream",
1747
+ httpStream: {
1748
+ port,
1749
+ host,
1750
+ endpoint: "/mcp"
1751
+ }
1752
+ });
1753
+ console.error(`[Setup] HTTP server ready at http://${host}:${port}/mcp`);
1754
+ } else {
1755
+ console.error("[Setup] Starting in stdio mode");
1756
+ await server.start({ transportType: "stdio" });
1757
+ }
1758
+ } catch (error) {
1759
+ console.error("[Error] Failed to start server:", error);
1760
+ process.exit(1);
1761
+ }
1762
+ }
1763
+ process.on("SIGINT", () => {
1764
+ console.error("[Shutdown] Shutting down Dokploy MCP Server...");
1765
+ process.exit(0);
1766
+ });
1767
+ process.on("SIGTERM", () => {
1768
+ console.error("[Shutdown] Shutting down Dokploy MCP Server...");
1769
+ process.exit(0);
1770
+ });
1771
+ main().catch(console.error);
1772
+
1773
+ //#endregion
1774
+ export { };
1775
+ //# sourceMappingURL=index.js.map