@daileyos/mcp-server 1.19.0 → 1.20.1

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.
Files changed (37) hide show
  1. package/dist/index.js +13 -0
  2. package/dist/index.js.map +1 -1
  3. package/dist/tools/addons.d.ts +3 -0
  4. package/dist/tools/addons.d.ts.map +1 -0
  5. package/dist/tools/addons.js +69 -0
  6. package/dist/tools/addons.js.map +1 -0
  7. package/dist/tools/credits.d.ts +3 -0
  8. package/dist/tools/credits.d.ts.map +1 -0
  9. package/dist/tools/credits.js +57 -0
  10. package/dist/tools/credits.js.map +1 -0
  11. package/dist/tools/dailey-images.d.ts +14 -0
  12. package/dist/tools/dailey-images.d.ts.map +1 -0
  13. package/dist/tools/dailey-images.js +87 -0
  14. package/dist/tools/dailey-images.js.map +1 -0
  15. package/dist/tools/email.d.ts +3 -0
  16. package/dist/tools/email.d.ts.map +1 -0
  17. package/dist/tools/email.js +61 -0
  18. package/dist/tools/email.js.map +1 -0
  19. package/dist/tools/environments.d.ts +3 -0
  20. package/dist/tools/environments.d.ts.map +1 -0
  21. package/dist/tools/environments.js +75 -0
  22. package/dist/tools/environments.js.map +1 -0
  23. package/dist/tools/wordpress-snapshot.d.ts +3 -0
  24. package/dist/tools/wordpress-snapshot.d.ts.map +1 -0
  25. package/dist/tools/wordpress-snapshot.js +121 -0
  26. package/dist/tools/wordpress-snapshot.js.map +1 -0
  27. package/package.json +1 -1
  28. package/src/index.ts +13 -0
  29. package/src/tools/addons.ts +124 -0
  30. package/src/tools/credits.ts +97 -0
  31. package/src/tools/dailey-images.ts +151 -0
  32. package/src/tools/email.ts +101 -0
  33. package/src/tools/environments.ts +138 -0
  34. package/src/tools/wordpress-snapshot.ts +221 -0
  35. package/tests/dailey-images.test.mjs +156 -0
  36. package/tests/environments.test.mjs +230 -0
  37. package/tests/wp-snapshot.test.mjs +261 -0
@@ -0,0 +1,138 @@
1
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ import { z } from 'zod';
3
+ import { apiRequest, textResult, formatError } from '../api.js';
4
+
5
+ interface Environment {
6
+ id?: string;
7
+ environment: string;
8
+ deployment: string;
9
+ domain: string;
10
+ status: string;
11
+ db_name?: string;
12
+ storage_prefix?: string;
13
+ image?: string;
14
+ replicas?: number;
15
+ created_at?: string;
16
+ updated_at?: string;
17
+ }
18
+
19
+ interface EnvironmentsResponse {
20
+ environments: Environment[];
21
+ }
22
+
23
+ interface ClonePreviewPlan {
24
+ steps: string[];
25
+ sourceLabel?: string;
26
+ targetLabel?: string;
27
+ }
28
+
29
+ interface ClonePreviewResponse {
30
+ plan: ClonePreviewPlan;
31
+ confirm_token: string;
32
+ }
33
+
34
+ interface CloneExecuteResponse {
35
+ operation_id: string;
36
+ }
37
+
38
+ export function registerEnvironmentTools(server: McpServer) {
39
+ server.tool(
40
+ 'dailey_environments',
41
+ 'List prod and staging environments for a project',
42
+ {
43
+ project: z.string().describe('The project ID or slug'),
44
+ },
45
+ async ({ project }) => {
46
+ const res = await apiRequest<EnvironmentsResponse>('GET', `/projects/${project}/environments`);
47
+ if (!res.ok) return textResult(formatError(res));
48
+
49
+ const envs = res.data.environments;
50
+ if (!envs || envs.length === 0) {
51
+ return textResult(`No environments found for project ${project}.`);
52
+ }
53
+
54
+ const lines: string[] = [`Environments for project ${project}:`, ''];
55
+
56
+ for (const env of envs) {
57
+ const label = env.environment === 'prod' ? 'Production (prod)' : `${env.environment}`;
58
+ lines.push(`${label}`);
59
+ lines.push(` Status: ${env.status}`);
60
+ lines.push(` Domain: https://${env.domain}`);
61
+ lines.push(` Deployment: ${env.deployment}`);
62
+ if (env.db_name) lines.push(` Database: ${env.db_name}`);
63
+ if (env.image) lines.push(` Image: ${env.image}`);
64
+ if (env.replicas != null) lines.push(` Replicas: ${env.replicas}`);
65
+ if (env.created_at) lines.push(` Created: ${env.created_at}`);
66
+ lines.push('');
67
+ }
68
+
69
+ return textResult(lines.join('\n').trimEnd());
70
+ },
71
+ );
72
+
73
+ server.tool(
74
+ 'dailey_wp_clone',
75
+ 'Clone a WordPress project from prod to staging (DESTRUCTIVE — two-phase). Call WITHOUT confirm_token to get the plan; re-call WITH the returned confirm_token to execute.',
76
+ {
77
+ project: z.string().describe('The project ID or slug'),
78
+ confirm_token: z.string().optional().describe(
79
+ 'Token from the plan response. Omit to preview the plan; provide to execute. ~10min TTL.',
80
+ ),
81
+ },
82
+ async ({ project, confirm_token }) => {
83
+ if (!confirm_token) {
84
+ // Phase 1: preview
85
+ const res = await apiRequest<ClonePreviewResponse>(
86
+ 'POST',
87
+ `/projects/${project}/wp/clone/preview`,
88
+ );
89
+ if (!res.ok) return textResult(formatError(res));
90
+
91
+ const { plan, confirm_token: token } = res.data;
92
+ const lines: string[] = [];
93
+
94
+ if (plan.sourceLabel || plan.targetLabel) {
95
+ lines.push(`Clone plan: ${plan.sourceLabel ?? 'prod'} → ${plan.targetLabel ?? 'staging'}`);
96
+ } else {
97
+ lines.push(`Clone plan for project ${project} (prod → staging):`);
98
+ }
99
+
100
+ if (plan.steps && plan.steps.length > 0) {
101
+ lines.push('');
102
+ lines.push('Steps:');
103
+ plan.steps.forEach((step, i) => {
104
+ lines.push(` ${i + 1}. ${step}`);
105
+ });
106
+ }
107
+
108
+ lines.push('');
109
+ lines.push(`confirm_token: ${token}`);
110
+ lines.push('');
111
+ lines.push(
112
+ 'This will overwrite staging with prod data. To proceed, re-call dailey_wp_clone with the same project and this confirm_token.',
113
+ );
114
+
115
+ return textResult(lines.join('\n'));
116
+ }
117
+
118
+ // Phase 2: execute
119
+ const res = await apiRequest<CloneExecuteResponse>(
120
+ 'POST',
121
+ `/projects/${project}/wp/clone`,
122
+ { confirm_token, confirmation: 'CLONE' },
123
+ );
124
+
125
+ if (!res.ok) {
126
+ if (res.status === 409) {
127
+ return textResult('A clone or restore operation is already in progress for this project.');
128
+ }
129
+ return textResult(formatError(res));
130
+ }
131
+
132
+ const { operation_id } = res.data;
133
+ return textResult(
134
+ `Clone started. operation_id=${operation_id}. Poll with dailey_wp_operation_status (project, operation_id).`,
135
+ );
136
+ },
137
+ );
138
+ }
@@ -0,0 +1,221 @@
1
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ import { z } from 'zod';
3
+ import { apiRequest, textResult, jsonResult, formatError } from '../api.js';
4
+
5
+ interface Snapshot {
6
+ id: string;
7
+ created_at: string;
8
+ kind: string;
9
+ status: string;
10
+ env?: string;
11
+ db_bytes?: number;
12
+ uploads_bytes?: number;
13
+ }
14
+
15
+ interface SnapshotsResponse {
16
+ snapshots: Snapshot[];
17
+ }
18
+
19
+ interface SnapshotStartResponse {
20
+ operation_id: string;
21
+ status_url?: string;
22
+ }
23
+
24
+ interface RestorePreviewPlan {
25
+ steps: string[];
26
+ backupFirst?: boolean;
27
+ sourceLabel?: string;
28
+ targetLabel?: string;
29
+ }
30
+
31
+ interface RestorePreviewResponse {
32
+ plan: RestorePreviewPlan;
33
+ confirm_token: string;
34
+ }
35
+
36
+ interface RestoreExecuteResponse {
37
+ operation_id: string;
38
+ }
39
+
40
+ interface Operation {
41
+ id: string;
42
+ type?: string;
43
+ status?: string;
44
+ current_step?: string;
45
+ verify?: unknown;
46
+ error?: string;
47
+ backup_snapshot_id?: string;
48
+ step_log?: string[];
49
+ }
50
+
51
+ interface OperationResponse {
52
+ operation: Operation;
53
+ }
54
+
55
+ function fmtBytes(bytes?: number): string {
56
+ if (bytes == null) return '-';
57
+ if (bytes < 1024) return `${bytes}B`;
58
+ if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)}KB`;
59
+ if (bytes < 1024 * 1024 * 1024) return `${(bytes / (1024 * 1024)).toFixed(1)}MB`;
60
+ return `${(bytes / (1024 * 1024 * 1024)).toFixed(2)}GB`;
61
+ }
62
+
63
+ export function registerWordPressSnapshotTools(server: McpServer) {
64
+ server.tool(
65
+ 'dailey_wp_snapshots',
66
+ 'List WordPress snapshots for a project',
67
+ {
68
+ project_id: z.string().describe('The project ID'),
69
+ },
70
+ async ({ project_id }) => {
71
+ const res = await apiRequest<SnapshotsResponse>('GET', `/projects/${project_id}/wp/snapshots`);
72
+ if (!res.ok) return textResult(formatError(res));
73
+
74
+ const snapshots = res.data.snapshots;
75
+ if (!snapshots || snapshots.length === 0) {
76
+ return textResult('No snapshots found for this project.');
77
+ }
78
+
79
+ const lines = [
80
+ `Snapshots for project ${project_id}`,
81
+ `${'ID'.padEnd(38)} ${'Created'.padEnd(26)} ${'Kind'.padEnd(12)} ${'Status'.padEnd(12)} ${'DB'.padEnd(10)} Uploads`,
82
+ '─'.repeat(115),
83
+ ];
84
+
85
+ for (const s of snapshots) {
86
+ lines.push(
87
+ `${(s.id || '').padEnd(38)} ${(s.created_at || '-').padEnd(26)} ${(s.kind || '-').padEnd(12)} ${(s.status || '-').padEnd(12)} ${fmtBytes(s.db_bytes).padEnd(10)} ${fmtBytes(s.uploads_bytes)}`,
88
+ );
89
+ }
90
+
91
+ return textResult(lines.join('\n'));
92
+ },
93
+ );
94
+
95
+ server.tool(
96
+ 'dailey_wp_snapshot',
97
+ 'Create a snapshot (DB + uploads) of a WordPress project',
98
+ {
99
+ project_id: z.string().describe('The project ID'),
100
+ },
101
+ async ({ project_id }) => {
102
+ const res = await apiRequest<SnapshotStartResponse>('POST', `/projects/${project_id}/wp/snapshot`);
103
+ if (!res.ok) return textResult(formatError(res));
104
+
105
+ const { operation_id } = res.data;
106
+ return textResult(
107
+ `Snapshot started. operation_id=${operation_id}. Poll with dailey_wp_operation_status (project_id, operation_id).`,
108
+ );
109
+ },
110
+ );
111
+
112
+ server.tool(
113
+ 'dailey_wp_restore',
114
+ 'Restore a WordPress project from a snapshot (DESTRUCTIVE — two-phase). Call WITHOUT confirm_token to get the plan; re-call WITH the returned confirm_token to execute.',
115
+ {
116
+ project_id: z.string().describe('The project ID'),
117
+ snapshot_id: z.string().describe('The snapshot ID to restore'),
118
+ confirm_token: z.string().optional().describe(
119
+ 'Token from the plan response. Omit to preview the plan; provide to execute. Bound to this project+snapshot, ~10min TTL.',
120
+ ),
121
+ },
122
+ async ({ project_id, snapshot_id, confirm_token }) => {
123
+ if (!confirm_token) {
124
+ // Phase 1: preview
125
+ const res = await apiRequest<RestorePreviewResponse>(
126
+ 'POST',
127
+ `/projects/${project_id}/wp/restore/preview`,
128
+ { snapshot_id },
129
+ );
130
+ if (!res.ok) return textResult(formatError(res));
131
+
132
+ const { plan, confirm_token: token } = res.data;
133
+ const lines: string[] = [];
134
+
135
+ if (plan.sourceLabel || plan.targetLabel) {
136
+ lines.push(`Restore plan: ${plan.sourceLabel ?? snapshot_id} → ${plan.targetLabel ?? 'this project'}`);
137
+ } else {
138
+ lines.push(`Restore plan for snapshot ${snapshot_id}:`);
139
+ }
140
+
141
+ if (plan.backupFirst) {
142
+ lines.push('• Backs up the target first as a rollback point.');
143
+ }
144
+
145
+ if (plan.steps && plan.steps.length > 0) {
146
+ lines.push('');
147
+ lines.push('Steps:');
148
+ plan.steps.forEach((step, i) => {
149
+ lines.push(` ${i + 1}. ${step}`);
150
+ });
151
+ }
152
+
153
+ lines.push('');
154
+ lines.push(`confirm_token: ${token}`);
155
+ lines.push('');
156
+ lines.push(
157
+ 'This is destructive. To proceed, re-call dailey_wp_restore with the same project_id + snapshot_id and this confirm_token.',
158
+ );
159
+
160
+ return textResult(lines.join('\n'));
161
+ }
162
+
163
+ // Phase 2: execute
164
+ const res = await apiRequest<RestoreExecuteResponse>(
165
+ 'POST',
166
+ `/projects/${project_id}/wp/restore`,
167
+ { snapshot_id, confirm_token, confirmation: 'RESTORE' },
168
+ );
169
+
170
+ if (!res.ok) {
171
+ if (res.status === 409) {
172
+ return textResult('A restore is already in progress for this project.');
173
+ }
174
+ // 400 (expired/invalid token) — surface the message
175
+ return textResult(formatError(res));
176
+ }
177
+
178
+ const { operation_id } = res.data;
179
+ return textResult(
180
+ `Restore started. operation_id=${operation_id}. Poll with dailey_wp_operation_status.`,
181
+ );
182
+ },
183
+ );
184
+
185
+ server.tool(
186
+ 'dailey_wp_operation_status',
187
+ 'Check the status of a WordPress snapshot/restore operation',
188
+ {
189
+ project_id: z.string().describe('The project ID'),
190
+ operation_id: z.string().describe('The operation ID'),
191
+ },
192
+ async ({ project_id, operation_id }) => {
193
+ const res = await apiRequest<OperationResponse>(
194
+ 'GET',
195
+ `/projects/${project_id}/wp/operations/${operation_id}`,
196
+ );
197
+ if (!res.ok) return textResult(formatError(res));
198
+
199
+ const op = res.data.operation;
200
+ const lines: string[] = [];
201
+
202
+ if (op.type) lines.push(`Type: ${op.type}`);
203
+ lines.push(`Status: ${op.status ?? '-'}`);
204
+ if (op.current_step) lines.push(`Current step: ${op.current_step}`);
205
+ if (op.verify != null) lines.push(`Verify: ${JSON.stringify(op.verify)}`);
206
+ if (op.error) lines.push(`Error: ${op.error}`);
207
+ if (op.backup_snapshot_id) lines.push(`Backup snapshot ID: ${op.backup_snapshot_id}`);
208
+
209
+ if (op.step_log && op.step_log.length > 0) {
210
+ const tail = op.step_log.slice(-10);
211
+ lines.push('');
212
+ lines.push('Step log (last 10):');
213
+ for (const entry of tail) {
214
+ lines.push(` ${entry}`);
215
+ }
216
+ }
217
+
218
+ return textResult(lines.join('\n'));
219
+ },
220
+ );
221
+ }
@@ -0,0 +1,156 @@
1
+ /**
2
+ * Dailey Images (AI generation) MCP tools — two-layer test.
3
+ *
4
+ * Layer 1 (protocol smoke): spawns dist/index.js, does the MCP handshake,
5
+ * calls tools/list, and asserts dailey_images_generate / dailey_images_enable /
6
+ * dailey_images_info appear with correct input schemas. No credentials needed.
7
+ *
8
+ * Layer 2 (in-process registration checks): imports the compiled module,
9
+ * stubs McpServer.tool(), and verifies names, schemas, and descriptions.
10
+ *
11
+ * Run:
12
+ * node --test tests/dailey-images.test.mjs
13
+ */
14
+
15
+ import { test, describe } from 'node:test';
16
+ import assert from 'node:assert/strict';
17
+ import { spawn } from 'node:child_process';
18
+ import { join, dirname } from 'node:path';
19
+ import { fileURLToPath } from 'node:url';
20
+
21
+ const __dirname = dirname(fileURLToPath(import.meta.url));
22
+ const BINARY = join(__dirname, '..', 'dist', 'index.js');
23
+
24
+ // ── Layer 1: protocol smoke (tools/list) ───────────────────────────────────
25
+
26
+ describe('dailey images MCP tools — protocol smoke', { concurrency: false }, () => {
27
+ test('generate/enable/info appear in tools/list with input schemas', async () => {
28
+ const child = spawn('node', [BINARY], {
29
+ env: {
30
+ ...process.env,
31
+ DAILEY_EMAIL: process.env.DAILEY_EMAIL || 'smoke@example.com',
32
+ DAILEY_PASSWORD: process.env.DAILEY_PASSWORD || 'smoke-password',
33
+ DAILEY_API_TOKEN: process.env.DAILEY_API_TOKEN || '',
34
+ DAILEY_API_URL: process.env.DAILEY_API_URL || 'https://os.dailey.cloud/api',
35
+ },
36
+ stdio: ['pipe', 'pipe', 'pipe'],
37
+ });
38
+
39
+ let buffer = '';
40
+ let nextId = 1;
41
+ const pending = new Map();
42
+
43
+ child.stdout.on('data', (chunk) => {
44
+ buffer += chunk.toString();
45
+ const lines = buffer.split('\n');
46
+ buffer = lines.pop();
47
+ for (const line of lines) {
48
+ if (!line.trim()) continue;
49
+ try {
50
+ const msg = JSON.parse(line);
51
+ if (msg.id != null && pending.has(msg.id)) {
52
+ const { resolve } = pending.get(msg.id);
53
+ pending.delete(msg.id);
54
+ resolve(msg);
55
+ }
56
+ } catch { /* ignore non-JSON lines */ }
57
+ }
58
+ });
59
+
60
+ child.stderr.on('data', (_chunk) => { /* suppress */ });
61
+
62
+ function send(method, params, timeoutMs = 10000) {
63
+ return new Promise((resolve, reject) => {
64
+ const id = nextId++;
65
+ const timer = setTimeout(() => {
66
+ if (pending.has(id)) {
67
+ pending.delete(id);
68
+ reject(new Error(`Timeout waiting for ${method}`));
69
+ }
70
+ }, timeoutMs);
71
+ pending.set(id, {
72
+ resolve: (v) => { clearTimeout(timer); resolve(v); },
73
+ reject,
74
+ });
75
+ child.stdin.write(JSON.stringify({ jsonrpc: '2.0', id, method, params }) + '\n');
76
+ });
77
+ }
78
+
79
+ try {
80
+ await send('initialize', {
81
+ protocolVersion: '2024-11-05',
82
+ capabilities: {},
83
+ clientInfo: { name: 'dailey-images-smoke', version: '1.0.0' },
84
+ });
85
+ child.stdin.write(JSON.stringify({ jsonrpc: '2.0', method: 'notifications/initialized' }) + '\n');
86
+
87
+ const toolsMsg = await send('tools/list', {});
88
+ const tools = toolsMsg.result?.tools ?? [];
89
+ const toolMap = Object.fromEntries(tools.map((t) => [t.name, t]));
90
+
91
+ for (const name of ['dailey_images_generate', 'dailey_images_enable', 'dailey_images_info']) {
92
+ assert.ok(toolMap[name], `Expected tool "${name}" in tools/list`);
93
+ assert.ok(toolMap[name].inputSchema?.properties, `${name} must have inputSchema.properties`);
94
+ assert.ok('project' in toolMap[name].inputSchema.properties, `${name} must have project param`);
95
+ }
96
+
97
+ // generate: prompt required; model enum; n optional
98
+ const gen = toolMap['dailey_images_generate'];
99
+ assert.ok('prompt' in gen.inputSchema.properties, 'generate must have prompt param');
100
+ assert.ok('model' in gen.inputSchema.properties, 'generate must have model param');
101
+ assert.ok('n' in gen.inputSchema.properties, 'generate must have n param');
102
+ const genRequired = gen.inputSchema.required ?? [];
103
+ assert.ok(genRequired.includes('project'), 'project must be required');
104
+ assert.ok(genRequired.includes('prompt'), 'prompt must be required');
105
+ assert.ok(!genRequired.includes('model'), 'model must be optional');
106
+ assert.ok(!genRequired.includes('n'), 'n must be optional');
107
+ // model is an enum with the two tiers
108
+ const modelEnum = gen.inputSchema.properties.model.enum;
109
+ assert.deepEqual(modelEnum, ['dailey-fast', 'dailey-pro'], 'model enum must be the two tiers');
110
+ } finally {
111
+ child.kill();
112
+ }
113
+ });
114
+ });
115
+
116
+ // ── Layer 2: in-process registration checks ────────────────────────────────
117
+
118
+ describe('dailey images tools — registration', { concurrency: false }, () => {
119
+ test('registers all three tools with the right shapes', async () => {
120
+ const registrations = [];
121
+ const stubServer = {
122
+ tool(name, description, schema, handler) {
123
+ registrations.push({ name, description, schema, handler });
124
+ },
125
+ };
126
+
127
+ const mod = await import(join(__dirname, '..', 'dist', 'tools', 'dailey-images.js'));
128
+ mod.registerDaileyImagesTools(stubServer);
129
+
130
+ const byName = Object.fromEntries(registrations.map((r) => [r.name, r]));
131
+
132
+ const gen = byName['dailey_images_generate'];
133
+ assert.ok(gen, 'dailey_images_generate must be registered');
134
+ assert.ok(typeof gen.handler === 'function', 'generate handler must be a function');
135
+ assert.ok(gen.schema?.project && gen.schema?.prompt, 'generate must have project + prompt');
136
+ // metered cost is called out in the description
137
+ assert.match(gen.description, /2¢/, 'generate description must mention 2¢ (fast)');
138
+ assert.match(gen.description, /10¢/, 'generate description must mention 10¢ (pro)');
139
+ assert.match(gen.description, /prepaid credits/i, 'generate description must mention prepaid credits');
140
+ // prompt required, model optional
141
+ const promptOptional = gen.schema.prompt?._def?.typeName === 'ZodOptional'
142
+ || (typeof gen.schema.prompt?.isOptional === 'function' && gen.schema.prompt.isOptional());
143
+ assert.ok(!promptOptional, 'prompt must NOT be optional');
144
+ const modelOptional = gen.schema.model?._def?.typeName === 'ZodOptional'
145
+ || (typeof gen.schema.model?.isOptional === 'function' && gen.schema.model.isOptional());
146
+ assert.ok(modelOptional, 'model must be optional');
147
+
148
+ const enable = byName['dailey_images_enable'];
149
+ assert.ok(enable, 'dailey_images_enable must be registered');
150
+ assert.ok(enable.schema?.project, 'enable must have project param');
151
+
152
+ const info = byName['dailey_images_info'];
153
+ assert.ok(info, 'dailey_images_info must be registered');
154
+ assert.ok(info.schema?.project, 'info must have project param');
155
+ });
156
+ });