@daileyos/mcp-server 1.13.4 → 1.15.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 +4 -0
- package/dist/index.js.map +1 -1
- package/dist/tools/db-migrate.d.ts +3 -0
- package/dist/tools/db-migrate.d.ts.map +1 -0
- package/dist/tools/db-migrate.js +153 -0
- package/dist/tools/db-migrate.js.map +1 -0
- package/dist/tools/wordpress-migrate.d.ts +3 -0
- package/dist/tools/wordpress-migrate.d.ts.map +1 -0
- package/dist/tools/wordpress-migrate.js +76 -0
- package/dist/tools/wordpress-migrate.js.map +1 -0
- package/dist/upload.d.ts +4 -0
- package/dist/upload.d.ts.map +1 -0
- package/dist/upload.js +30 -0
- package/dist/upload.js.map +1 -0
- package/package.json +1 -1
- package/src/index.ts +4 -0
- package/src/tools/db-migrate.ts +211 -0
- package/src/tools/wordpress-migrate.ts +88 -0
- package/src/upload.ts +35 -0
- package/dist/tools/buddy.d.ts +0 -3
- package/dist/tools/buddy.d.ts.map +0 -1
- package/dist/tools/buddy.js +0 -765
- package/dist/tools/buddy.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -11,6 +11,7 @@ import { registerScaleTools } from './tools/scale.js';
|
|
|
11
11
|
import { registerEnvTools } from './tools/env.js';
|
|
12
12
|
import { registerDomainTools } from './tools/domains.js';
|
|
13
13
|
import { registerDbTools } from './tools/db.js';
|
|
14
|
+
import { registerMigrateTools } from './tools/db-migrate.js';
|
|
14
15
|
import { registerExecRunTools } from './tools/exec-run.js';
|
|
15
16
|
import { registerProjectTransferTools } from './tools/project-transfer.js';
|
|
16
17
|
import { registerAdminTools } from './tools/admin.js';
|
|
@@ -22,6 +23,7 @@ import { registerImageTools } from './tools/images.js';
|
|
|
22
23
|
import { registerProcessTools } from './tools/processes.js';
|
|
23
24
|
import { registerLifecycleTools } from './tools/lifecycle.js';
|
|
24
25
|
import { registerBackupTools } from './tools/backups.js';
|
|
26
|
+
import { registerWordPressMigrateTools } from './tools/wordpress-migrate.js';
|
|
25
27
|
import { registerResourceConfigTools } from './tools/resource-config.js';
|
|
26
28
|
import { registerLinkTools } from './tools/links.js';
|
|
27
29
|
import { registerCredentialRevealTools } from './tools/credentials-reveal.js';
|
|
@@ -114,8 +116,10 @@ registerLinkTools(server);
|
|
|
114
116
|
registerCredentialRevealTools(server);
|
|
115
117
|
// Data
|
|
116
118
|
registerDbTools(server);
|
|
119
|
+
registerMigrateTools(server);
|
|
117
120
|
registerStorageTools(server);
|
|
118
121
|
registerBackupTools(server);
|
|
122
|
+
registerWordPressMigrateTools(server);
|
|
119
123
|
// Runtime operations — exec into a pod, run one-off jobs
|
|
120
124
|
registerExecRunTools(server);
|
|
121
125
|
// Admin-only — customer onboarding, project transfer
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AAEjF,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO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E,SAAS,QAgHrD"}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { apiRequest, formatError, textResult } from '../api.js';
|
|
3
|
+
const sshSchema = z
|
|
4
|
+
.object({
|
|
5
|
+
host: z.string().describe('SSH bastion/tunnel host'),
|
|
6
|
+
port: z.number().int().optional().describe('SSH port (default 22)'),
|
|
7
|
+
user: z.string().describe('SSH user'),
|
|
8
|
+
password: z.string().optional().describe('SSH password (do not echo back)'),
|
|
9
|
+
private_key: z.string().optional().describe('SSH private key (PEM)'),
|
|
10
|
+
passphrase: z.string().optional().describe('Passphrase for the private key'),
|
|
11
|
+
})
|
|
12
|
+
.passthrough();
|
|
13
|
+
const sourceSchema = z.object({
|
|
14
|
+
host: z.string().describe('Source database host'),
|
|
15
|
+
port: z.number().int().optional().describe('Source database port'),
|
|
16
|
+
database: z.string().describe('Source database name'),
|
|
17
|
+
user: z.string().describe('Source database user'),
|
|
18
|
+
password: z.string().describe('Source database password — never echoed back in tool output'),
|
|
19
|
+
ssh: sshSchema.optional().describe('Optional SSH tunnel config for reaching the source DB'),
|
|
20
|
+
});
|
|
21
|
+
function progressLines(m) {
|
|
22
|
+
const lines = [
|
|
23
|
+
`Migration ${m.id}`,
|
|
24
|
+
'─'.repeat(40),
|
|
25
|
+
`Status: ${m.status || 'unknown'}`,
|
|
26
|
+
];
|
|
27
|
+
if (m.phase)
|
|
28
|
+
lines.push(`Phase: ${m.phase}`);
|
|
29
|
+
if (m.message)
|
|
30
|
+
lines.push(`Message: ${m.message}`);
|
|
31
|
+
if (m.rows_total !== undefined && m.rows_total !== null) {
|
|
32
|
+
const copied = m.rows_copied ?? 0;
|
|
33
|
+
lines.push(`Rows: ${copied}/${m.rows_total} copied`);
|
|
34
|
+
}
|
|
35
|
+
else if (m.rows_copied !== undefined && m.rows_copied !== null) {
|
|
36
|
+
lines.push(`Rows: ${m.rows_copied} copied`);
|
|
37
|
+
}
|
|
38
|
+
if (m.target_user)
|
|
39
|
+
lines.push(`Target user: ${m.target_user}`);
|
|
40
|
+
if (m.target_db)
|
|
41
|
+
lines.push(`Target db: ${m.target_db}`);
|
|
42
|
+
if (m.error)
|
|
43
|
+
lines.push(`Error: ${m.error}`);
|
|
44
|
+
if (m.report_json) {
|
|
45
|
+
try {
|
|
46
|
+
const parsed = typeof m.report_json === 'string' ? JSON.parse(m.report_json) : m.report_json;
|
|
47
|
+
if (parsed && typeof parsed === 'object') {
|
|
48
|
+
lines.push(`Report: ${JSON.stringify(parsed)}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
// report_json did not parse — skip the summary line.
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return lines;
|
|
56
|
+
}
|
|
57
|
+
export function registerMigrateTools(server) {
|
|
58
|
+
server.tool('dailey_db_migrate_start', 'Start a managed database migration from an external source DB into a project\'s managed database. Submits the source connection and kicks off an estimate (dry-run) — it does NOT copy data yet. The server derives the target engine from the project\'s managed DB (mysql | postgres); the source DB must be the SAME engine. Returns a migration id and status="estimating". Poll dailey_db_migrate_status until status="awaiting_confirm", review rows_total, then call dailey_db_migrate_confirm to run the real copy. The source password is used only to connect — it is never echoed back in any output.', {
|
|
59
|
+
project_id: z.string().describe('The project ID (or name) to migrate INTO'),
|
|
60
|
+
source: sourceSchema.describe('External source database connection details'),
|
|
61
|
+
allow_non_empty: z.boolean().optional().describe('Allow migrating into a target DB that already has data'),
|
|
62
|
+
row_ceiling: z.number().int().optional().describe('Optional safety cap on total rows to migrate'),
|
|
63
|
+
}, async ({ project_id, source, allow_non_empty, row_ceiling }) => {
|
|
64
|
+
const body = {
|
|
65
|
+
host: source.host,
|
|
66
|
+
database: source.database,
|
|
67
|
+
user: source.user,
|
|
68
|
+
password: source.password,
|
|
69
|
+
};
|
|
70
|
+
if (source.port !== undefined)
|
|
71
|
+
body.port = source.port;
|
|
72
|
+
if (source.ssh !== undefined)
|
|
73
|
+
body.ssh = source.ssh;
|
|
74
|
+
if (allow_non_empty !== undefined)
|
|
75
|
+
body.allow_non_empty = allow_non_empty;
|
|
76
|
+
if (row_ceiling !== undefined)
|
|
77
|
+
body.row_ceiling = row_ceiling;
|
|
78
|
+
const res = await apiRequest('POST', `/projects/${project_id}/migrations`, body);
|
|
79
|
+
if (!res.ok)
|
|
80
|
+
return textResult(formatError(res));
|
|
81
|
+
const d = res.data;
|
|
82
|
+
const lines = [
|
|
83
|
+
`Migration started`,
|
|
84
|
+
'─'.repeat(40),
|
|
85
|
+
`ID: ${d.id}`,
|
|
86
|
+
`Status: ${d.status}`,
|
|
87
|
+
'',
|
|
88
|
+
`Estimating now. Poll dailey_db_migrate_status project_id=${project_id} id=${d.id} until status=awaiting_confirm,`,
|
|
89
|
+
`then dailey_db_migrate_confirm to run the real copy.`,
|
|
90
|
+
];
|
|
91
|
+
return textResult(lines.join('\n'));
|
|
92
|
+
});
|
|
93
|
+
server.tool('dailey_db_migrate_status', 'Check the status/progress of a managed migration. With an id, returns that migration\'s progress fields (status, phase, message, rows_total, rows_copied, target_user, target_db, error). Without an id, lists all migrations for the project. Live progress is rows_copied/rows_total. Terminal statuses are completed | failed | canceled.', {
|
|
94
|
+
project_id: z.string().describe('The project ID (or name)'),
|
|
95
|
+
id: z.string().optional().describe('Migration id. Omit to list all migrations for the project.'),
|
|
96
|
+
}, async ({ project_id, id }) => {
|
|
97
|
+
if (!id) {
|
|
98
|
+
const res = await apiRequest('GET', `/projects/${project_id}/migrations`);
|
|
99
|
+
if (!res.ok)
|
|
100
|
+
return textResult(formatError(res));
|
|
101
|
+
const migrations = res.data.migrations || [];
|
|
102
|
+
if (migrations.length === 0)
|
|
103
|
+
return textResult('No migrations for this project.');
|
|
104
|
+
const lines = [`Migrations (${migrations.length})`, '─'.repeat(40)];
|
|
105
|
+
for (const m of migrations) {
|
|
106
|
+
const rows = m.rows_total !== undefined && m.rows_total !== null
|
|
107
|
+
? ` ${m.rows_copied ?? 0}/${m.rows_total} rows`
|
|
108
|
+
: '';
|
|
109
|
+
lines.push(`• ${m.id} status=${m.status}${m.phase ? ` phase=${m.phase}` : ''}${rows}`);
|
|
110
|
+
}
|
|
111
|
+
return textResult(lines.join('\n'));
|
|
112
|
+
}
|
|
113
|
+
const res = await apiRequest('GET', `/projects/${project_id}/migrations/${id}`);
|
|
114
|
+
if (!res.ok)
|
|
115
|
+
return textResult(formatError(res));
|
|
116
|
+
return textResult(progressLines(res.data.migration).join('\n'));
|
|
117
|
+
});
|
|
118
|
+
server.tool('dailey_db_migrate_confirm', 'Confirm a managed migration that is awaiting confirmation. This triggers the REAL data copy and mints a temporary target user for the load — it is only valid from status=awaiting_confirm. Returns the id and status="queued". After confirming, poll dailey_db_migrate_status to watch rows_copied/rows_total until a terminal status (completed | failed | canceled).', {
|
|
119
|
+
project_id: z.string().describe('The project ID (or name)'),
|
|
120
|
+
id: z.string().describe('Migration id to confirm (must be awaiting_confirm)'),
|
|
121
|
+
}, async ({ project_id, id }) => {
|
|
122
|
+
const res = await apiRequest('POST', `/projects/${project_id}/migrations/${id}/confirm`);
|
|
123
|
+
if (!res.ok)
|
|
124
|
+
return textResult(formatError(res));
|
|
125
|
+
const d = res.data;
|
|
126
|
+
const lines = [
|
|
127
|
+
`Migration confirmed — real data copy queued`,
|
|
128
|
+
'─'.repeat(40),
|
|
129
|
+
`ID: ${d.id}`,
|
|
130
|
+
`Status: ${d.status}`,
|
|
131
|
+
'',
|
|
132
|
+
`Poll dailey_db_migrate_status project_id=${project_id} id=${d.id} to watch progress to completion.`,
|
|
133
|
+
];
|
|
134
|
+
return textResult(lines.join('\n'));
|
|
135
|
+
});
|
|
136
|
+
server.tool('dailey_db_migrate_cancel', 'Cancel a managed migration. Valid from status pending | estimating | awaiting_confirm | queued (409 otherwise). Returns the id and status="canceled".', {
|
|
137
|
+
project_id: z.string().describe('The project ID (or name)'),
|
|
138
|
+
id: z.string().describe('Migration id to cancel'),
|
|
139
|
+
}, async ({ project_id, id }) => {
|
|
140
|
+
const res = await apiRequest('POST', `/projects/${project_id}/migrations/${id}/cancel`);
|
|
141
|
+
if (!res.ok)
|
|
142
|
+
return textResult(formatError(res));
|
|
143
|
+
const d = res.data;
|
|
144
|
+
const lines = [
|
|
145
|
+
`Migration canceled`,
|
|
146
|
+
'─'.repeat(40),
|
|
147
|
+
`ID: ${d.id}`,
|
|
148
|
+
`Status: ${d.status}`,
|
|
149
|
+
];
|
|
150
|
+
return textResult(lines.join('\n'));
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=db-migrate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"db-migrate.js","sourceRoot":"","sources":["../../src/tools/db-migrate.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AA8ChE,MAAM,SAAS,GAAG,CAAC;KAChB,MAAM,CAAC;IACN,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,yBAAyB,CAAC;IACpD,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,uBAAuB,CAAC;IACnE,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC;IACrC,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,iCAAiC,CAAC;IAC3E,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,uBAAuB,CAAC;IACpE,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,gCAAgC,CAAC;CAC7E,CAAC;KACD,WAAW,EAAE,CAAC;AAEjB,MAAM,YAAY,G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'zod';
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
import { basename } from 'node:path';
|
|
4
|
+
import { apiRequest, formatError, textResult } from '../api.js';
|
|
5
|
+
import { putFileToPresignedUrl } from '../upload.js';
|
|
6
|
+
export function registerWordPressMigrateTools(server) {
|
|
7
|
+
server.tool('dailey_wordpress_migrate', 'Migrate an existing WordPress site (from any host) onto Dailey OS, intact. action=migrate uploads a MySQL dump (.sql/.sql.gz) + a wp-content archive (.tar.gz/.zip) from local paths, then runs the import (DB import, serialized-safe URL rewrite, wp-content swap) and reports the final status. WARNING: replaces the target project\'s database and wp-content. action=status checks a previous migration.', {
|
|
8
|
+
project_id: z.string().describe('Target project ID (must be a WordPress project with a MySQL DB + volume)'),
|
|
9
|
+
action: z.enum(['migrate', 'status']).describe('migrate = full flow (upload + run + wait) | status = check a migration'),
|
|
10
|
+
db_file: z.string().optional().describe('Local path to the MySQL dump (.sql or .sql.gz) — required for migrate'),
|
|
11
|
+
content_file: z.string().optional().describe('Local path to the wp-content archive (.tar.gz/.tgz/.zip) — required for migrate'),
|
|
12
|
+
old_url: z.string().optional().describe('The site\'s current URL, e.g. https://oldsite.com — required for migrate'),
|
|
13
|
+
table_prefix: z.string().optional().describe('Table prefix if not wp_'),
|
|
14
|
+
migration_id: z.string().optional().describe('Migration ID — required for status'),
|
|
15
|
+
}, async ({ project_id, action, db_file, content_file, old_url, table_prefix, migration_id }) => {
|
|
16
|
+
if (action === 'status') {
|
|
17
|
+
if (!migration_id)
|
|
18
|
+
return textResult('migration_id is required for action=status');
|
|
19
|
+
const res = await apiRequest('GET', `/projects/${project_id}/migrate/wordpress/${migration_id}`);
|
|
20
|
+
if (!res.ok)
|
|
21
|
+
return textResult(formatError(res));
|
|
22
|
+
const s = res.data;
|
|
23
|
+
return textResult(`Migration ${migration_id}: ${s.status}${s.step ? ` (step: ${s.step})` : ''}${s.error ? `\nError: ${s.error}` : ''}${s.log_tail ? `\n--- log ---\n${s.log_tail}` : ''}`);
|
|
24
|
+
}
|
|
25
|
+
// action === 'migrate'
|
|
26
|
+
if (!db_file || !content_file || !old_url) {
|
|
27
|
+
return textResult('db_file, content_file, and old_url are required for action=migrate');
|
|
28
|
+
}
|
|
29
|
+
for (const f of [db_file, content_file]) {
|
|
30
|
+
if (!existsSync(f))
|
|
31
|
+
return textResult(`File not found: ${f}`);
|
|
32
|
+
}
|
|
33
|
+
const start = await apiRequest('POST', `/projects/${project_id}/migrate/wordpress`, {
|
|
34
|
+
db_filename: basename(db_file),
|
|
35
|
+
content_filename: basename(content_file),
|
|
36
|
+
});
|
|
37
|
+
if (!start.ok)
|
|
38
|
+
return textResult(formatError(start));
|
|
39
|
+
const { migration_id: mid, db_upload, content_upload } = start.data;
|
|
40
|
+
try {
|
|
41
|
+
await putFileToPresignedUrl(db_upload.url, db_file, db_upload.headers);
|
|
42
|
+
await putFileToPresignedUrl(content_upload.url, content_file, content_upload.headers);
|
|
43
|
+
}
|
|
44
|
+
catch (e) {
|
|
45
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
46
|
+
return textResult(`Upload failed: ${message}\nMigration ${mid} is still pending — fix the file and call migrate again (a new migration will be started).`);
|
|
47
|
+
}
|
|
48
|
+
const run = await apiRequest('POST', `/projects/${project_id}/migrate/wordpress/${mid}/run`, {
|
|
49
|
+
old_url, ...(table_prefix ? { table_prefix } : {}),
|
|
50
|
+
});
|
|
51
|
+
if (!run.ok)
|
|
52
|
+
return textResult(formatError(run));
|
|
53
|
+
// Poll to terminal state (up to ~10 min; migrations are usually 1-3 min).
|
|
54
|
+
const started = Date.now();
|
|
55
|
+
let last = null;
|
|
56
|
+
while (Date.now() - started < 10 * 60 * 1000) {
|
|
57
|
+
await new Promise((r) => setTimeout(r, 5000));
|
|
58
|
+
const st = await apiRequest('GET', `/projects/${project_id}/migrate/wordpress/${mid}`);
|
|
59
|
+
if (st.ok) {
|
|
60
|
+
last = st.data;
|
|
61
|
+
if (last.status === 'succeeded' || last.status === 'failed')
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (!last)
|
|
66
|
+
return textResult(`Migration ${mid} launched but status could not be read. Check later with action=status.`);
|
|
67
|
+
if (last.status === 'succeeded') {
|
|
68
|
+
return textResult(`Migration succeeded. Site is live at ${run.data.new_url} with the imported content.\nNote: hard-refresh and re-save permalinks (Settings > Permalinks) if pretty URLs 404.`);
|
|
69
|
+
}
|
|
70
|
+
if (last.status === 'failed') {
|
|
71
|
+
return textResult(`Migration FAILED at step: ${last.step ?? 'unknown'}\n${last.error ?? ''}\n--- log ---\n${last.log_tail ?? ''}\nYour staged files were kept — fix the issue and run migrate again.`);
|
|
72
|
+
}
|
|
73
|
+
return textResult(`Migration ${mid} still ${last.status} (step: ${last.step ?? '-'}) after 10 min — check again with action=status migration_id=${mid}.`);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=wordpress-migrate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wordpress-migrate.js","sourceRoot":"","sources":["../../src/tools/wordpress-migrate.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAWrD,MAAM,UAAU,6BAA6B,CAAC,MAAiB;IAC7D,MAAM,CAAC,IAAI,CACT,0BAA0B,EAC1B,gZAAgZ,EAChZ;QACE,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,0EAA0E,CAAC;QAC3G,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC,QAAQ,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AI,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;YAC7B,OAAO,UAAU,CAAC,6BAA6B,IAAI,CAAC,IAAI,IAAI,SAAS,KAAK,IAAI,CAAC,KAAK,IAAI,EAAE,kBAAkB,IAAI,CAAC,QAAQ,IAAI,EAAE,sEAAsE,CAAC,CAAC;QACzM,CAAC;QACD,OAAO,UAAU,CAAC,aAAa,GAAG,UAAU,IAAI,CAAC,MAAM,WAAW,IAAI,CAAC,IAAI,IAAI,GAAG,gEAAgE,GAAG,GAAG,CAAC,CAAC;IAC5J,CAAC,CACF,CAAC;AACJ,CAAC"}
|
package/dist/upload.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Stream a local file to a presigned PUT URL. S3/R2 presigned PUTs require
|
|
2
|
+
* Content-Length (no chunked encoding), so this uses https.request, not fetch. */
|
|
3
|
+
export declare function putFileToPresignedUrl(presignedUrl: string, filePath: string, headers?: Record<string, string>, onProgress?: (sentBytes: number, totalBytes: number) => void): Promise<void>;
|
|
4
|
+
//# sourceMappingURL=upload.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../src/upload.ts"],"names":[],"mappings":"AAIA;mFACmF;AACnF,wBAAgB,qBAAqB,CACnC,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,EACpC,UAAU,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,KAAK,IAAI,GAC3D,OAAO,CAAC,IAAI,CAAC,CAuBf"}
|
package/dist/upload.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { createReadStream, statSync } from 'node:fs';
|
|
2
|
+
import { request } from 'node:https';
|
|
3
|
+
import { URL } from 'node:url';
|
|
4
|
+
/** Stream a local file to a presigned PUT URL. S3/R2 presigned PUTs require
|
|
5
|
+
* Content-Length (no chunked encoding), so this uses https.request, not fetch. */
|
|
6
|
+
export function putFileToPresignedUrl(presignedUrl, filePath, headers = {}, onProgress) {
|
|
7
|
+
const total = statSync(filePath).size;
|
|
8
|
+
if (total <= 0)
|
|
9
|
+
return Promise.reject(new Error(`${filePath} is empty`));
|
|
10
|
+
return new Promise((resolve, reject) => {
|
|
11
|
+
const u = new URL(presignedUrl);
|
|
12
|
+
const req = request({ method: 'PUT', hostname: u.hostname, path: u.pathname + u.search, headers: { ...headers, 'Content-Length': total } }, (res) => {
|
|
13
|
+
let body = '';
|
|
14
|
+
res.on('data', (c) => { body += c; });
|
|
15
|
+
res.on('end', () => {
|
|
16
|
+
if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300)
|
|
17
|
+
resolve();
|
|
18
|
+
else
|
|
19
|
+
reject(new Error(`Upload failed: HTTP ${res.statusCode} ${body.slice(0, 300)}`));
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
req.on('error', reject);
|
|
23
|
+
let sent = 0;
|
|
24
|
+
const stream = createReadStream(filePath);
|
|
25
|
+
stream.on('data', (chunk) => { sent += chunk.length; onProgress?.(sent, total); });
|
|
26
|
+
stream.on('error', reject);
|
|
27
|
+
stream.pipe(req);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=upload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upload.js","sourceRoot":"","sources":["../src/upload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/B;mFACmF;AACnF,MAAM,UAAU,qBAAqB,CACnC,YAAoB,EACpB,QAAgB,EAChB,UAAkC,EAAE,EACpC,UAA4D;IAE5D,MAAM,KAAK,GAAG,QAAQ,CAAC,QAAQ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AAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,GAAG,IAAI,IAAK,KAAgB,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC/F,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC3B,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACnB,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -13,6 +13,7 @@ import { registerScaleTools } from './tools/scale.js';
|
|
|
13
13
|
import { registerEnvTools } from './tools/env.js';
|
|
14
14
|
import { registerDomainTools } from './tools/domains.js';
|
|
15
15
|
import { registerDbTools } from './tools/db.js';
|
|
16
|
+
import { registerMigrateTools } from './tools/db-migrate.js';
|
|
16
17
|
import { registerExecRunTools } from './tools/exec-run.js';
|
|
17
18
|
import { registerProjectTransferTools } from './tools/project-transfer.js';
|
|
18
19
|
import { registerAdminTools } from './tools/admin.js';
|
|
@@ -24,6 +25,7 @@ import { registerImageTools } from './tools/images.js';
|
|
|
24
25
|
import { registerProcessTools } from './tools/processes.js';
|
|
25
26
|
import { registerLifecycleTools } from './tools/lifecycle.js';
|
|
26
27
|
import { registerBackupTools } from './tools/backups.js';
|
|
28
|
+
import { registerWordPressMigrateTools } from './tools/wordpress-migrate.js';
|
|
27
29
|
import { registerResourceConfigTools } from './tools/resource-config.js';
|
|
28
30
|
import { registerLinkTools } from './tools/links.js';
|
|
29
31
|
import { registerCredentialRevealTools } from './tools/credentials-reveal.js';
|
|
@@ -134,8 +136,10 @@ registerCredentialRevealTools(server);
|
|
|
134
136
|
|
|
135
137
|
// Data
|
|
136
138
|
registerDbTools(server);
|
|
139
|
+
registerMigrateTools(server);
|
|
137
140
|
registerStorageTools(server);
|
|
138
141
|
registerBackupTools(server);
|
|
142
|
+
registerWordPressMigrateTools(server);
|
|
139
143
|
|
|
140
144
|
// Runtime operations — exec into a pod, run one-off jobs
|
|
141
145
|
registerExecRunTools(server);
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { apiRequest, formatError, textResult } from '../api.js';
|
|
4
|
+
|
|
5
|
+
// MigrationRow as returned by the customer-api managed-migrations endpoints.
|
|
6
|
+
// callback_token_hash is never returned by the server, and we never echo the
|
|
7
|
+
// source password back in tool output (security hard rule).
|
|
8
|
+
interface MigrationRow {
|
|
9
|
+
id: string;
|
|
10
|
+
project_id: string;
|
|
11
|
+
engine: string;
|
|
12
|
+
status: string;
|
|
13
|
+
phase?: string;
|
|
14
|
+
message?: string;
|
|
15
|
+
rows_total?: number;
|
|
16
|
+
rows_copied?: number;
|
|
17
|
+
target_user?: string;
|
|
18
|
+
target_db?: string;
|
|
19
|
+
report_json?: unknown;
|
|
20
|
+
error?: string;
|
|
21
|
+
dispatch_count?: number;
|
|
22
|
+
created_at?: string;
|
|
23
|
+
updated_at?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface StartResponse {
|
|
27
|
+
id: string;
|
|
28
|
+
status: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface ListResponse {
|
|
32
|
+
migrations: MigrationRow[];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
interface GetResponse {
|
|
36
|
+
migration: MigrationRow;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
interface ConfirmResponse {
|
|
40
|
+
id: string;
|
|
41
|
+
status: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
interface CancelResponse {
|
|
45
|
+
id: string;
|
|
46
|
+
status: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const sshSchema = z
|
|
50
|
+
.object({
|
|
51
|
+
host: z.string().describe('SSH bastion/tunnel host'),
|
|
52
|
+
port: z.number().int().optional().describe('SSH port (default 22)'),
|
|
53
|
+
user: z.string().describe('SSH user'),
|
|
54
|
+
password: z.string().optional().describe('SSH password (do not echo back)'),
|
|
55
|
+
private_key: z.string().optional().describe('SSH private key (PEM)'),
|
|
56
|
+
passphrase: z.string().optional().describe('Passphrase for the private key'),
|
|
57
|
+
})
|
|
58
|
+
.passthrough();
|
|
59
|
+
|
|
60
|
+
const sourceSchema = z.object({
|
|
61
|
+
host: z.string().describe('Source database host'),
|
|
62
|
+
port: z.number().int().optional().describe('Source database port'),
|
|
63
|
+
database: z.string().describe('Source database name'),
|
|
64
|
+
user: z.string().describe('Source database user'),
|
|
65
|
+
password: z.string().describe('Source database password — never echoed back in tool output'),
|
|
66
|
+
ssh: sshSchema.optional().describe('Optional SSH tunnel config for reaching the source DB'),
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
function progressLines(m: MigrationRow): string[] {
|
|
70
|
+
const lines = [
|
|
71
|
+
`Migration ${m.id}`,
|
|
72
|
+
'─'.repeat(40),
|
|
73
|
+
`Status: ${m.status || 'unknown'}`,
|
|
74
|
+
];
|
|
75
|
+
if (m.phase) lines.push(`Phase: ${m.phase}`);
|
|
76
|
+
if (m.message) lines.push(`Message: ${m.message}`);
|
|
77
|
+
if (m.rows_total !== undefined && m.rows_total !== null) {
|
|
78
|
+
const copied = m.rows_copied ?? 0;
|
|
79
|
+
lines.push(`Rows: ${copied}/${m.rows_total} copied`);
|
|
80
|
+
} else if (m.rows_copied !== undefined && m.rows_copied !== null) {
|
|
81
|
+
lines.push(`Rows: ${m.rows_copied} copied`);
|
|
82
|
+
}
|
|
83
|
+
if (m.target_user) lines.push(`Target user: ${m.target_user}`);
|
|
84
|
+
if (m.target_db) lines.push(`Target db: ${m.target_db}`);
|
|
85
|
+
if (m.error) lines.push(`Error: ${m.error}`);
|
|
86
|
+
if (m.report_json) {
|
|
87
|
+
try {
|
|
88
|
+
const parsed = typeof m.report_json === 'string' ? JSON.parse(m.report_json) : m.report_json;
|
|
89
|
+
if (parsed && typeof parsed === 'object') {
|
|
90
|
+
lines.push(`Report: ${JSON.stringify(parsed)}`);
|
|
91
|
+
}
|
|
92
|
+
} catch {
|
|
93
|
+
// report_json did not parse — skip the summary line.
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return lines;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function registerMigrateTools(server: McpServer) {
|
|
100
|
+
server.tool(
|
|
101
|
+
'dailey_db_migrate_start',
|
|
102
|
+
'Start a managed database migration from an external source DB into a project\'s managed database. Submits the source connection and kicks off an estimate (dry-run) — it does NOT copy data yet. The server derives the target engine from the project\'s managed DB (mysql | postgres); the source DB must be the SAME engine. Returns a migration id and status="estimating". Poll dailey_db_migrate_status until status="awaiting_confirm", review rows_total, then call dailey_db_migrate_confirm to run the real copy. The source password is used only to connect — it is never echoed back in any output.',
|
|
103
|
+
{
|
|
104
|
+
project_id: z.string().describe('The project ID (or name) to migrate INTO'),
|
|
105
|
+
source: sourceSchema.describe('External source database connection details'),
|
|
106
|
+
allow_non_empty: z.boolean().optional().describe('Allow migrating into a target DB that already has data'),
|
|
107
|
+
row_ceiling: z.number().int().optional().describe('Optional safety cap on total rows to migrate'),
|
|
108
|
+
},
|
|
109
|
+
async ({ project_id, source, allow_non_empty, row_ceiling }) => {
|
|
110
|
+
const body: Record<string, unknown> = {
|
|
111
|
+
host: source.host,
|
|
112
|
+
database: source.database,
|
|
113
|
+
user: source.user,
|
|
114
|
+
password: source.password,
|
|
115
|
+
};
|
|
116
|
+
if (source.port !== undefined) body.port = source.port;
|
|
117
|
+
if (source.ssh !== undefined) body.ssh = source.ssh;
|
|
118
|
+
if (allow_non_empty !== undefined) body.allow_non_empty = allow_non_empty;
|
|
119
|
+
if (row_ceiling !== undefined) body.row_ceiling = row_ceiling;
|
|
120
|
+
|
|
121
|
+
const res = await apiRequest<StartResponse>('POST', `/projects/${project_id}/migrations`, body);
|
|
122
|
+
if (!res.ok) return textResult(formatError(res));
|
|
123
|
+
|
|
124
|
+
const d = res.data;
|
|
125
|
+
const lines = [
|
|
126
|
+
`Migration started`,
|
|
127
|
+
'─'.repeat(40),
|
|
128
|
+
`ID: ${d.id}`,
|
|
129
|
+
`Status: ${d.status}`,
|
|
130
|
+
'',
|
|
131
|
+
`Estimating now. Poll dailey_db_migrate_status project_id=${project_id} id=${d.id} until status=awaiting_confirm,`,
|
|
132
|
+
`then dailey_db_migrate_confirm to run the real copy.`,
|
|
133
|
+
];
|
|
134
|
+
return textResult(lines.join('\n'));
|
|
135
|
+
},
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
server.tool(
|
|
139
|
+
'dailey_db_migrate_status',
|
|
140
|
+
'Check the status/progress of a managed migration. With an id, returns that migration\'s progress fields (status, phase, message, rows_total, rows_copied, target_user, target_db, error). Without an id, lists all migrations for the project. Live progress is rows_copied/rows_total. Terminal statuses are completed | failed | canceled.',
|
|
141
|
+
{
|
|
142
|
+
project_id: z.string().describe('The project ID (or name)'),
|
|
143
|
+
id: z.string().optional().describe('Migration id. Omit to list all migrations for the project.'),
|
|
144
|
+
},
|
|
145
|
+
async ({ project_id, id }) => {
|
|
146
|
+
if (!id) {
|
|
147
|
+
const res = await apiRequest<ListResponse>('GET', `/projects/${project_id}/migrations`);
|
|
148
|
+
if (!res.ok) return textResult(formatError(res));
|
|
149
|
+
const migrations = res.data.migrations || [];
|
|
150
|
+
if (migrations.length === 0) return textResult('No migrations for this project.');
|
|
151
|
+
const lines = [`Migrations (${migrations.length})`, '─'.repeat(40)];
|
|
152
|
+
for (const m of migrations) {
|
|
153
|
+
const rows =
|
|
154
|
+
m.rows_total !== undefined && m.rows_total !== null
|
|
155
|
+
? ` ${m.rows_copied ?? 0}/${m.rows_total} rows`
|
|
156
|
+
: '';
|
|
157
|
+
lines.push(`• ${m.id} status=${m.status}${m.phase ? ` phase=${m.phase}` : ''}${rows}`);
|
|
158
|
+
}
|
|
159
|
+
return textResult(lines.join('\n'));
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const res = await apiRequest<GetResponse>('GET', `/projects/${project_id}/migrations/${id}`);
|
|
163
|
+
if (!res.ok) return textResult(formatError(res));
|
|
164
|
+
return textResult(progressLines(res.data.migration).join('\n'));
|
|
165
|
+
},
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
server.tool(
|
|
169
|
+
'dailey_db_migrate_confirm',
|
|
170
|
+
'Confirm a managed migration that is awaiting confirmation. This triggers the REAL data copy and mints a temporary target user for the load — it is only valid from status=awaiting_confirm. Returns the id and status="queued". After confirming, poll dailey_db_migrate_status to watch rows_copied/rows_total until a terminal status (completed | failed | canceled).',
|
|
171
|
+
{
|
|
172
|
+
project_id: z.string().describe('The project ID (or name)'),
|
|
173
|
+
id: z.string().describe('Migration id to confirm (must be awaiting_confirm)'),
|
|
174
|
+
},
|
|
175
|
+
async ({ project_id, id }) => {
|
|
176
|
+
const res = await apiRequest<ConfirmResponse>('POST', `/projects/${project_id}/migrations/${id}/confirm`);
|
|
177
|
+
if (!res.ok) return textResult(formatError(res));
|
|
178
|
+
const d = res.data;
|
|
179
|
+
const lines = [
|
|
180
|
+
`Migration confirmed — real data copy queued`,
|
|
181
|
+
'─'.repeat(40),
|
|
182
|
+
`ID: ${d.id}`,
|
|
183
|
+
`Status: ${d.status}`,
|
|
184
|
+
'',
|
|
185
|
+
`Poll dailey_db_migrate_status project_id=${project_id} id=${d.id} to watch progress to completion.`,
|
|
186
|
+
];
|
|
187
|
+
return textResult(lines.join('\n'));
|
|
188
|
+
},
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
server.tool(
|
|
192
|
+
'dailey_db_migrate_cancel',
|
|
193
|
+
'Cancel a managed migration. Valid from status pending | estimating | awaiting_confirm | queued (409 otherwise). Returns the id and status="canceled".',
|
|
194
|
+
{
|
|
195
|
+
project_id: z.string().describe('The project ID (or name)'),
|
|
196
|
+
id: z.string().describe('Migration id to cancel'),
|
|
197
|
+
},
|
|
198
|
+
async ({ project_id, id }) => {
|
|
199
|
+
const res = await apiRequest<CancelResponse>('POST', `/projects/${project_id}/migrations/${id}/cancel`);
|
|
200
|
+
if (!res.ok) return textResult(formatError(res));
|
|
201
|
+
const d = res.data;
|
|
202
|
+
const lines = [
|
|
203
|
+
`Migration canceled`,
|
|
204
|
+
'─'.repeat(40),
|
|
205
|
+
`ID: ${d.id}`,
|
|
206
|
+
`Status: ${d.status}`,
|
|
207
|
+
];
|
|
208
|
+
return textResult(lines.join('\n'));
|
|
209
|
+
},
|
|
210
|
+
);
|
|
211
|
+
}
|