@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.
@@ -0,0 +1,88 @@
1
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ import { z } from 'zod';
3
+ import { existsSync } from 'node:fs';
4
+ import { basename } from 'node:path';
5
+ import { apiRequest, formatError, textResult } from '../api.js';
6
+ import { putFileToPresignedUrl } from '../upload.js';
7
+
8
+ interface StartResponse {
9
+ migration_id: string;
10
+ db_upload: { url: string; key: string; headers: Record<string, string>; max_bytes: number };
11
+ content_upload: { url: string; key: string; headers: Record<string, string>; max_bytes: number };
12
+ warning?: string;
13
+ }
14
+ interface RunResponse { ok: boolean; migration_id: string; new_url: string }
15
+ interface StatusResponse { status: string; step?: string; error?: string; log_tail?: string; finished_at?: string }
16
+
17
+ export function registerWordPressMigrateTools(server: McpServer) {
18
+ server.tool(
19
+ 'dailey_wordpress_migrate',
20
+ '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.',
21
+ {
22
+ project_id: z.string().describe('Target project ID (must be a WordPress project with a MySQL DB + volume)'),
23
+ action: z.enum(['migrate', 'status']).describe('migrate = full flow (upload + run + wait) | status = check a migration'),
24
+ db_file: z.string().optional().describe('Local path to the MySQL dump (.sql or .sql.gz) — required for migrate'),
25
+ content_file: z.string().optional().describe('Local path to the wp-content archive (.tar.gz/.tgz/.zip) — required for migrate'),
26
+ old_url: z.string().optional().describe('The site\'s current URL, e.g. https://oldsite.com — required for migrate'),
27
+ table_prefix: z.string().optional().describe('Table prefix if not wp_'),
28
+ migration_id: z.string().optional().describe('Migration ID — required for status'),
29
+ },
30
+ async ({ project_id, action, db_file, content_file, old_url, table_prefix, migration_id }) => {
31
+ if (action === 'status') {
32
+ if (!migration_id) return textResult('migration_id is required for action=status');
33
+ const res = await apiRequest<StatusResponse>('GET', `/projects/${project_id}/migrate/wordpress/${migration_id}`);
34
+ if (!res.ok) return textResult(formatError(res));
35
+ const s = res.data;
36
+ 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}` : ''}`);
37
+ }
38
+
39
+ // action === 'migrate'
40
+ if (!db_file || !content_file || !old_url) {
41
+ return textResult('db_file, content_file, and old_url are required for action=migrate');
42
+ }
43
+ for (const f of [db_file, content_file]) {
44
+ if (!existsSync(f)) return textResult(`File not found: ${f}`);
45
+ }
46
+
47
+ const start = await apiRequest<StartResponse>('POST', `/projects/${project_id}/migrate/wordpress`, {
48
+ db_filename: basename(db_file),
49
+ content_filename: basename(content_file),
50
+ });
51
+ if (!start.ok) return textResult(formatError(start));
52
+ const { migration_id: mid, db_upload, content_upload } = start.data;
53
+
54
+ try {
55
+ await putFileToPresignedUrl(db_upload.url, db_file, db_upload.headers);
56
+ await putFileToPresignedUrl(content_upload.url, content_file, content_upload.headers);
57
+ } catch (e: unknown) {
58
+ const message = e instanceof Error ? e.message : String(e);
59
+ return textResult(`Upload failed: ${message}\nMigration ${mid} is still pending — fix the file and call migrate again (a new migration will be started).`);
60
+ }
61
+
62
+ const run = await apiRequest<RunResponse>('POST', `/projects/${project_id}/migrate/wordpress/${mid}/run`, {
63
+ old_url, ...(table_prefix ? { table_prefix } : {}),
64
+ });
65
+ if (!run.ok) return textResult(formatError(run));
66
+
67
+ // Poll to terminal state (up to ~10 min; migrations are usually 1-3 min).
68
+ const started = Date.now();
69
+ let last: StatusResponse | null = null;
70
+ while (Date.now() - started < 10 * 60 * 1000) {
71
+ await new Promise((r) => setTimeout(r, 5000));
72
+ const st = await apiRequest<StatusResponse>('GET', `/projects/${project_id}/migrate/wordpress/${mid}`);
73
+ if (st.ok) {
74
+ last = st.data;
75
+ if (last.status === 'succeeded' || last.status === 'failed') break;
76
+ }
77
+ }
78
+ if (!last) return textResult(`Migration ${mid} launched but status could not be read. Check later with action=status.`);
79
+ if (last.status === 'succeeded') {
80
+ 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.`);
81
+ }
82
+ if (last.status === 'failed') {
83
+ 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.`);
84
+ }
85
+ return textResult(`Migration ${mid} still ${last.status} (step: ${last.step ?? '-'}) after 10 min — check again with action=status migration_id=${mid}.`);
86
+ },
87
+ );
88
+ }
package/src/upload.ts ADDED
@@ -0,0 +1,35 @@
1
+ import { createReadStream, statSync } from 'node:fs';
2
+ import { request } from 'node:https';
3
+ import { URL } from 'node:url';
4
+
5
+ /** Stream a local file to a presigned PUT URL. S3/R2 presigned PUTs require
6
+ * Content-Length (no chunked encoding), so this uses https.request, not fetch. */
7
+ export function putFileToPresignedUrl(
8
+ presignedUrl: string,
9
+ filePath: string,
10
+ headers: Record<string, string> = {},
11
+ onProgress?: (sentBytes: number, totalBytes: number) => void,
12
+ ): Promise<void> {
13
+ const total = statSync(filePath).size;
14
+ if (total <= 0) return Promise.reject(new Error(`${filePath} is empty`));
15
+ return new Promise((resolve, reject) => {
16
+ const u = new URL(presignedUrl);
17
+ const req = request(
18
+ { method: 'PUT', hostname: u.hostname, path: u.pathname + u.search, headers: { ...headers, 'Content-Length': total } },
19
+ (res) => {
20
+ let body = '';
21
+ res.on('data', (c) => { body += c; });
22
+ res.on('end', () => {
23
+ if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300) resolve();
24
+ else reject(new Error(`Upload failed: HTTP ${res.statusCode} ${body.slice(0, 300)}`));
25
+ });
26
+ },
27
+ );
28
+ req.on('error', reject);
29
+ let sent = 0;
30
+ const stream = createReadStream(filePath);
31
+ stream.on('data', (chunk) => { sent += (chunk as Buffer).length; onProgress?.(sent, total); });
32
+ stream.on('error', reject);
33
+ stream.pipe(req);
34
+ });
35
+ }
@@ -1,3 +0,0 @@
1
- import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
- export declare function registerBuddyTools(server: McpServer): void;
3
- //# sourceMappingURL=buddy.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"buddy.d.ts","sourceRoot":"","sources":["../../src/tools/buddy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAocpE,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,SAAS,QAuVnD"}