@daileyos/mcp-server 1.21.2 → 1.21.4

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 (163) hide show
  1. package/dist/api.d.ts +7 -0
  2. package/dist/api.d.ts.map +1 -1
  3. package/dist/api.js +23 -2
  4. package/dist/api.js.map +1 -1
  5. package/dist/index.js +24 -17
  6. package/dist/index.js.map +1 -1
  7. package/dist/tools/accounts.js +1 -1
  8. package/dist/tools/accounts.js.map +1 -1
  9. package/dist/tools/ai.d.ts.map +1 -1
  10. package/dist/tools/ai.js +7 -1
  11. package/dist/tools/ai.js.map +1 -1
  12. package/dist/tools/auth.d.ts.map +1 -1
  13. package/dist/tools/auth.js +25 -6
  14. package/dist/tools/auth.js.map +1 -1
  15. package/dist/tools/backups.d.ts.map +1 -1
  16. package/dist/tools/backups.js +3 -1
  17. package/dist/tools/backups.js.map +1 -1
  18. package/dist/tools/build-logs.d.ts.map +1 -1
  19. package/dist/tools/build-logs.js +3 -1
  20. package/dist/tools/build-logs.js.map +1 -1
  21. package/dist/tools/credentials-reveal.d.ts.map +1 -1
  22. package/dist/tools/credentials-reveal.js +3 -1
  23. package/dist/tools/credentials-reveal.js.map +1 -1
  24. package/dist/tools/dailey-images.js +3 -3
  25. package/dist/tools/dailey-images.js.map +1 -1
  26. package/dist/tools/db-migrate.js +5 -5
  27. package/dist/tools/db-migrate.js.map +1 -1
  28. package/dist/tools/db.d.ts.map +1 -1
  29. package/dist/tools/db.js +17 -1
  30. package/dist/tools/db.js.map +1 -1
  31. package/dist/tools/deploy-status.d.ts.map +1 -1
  32. package/dist/tools/deploy-status.js +3 -1
  33. package/dist/tools/deploy-status.js.map +1 -1
  34. package/dist/tools/deploy.d.ts.map +1 -1
  35. package/dist/tools/deploy.js +9 -1
  36. package/dist/tools/deploy.js.map +1 -1
  37. package/dist/tools/domains.d.ts.map +1 -1
  38. package/dist/tools/domains.js +3 -1
  39. package/dist/tools/domains.js.map +1 -1
  40. package/dist/tools/email.d.ts.map +1 -1
  41. package/dist/tools/email.js +7 -1
  42. package/dist/tools/email.js.map +1 -1
  43. package/dist/tools/env.d.ts.map +1 -1
  44. package/dist/tools/env.js +5 -1
  45. package/dist/tools/env.js.map +1 -1
  46. package/dist/tools/environments.js +3 -3
  47. package/dist/tools/environments.js.map +1 -1
  48. package/dist/tools/exec-run.d.ts.map +1 -1
  49. package/dist/tools/exec-run.js +7 -1
  50. package/dist/tools/exec-run.js.map +1 -1
  51. package/dist/tools/images.d.ts.map +1 -1
  52. package/dist/tools/images.js +5 -1
  53. package/dist/tools/images.js.map +1 -1
  54. package/dist/tools/lifecycle.d.ts.map +1 -1
  55. package/dist/tools/lifecycle.js +5 -1
  56. package/dist/tools/lifecycle.js.map +1 -1
  57. package/dist/tools/links.d.ts.map +1 -1
  58. package/dist/tools/links.js +3 -1
  59. package/dist/tools/links.js.map +1 -1
  60. package/dist/tools/platform.d.ts.map +1 -1
  61. package/dist/tools/platform.js +3 -1
  62. package/dist/tools/platform.js.map +1 -1
  63. package/dist/tools/processes.d.ts.map +1 -1
  64. package/dist/tools/processes.js +11 -1
  65. package/dist/tools/processes.js.map +1 -1
  66. package/dist/tools/projects.d.ts.map +1 -1
  67. package/dist/tools/projects.js +36 -12
  68. package/dist/tools/projects.js.map +1 -1
  69. package/dist/tools/resource-config.d.ts.map +1 -1
  70. package/dist/tools/resource-config.js +3 -1
  71. package/dist/tools/resource-config.js.map +1 -1
  72. package/dist/tools/scale.d.ts.map +1 -1
  73. package/dist/tools/scale.js +3 -1
  74. package/dist/tools/scale.js.map +1 -1
  75. package/dist/tools/storage.d.ts.map +1 -1
  76. package/dist/tools/storage.js +11 -1
  77. package/dist/tools/storage.js.map +1 -1
  78. package/dist/tools/support.d.ts.map +1 -1
  79. package/dist/tools/support.js +3 -1
  80. package/dist/tools/support.js.map +1 -1
  81. package/dist/tools/usage.d.ts.map +1 -1
  82. package/dist/tools/usage.js +3 -1
  83. package/dist/tools/usage.js.map +1 -1
  84. package/dist/tools/wordpress-import.d.ts.map +1 -1
  85. package/dist/tools/wordpress-import.js +3 -1
  86. package/dist/tools/wordpress-import.js.map +1 -1
  87. package/dist/tools/wordpress-migrate.d.ts.map +1 -1
  88. package/dist/tools/wordpress-migrate.js +3 -1
  89. package/dist/tools/wordpress-migrate.js.map +1 -1
  90. package/dist/tools/wordpress-snapshot.d.ts.map +1 -1
  91. package/dist/tools/wordpress-snapshot.js +9 -1
  92. package/dist/tools/wordpress-snapshot.js.map +1 -1
  93. package/package.json +4 -1
  94. package/.dockerignore +0 -6
  95. package/.github/workflows/publish.yml +0 -120
  96. package/Dockerfile +0 -19
  97. package/claude-config.json +0 -13
  98. package/docs/superpowers/plans/2026-08-09-remote-mcp-endpoint.md +0 -663
  99. package/docs/superpowers/specs/2026-08-09-remote-mcp-endpoint-design.md +0 -66
  100. package/src/api.ts +0 -263
  101. package/src/context.ts +0 -12
  102. package/src/http.ts +0 -160
  103. package/src/index.ts +0 -94
  104. package/src/server.ts +0 -188
  105. package/src/tools/accounts.ts +0 -119
  106. package/src/tools/addons.ts +0 -124
  107. package/src/tools/admin.ts +0 -42
  108. package/src/tools/ai.ts +0 -83
  109. package/src/tools/analyze.ts +0 -108
  110. package/src/tools/auth.ts +0 -177
  111. package/src/tools/backups.ts +0 -84
  112. package/src/tools/billing.ts +0 -34
  113. package/src/tools/build-logs.ts +0 -65
  114. package/src/tools/bundle.ts +0 -129
  115. package/src/tools/cli.ts +0 -76
  116. package/src/tools/credentials-reveal.ts +0 -64
  117. package/src/tools/credits.ts +0 -97
  118. package/src/tools/dailey-images.ts +0 -151
  119. package/src/tools/db-migrate.ts +0 -211
  120. package/src/tools/db.ts +0 -391
  121. package/src/tools/deploy-status.ts +0 -247
  122. package/src/tools/deploy.ts +0 -101
  123. package/src/tools/diagnose.ts +0 -567
  124. package/src/tools/domains.ts +0 -156
  125. package/src/tools/email.ts +0 -101
  126. package/src/tools/env.ts +0 -205
  127. package/src/tools/environments.ts +0 -138
  128. package/src/tools/exec-run.ts +0 -91
  129. package/src/tools/images.ts +0 -221
  130. package/src/tools/lifecycle.ts +0 -75
  131. package/src/tools/links.ts +0 -69
  132. package/src/tools/platform.ts +0 -209
  133. package/src/tools/processes.ts +0 -182
  134. package/src/tools/project-transfer.ts +0 -129
  135. package/src/tools/projects.ts +0 -287
  136. package/src/tools/resource-config.ts +0 -84
  137. package/src/tools/scale.ts +0 -33
  138. package/src/tools/storage.ts +0 -281
  139. package/src/tools/support.ts +0 -42
  140. package/src/tools/usage.ts +0 -128
  141. package/src/tools/wordpress-import.ts +0 -174
  142. package/src/tools/wordpress-live-edit.ts +0 -250
  143. package/src/tools/wordpress-migrate.ts +0 -104
  144. package/src/tools/wordpress-snapshot.ts +0 -225
  145. package/src/tools/wordpress-targeting.ts +0 -188
  146. package/src/upload.ts +0 -35
  147. package/src/version.ts +0 -70
  148. package/test/context.test.ts +0 -36
  149. package/test/http.test.ts +0 -103
  150. package/test/server-surface.test.ts +0 -36
  151. package/test/use-account-sticky.test.ts +0 -28
  152. package/test/wordpress-import.test.ts +0 -223
  153. package/test/wordpress-live-edit.test.ts +0 -159
  154. package/test/wordpress-targeting.test.ts +0 -162
  155. package/tests/dailey-images.test.mjs +0 -156
  156. package/tests/environments.test.mjs +0 -230
  157. package/tests/mcp-protocol-smoke.mjs +0 -149
  158. package/tests/new-tools-smoke.mjs +0 -217
  159. package/tests/pack1-mcp-preflight.test.mjs +0 -184
  160. package/tests/pack6-smoke.mjs +0 -222
  161. package/tests/wp-snapshot-labels.test.mjs +0 -21
  162. package/tests/wp-snapshot.test.mjs +0 -261
  163. package/tsconfig.json +0 -19
package/src/tools/db.ts DELETED
@@ -1,391 +0,0 @@
1
- import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
- import { z } from 'zod';
3
- import { apiRequest, formatError, textResult } from '../api.js';
4
-
5
- interface DatabaseInfo {
6
- host?: string;
7
- port?: number;
8
- database?: string;
9
- username?: string;
10
- password?: string;
11
- status?: string;
12
- size_mb?: number;
13
- type?: string;
14
- }
15
-
16
- interface DatabaseSchemaResponse {
17
- database: string;
18
- tables: Array<{
19
- name: string;
20
- rows: number;
21
- size_kb: number;
22
- columns: Array<{
23
- name: string;
24
- type: string;
25
- nullable: boolean;
26
- key: string;
27
- extra: string;
28
- }>;
29
- }>;
30
- total_rows: number;
31
- total_size_kb: number;
32
- }
33
-
34
- interface DatabaseQueryResponse {
35
- rows?: Array<Record<string, unknown>>;
36
- row_count?: number;
37
- duration_ms?: number;
38
- read_only?: boolean;
39
- auto_limited?: boolean;
40
- error?: string;
41
- }
42
-
43
- interface DatabaseMigrationsResponse {
44
- has_migration_table: boolean;
45
- total_applied: number;
46
- applied: Array<{ name: string; applied_at?: string }>;
47
- }
48
-
49
- export function registerDbTools(server: McpServer) {
50
- server.tool(
51
- 'dailey_db_info',
52
- 'Get database connection info for a project',
53
- { project_id: z.string().describe('The project ID') },
54
- async ({ project_id }) => {
55
- const res = await apiRequest<DatabaseInfo>('GET', `/projects/${project_id}/database`);
56
- if (!res.ok) return textResult(formatError(res));
57
-
58
- const db = res.data;
59
- const lines = [
60
- `Database Info`,
61
- '─────────────────────────────',
62
- `Type: ${db.type || 'unknown'}`,
63
- `Status: ${db.status || 'unknown'}`,
64
- `Host: ${db.host || '-'}`,
65
- `Port: ${db.port || '-'}`,
66
- `Database: ${db.database || '-'}`,
67
- `Username: ${db.username || '-'}`,
68
- `Password: [use dailey_db_tunnel to connect — password not returned here to avoid chat-log exposure]`,
69
- ];
70
- if (db.size_mb !== undefined) {
71
- lines.push(`Size: ${db.size_mb} MB`);
72
- }
73
- return textResult(lines.join('\n'));
74
- },
75
- );
76
-
77
- server.tool(
78
- 'dailey_db_schema',
79
- 'Inspect the schema of a project database',
80
- { project_id: z.string().describe('The project ID') },
81
- async ({ project_id }) => {
82
- const res = await apiRequest<DatabaseSchemaResponse>('GET', `/projects/${project_id}/database/schema`);
83
- if (!res.ok) return textResult(formatError(res));
84
-
85
- const schema = res.data;
86
- const lines = [
87
- `Schema: ${schema.database}`,
88
- `Tables: ${schema.tables?.length || 0}`,
89
- `Rows: ${schema.total_rows || 0}`,
90
- `Size: ${schema.total_size_kb || 0} KB`,
91
- '',
92
- ];
93
-
94
- for (const table of schema.tables || []) {
95
- lines.push(`${table.name} (${table.rows} rows, ${table.size_kb} KB)`);
96
- for (const column of table.columns || []) {
97
- const flags = [
98
- column.key ? `key=${column.key}` : null,
99
- column.nullable ? 'nullable' : 'required',
100
- column.extra || null,
101
- ].filter(Boolean);
102
- lines.push(` - ${column.name}: ${column.type}${flags.length ? ` [${flags.join(', ')}]` : ''}`);
103
- }
104
- lines.push('');
105
- }
106
-
107
- return textResult(lines.join('\n').trimEnd());
108
- },
109
- );
110
-
111
- server.tool(
112
- 'dailey_db_recall',
113
- 'Recall records with a safe read-only SQL query (SELECT / SHOW / DESCRIBE / EXPLAIN / WITH). Mutating SQL (INSERT / UPDATE / DELETE / DDL) is rejected by the server. For writes, use the `dailey db import` CLI command — invoke `dailey_cli_suggest_import` to construct it. For ad-hoc DBA work, use `dailey db connect`.',
114
- {
115
- project_id: z.string().describe('The project ID'),
116
- sql: z.string().describe('A read-only SQL query such as SELECT, SHOW, or DESCRIBE'),
117
- limit: z.number().int().min(1).max(1000).optional().describe('Auto-limit for SELECT/WITH queries without LIMIT'),
118
- },
119
- async ({ project_id, sql, limit }) => {
120
- const body: Record<string, unknown> = { sql };
121
- if (limit !== undefined) body.limit = limit;
122
- const res = await apiRequest<DatabaseQueryResponse>('POST', `/projects/${project_id}/database/recall`, body);
123
- if (!res.ok) return textResult(formatError(res));
124
- if (res.data.error) return textResult(`Error: ${res.data.error}`);
125
-
126
- const rows = res.data.rows || [];
127
- const lines = [
128
- `Read-only recall`,
129
- `Rows: ${res.data.row_count || 0}`,
130
- `Duration: ${res.data.duration_ms || 0}ms`,
131
- `Mode: ${res.data.read_only ? 'read-only' : 'unknown'}`,
132
- `AutoLimit: ${res.data.auto_limited ? 'yes' : 'no'}`,
133
- '',
134
- ];
135
-
136
- if (rows.length === 0) {
137
- lines.push('No rows returned.');
138
- } else {
139
- lines.push(JSON.stringify(rows, null, 2));
140
- }
141
-
142
- return textResult(lines.join('\n'));
143
- },
144
- );
145
-
146
- server.tool(
147
- 'dailey_db_validate',
148
- 'Validate a SQL migration BEFORE deploying it. Catches security issues (SQL injection vectors, privilege escalation, system catalog access) and semantic issues (CREATE TABLE without IF NOT EXISTS when table exists, ALTER ADD COLUMN when column already exists).',
149
- {
150
- project_id: z.string().describe('The project ID'),
151
- sql: z.string().describe('SQL migration to validate (can contain multiple statements separated by ;)'),
152
- },
153
- async ({ project_id, sql }) => {
154
- const res = await apiRequest<any>('POST', `/projects/${project_id}/database/validate`, { sql });
155
- if (!res.ok) return textResult(formatError(res));
156
-
157
- const d = res.data;
158
- const lines = [
159
- `Migration validation`,
160
- '─'.repeat(40),
161
- `Valid: ${d.valid ? '✓' : '✗'}`,
162
- `Warnings: ${d.has_warnings ? 'yes' : 'no'}`,
163
- `Summary: ${d.summary || '-'}`,
164
- ];
165
-
166
- if (d.statements?.length) {
167
- lines.push('');
168
- lines.push('Statements:');
169
- for (const s of d.statements) {
170
- const marker = s.valid ? (s.warning ? '⚠' : '✓') : '✗';
171
- lines.push(` ${marker} ${s.sql}${s.sql.length >= 80 ? '...' : ''}`);
172
- if (s.error) lines.push(` error: ${s.error}`);
173
- if (s.warning) lines.push(` warn: ${s.warning}`);
174
- if (s.info) lines.push(` info: ${s.info}`);
175
- }
176
- }
177
-
178
- if (d.errors?.length) {
179
- lines.push('');
180
- lines.push('Errors:');
181
- for (const e of d.errors) lines.push(` ✗ ${e}`);
182
- }
183
-
184
- if (d.warnings?.length) {
185
- lines.push('');
186
- lines.push('Warnings:');
187
- for (const w of d.warnings) lines.push(` ⚠ ${w}`);
188
- }
189
-
190
- return textResult(lines.join('\n'));
191
- },
192
- );
193
-
194
- server.tool(
195
- 'dailey_db_tunnel',
196
- 'Open, close, or list short-lived database tunnel sessions. Sessions auto-expire after 1 hour. NOTE: This MCP tool opens a raw API session and returns a Tailscale CGNAT host (100.x.x.x) — connecting to it directly from MCP requires the client to be on the Dailey Tailnet. For connecting GUI tools or running psql/pg_restore/mysqldump IMPORTS without Tailscale, tell the user to use `dailey db connect <project>` from the CLI instead — it proxies through a WebSocket and binds a local port (127.0.0.1:15432 for postgres, 127.0.0.1:13306 for mysql) that any client can reach. The CLI tunnel output includes ready-to-paste import commands for both psql and pg_restore. Use this MCP tool only for session management (list / close).',
197
- {
198
- project_id: z.string().describe('The project ID'),
199
- action: z.enum(['open', 'close', 'list']).describe('open | close | list'),
200
- session_id: z.string().optional().describe('Session ID to close (required for close)'),
201
- },
202
- async ({ project_id, action, session_id }) => {
203
- if (action === 'open') {
204
- const res = await apiRequest<any>('POST', `/projects/${project_id}/database/tunnel`);
205
- if (!res.ok) return textResult(formatError(res));
206
- const d = res.data;
207
- const isTailnetHost = typeof d.host === 'string' && /^100\./.test(d.host);
208
- const lines = [
209
- `Database tunnel opened`,
210
- '─'.repeat(40),
211
- `Session ID: ${d.session_id}`,
212
- `Engine: ${d.engine}`,
213
- `Host: ${d.host}:${d.port}`,
214
- `Database: ${d.database}`,
215
- `Username: ${d.username}`,
216
- `Password: ${d.password}`,
217
- `Expires at: ${d.expires_at} (${d.ttl_seconds}s)`,
218
- '',
219
- `${d.message}`,
220
- ];
221
- if (isTailnetHost) {
222
- lines.push('');
223
- lines.push('⚠ PREFLIGHT — Tailnet required:');
224
- lines.push(` The host ${d.host} is a Tailscale CGNAT address. Verify your client is on`);
225
- lines.push(` the Dailey Tailnet before connecting, otherwise your client will hang on`);
226
- lines.push(` connect. Quick check from the client: "tailscale status" should list`);
227
- lines.push(` an active node, and "ping ${d.host}" should respond.`);
228
- lines.push('');
229
- lines.push(' If the client can NOT be put on the Tailnet, use `dailey db import` for');
230
- lines.push(' bulk data loads (JSON/CSV) or `dailey db recall` for read-only SELECTs —');
231
- lines.push(' both route through the public API and do not require Tailscale.');
232
- }
233
- lines.push('');
234
- lines.push(`Close with: dailey_db_tunnel action=close session_id=${d.session_id}`);
235
- return textResult(lines.join('\n'));
236
- }
237
-
238
- if (action === 'close') {
239
- if (!session_id) return textResult('Error: session_id is required to close.');
240
- const res = await apiRequest(
241
- 'DELETE',
242
- `/projects/${project_id}/database/tunnel/${encodeURIComponent(session_id)}`,
243
- );
244
- if (!res.ok) return textResult(formatError(res));
245
- return textResult(`Tunnel session ${session_id} closed.`);
246
- }
247
-
248
- if (action === 'list') {
249
- const res = await apiRequest<{ sessions: any[] }>('GET', `/projects/${project_id}/database/tunnel`);
250
- if (!res.ok) return textResult(formatError(res));
251
- const sessions = res.data.sessions || [];
252
- if (sessions.length === 0) return textResult('No active tunnel sessions.');
253
- const lines = [`Active tunnel sessions (${sessions.length})`, '─'.repeat(40)];
254
- for (const s of sessions) {
255
- lines.push(`• ${s.sessionId} engine=${s.engine} expires=${new Date(s.expiresAt).toISOString()}`);
256
- }
257
- return textResult(lines.join('\n'));
258
- }
259
-
260
- return textResult('Invalid action. Use open, close, or list.');
261
- },
262
- );
263
-
264
- server.tool(
265
- 'dailey_db_migrations',
266
- 'Show migration status for a project database',
267
- { project_id: z.string().describe('The project ID') },
268
- async ({ project_id }) => {
269
- const res = await apiRequest<DatabaseMigrationsResponse>('GET', `/projects/${project_id}/database/migrations`);
270
- if (!res.ok) return textResult(formatError(res));
271
-
272
- if (!res.data.has_migration_table) {
273
- return textResult('No _migrations table found for this project.');
274
- }
275
-
276
- const lines = [
277
- `Migrations`,
278
- `Applied: ${res.data.total_applied}`,
279
- '',
280
- ];
281
- for (const migration of res.data.applied || []) {
282
- lines.push(`- ${migration.name}${migration.applied_at ? ` (${migration.applied_at})` : ''}`);
283
- }
284
- return textResult(lines.join('\n'));
285
- },
286
- );
287
-
288
- server.tool(
289
- 'dailey_db_import',
290
- 'Bulk-insert or upsert rows into a project table. Two-phase commit: call first with dry_run=true to validate + get a confirm_token + row counts; call again with confirm_token to commit. For JSON, pass an array of row objects as a JSON string in `payload`. For CSV, pass the raw CSV text with a header row. `mode=upsert` requires `conflict_keys`. The dry_run phase parses, validates types, counts insert/update/error rows, and returns a short-lived token without writing anything.',
291
- {
292
- project_id: z.string().describe('The project ID'),
293
- table: z.string().describe('Target table name in the project database'),
294
- mode: z.enum(['insert', 'upsert']).describe('insert = fail on duplicate key; upsert = update on conflict'),
295
- format: z.enum(['json', 'csv']).describe('Payload format'),
296
- payload: z.string().describe('Inline data. JSON: stringified array of row objects, e.g. `[{"email":"a@b.com","name":"A"}]`. CSV: raw CSV text with a header row on line 1.'),
297
- conflict_keys: z.array(z.string()).optional().describe('Required for upsert — columns that identify a row for conflict (e.g. ["email"] or composite ["tenant_id","external_id"])'),
298
- dry_run: z.boolean().optional().describe('Set true on the first call to validate without writing. Response includes confirm_token to pass to the second call.'),
299
- confirm_token: z.string().optional().describe('Token from a prior dry_run response. Required on the commit call. Single-use.'),
300
- allow_extra_columns: z.boolean().optional().describe('If true, payload columns not present in the table schema are silently dropped. Default false.'),
301
- batch_size: z.number().int().optional().describe('Rows per write batch (default 500)'),
302
- },
303
- async ({ project_id, table, mode, format, payload, conflict_keys, dry_run, confirm_token, allow_extra_columns, batch_size }) => {
304
- if (!dry_run && !confirm_token) {
305
- return textResult('Must pass either dry_run=true (validate) or confirm_token (commit). Two-phase commit is required.');
306
- }
307
- if (mode === 'upsert' && (!conflict_keys || conflict_keys.length === 0)) {
308
- return textResult('mode=upsert requires conflict_keys, e.g. ["email"].');
309
- }
310
- const body: any = { table, mode, format, payload };
311
- if (conflict_keys?.length) body.conflict_keys = conflict_keys;
312
- if (dry_run) body.dry_run = true;
313
- if (confirm_token) body.confirm = confirm_token;
314
- if (allow_extra_columns) body.allow_extra_columns = true;
315
- if (batch_size) body.batch_size = batch_size;
316
-
317
- const res = await apiRequest<any>('POST', `/projects/${project_id}/database/import`, body);
318
- if (!res.ok) return textResult(formatError(res));
319
-
320
- const d = res.data;
321
- const lines: string[] = [];
322
- if (d.dry_run) {
323
- lines.push(`Dry run: ${d.insert_count ?? 0} inserts, ${d.update_count ?? 0} updates, ${d.error_count ?? 0} errors`);
324
- if (d.confirm_token) lines.push(`confirm_token: ${d.confirm_token}`);
325
- if (d.expires_at) lines.push(`Expires: ${d.expires_at}`);
326
- if (d.errors?.length) {
327
- lines.push('', 'Row errors (first 10):');
328
- for (const e of d.errors.slice(0, 10)) lines.push(` ✗ row ${e.row ?? '?'}: ${e.error || JSON.stringify(e)}`);
329
- }
330
- lines.push('', 'If this looks right, re-call with confirm_token.');
331
- } else {
332
- lines.push(`Committed: ${d.inserted ?? 0} inserted, ${d.updated ?? 0} updated, ${d.errors ?? 0} errors`);
333
- if (d.duration_ms) lines.push(`Duration: ${d.duration_ms}ms`);
334
- }
335
- return textResult(lines.join('\n'));
336
- },
337
- );
338
-
339
- server.tool(
340
- 'dailey_db_exec',
341
- 'Execute write SQL (DDL/DML) against a project database — CREATE TABLE, ALTER, INSERT, UPDATE, etc. Runs all statements in a single transaction as a short-lived exec user, then drops the user. Works for both MySQL and Postgres (engine auto-detected). Refuses forbidden statements (DROP DATABASE, GRANT, CREATE USER, ATTACH, etc.). If the SQL contains destructive statements (DROP TABLE, TRUNCATE, DELETE without WHERE), set confirm=true to acknowledge. The endpoint writes every invocation to the exec_audit table. After running DDL, you may want to call dailey_db_schema to see the new shape.',
342
- {
343
- project_id: z.string().describe('The project ID'),
344
- sql: z.string().describe('One or more SQL statements separated by ";". Can include CREATE/ALTER/DROP TABLE, INSERT, UPDATE, DELETE, CREATE INDEX, etc. Transactions are automatic.'),
345
- confirm: z.boolean().optional().describe('Required (true) when sql contains destructive statements like DROP TABLE, TRUNCATE, or DELETE without WHERE. First call without confirm to see the destructive list; re-call with confirm=true to execute.'),
346
- },
347
- async ({ project_id, sql, confirm }) => {
348
- const res = await apiRequest<any>('POST', `/projects/${project_id}/database/exec`, {
349
- sql,
350
- confirm: !!confirm,
351
- });
352
-
353
- if (!res.ok) {
354
- const body: any = res.data;
355
- const lines = [formatError(res)];
356
- if (body?.forbidden?.length) {
357
- lines.push('', 'Forbidden statements (will never be allowed):');
358
- for (const f of body.forbidden) lines.push(` • ${f}`);
359
- }
360
- if (body?.destructive?.length) {
361
- lines.push('', 'Destructive statements detected — re-call with confirm=true to proceed:');
362
- for (const d of body.destructive) lines.push(` • ${d}`);
363
- }
364
- return textResult(lines.join('\n'));
365
- }
366
-
367
- const d = res.data;
368
- const lines = [
369
- `Execution: ${d.committed ? 'COMMITTED ✓' : (d.phase || 'unknown')}`,
370
- `Engine: ${d.engine || 'unknown'}`,
371
- `Database: ${d.database || 'unknown'}`,
372
- `Statements: ${d.statement_count ?? (d.results?.length ?? 0)}`,
373
- ];
374
- if (d.destructive?.length) {
375
- lines.push('');
376
- lines.push('Destructive statements applied:');
377
- for (const s of d.destructive) lines.push(` • ${s}`);
378
- }
379
- if (d.results?.length) {
380
- lines.push('');
381
- lines.push('Per-statement results:');
382
- for (const r of d.results) {
383
- if (typeof r.rows === 'number') lines.push(` ✓ ${r.rows} row(s) returned`);
384
- else if (typeof r.affected === 'number') lines.push(` ✓ ${r.affected} row(s) affected`);
385
- else lines.push(` ✓ ok`);
386
- }
387
- }
388
- return textResult(lines.join('\n'));
389
- },
390
- );
391
- }
@@ -1,247 +0,0 @@
1
- import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
- import { z } from 'zod';
3
- import { apiRequest, formatError, textResult } from '../api.js';
4
-
5
- interface DeployStatus {
6
- mode?: 'git' | 'image';
7
- image?: string;
8
- current_sha?: string | null;
9
- deployed_at?: string | null;
10
- can_deploy?: boolean;
11
- is_building?: boolean;
12
- branch?: string;
13
- has_new_version?: boolean;
14
- new_commits?: number;
15
- latest_sha?: string | null;
16
- latest_message?: string | null;
17
- pod_crash?: { restart_count: number; recent_logs: string } | null;
18
- }
19
-
20
- interface Build {
21
- id: string;
22
- status?: string;
23
- started_at?: string;
24
- finished_at?: string;
25
- commit_sha?: string;
26
- }
27
-
28
- interface BuildRow {
29
- id: string;
30
- status: string;
31
- log?: string;
32
- started_at?: string;
33
- finished_at?: string;
34
- commit_sha?: string;
35
- build_error_summary?: string;
36
- build_error_fix?: string;
37
- }
38
-
39
- const STAGE_EMOJI_RE = /^[⚙📦🚀✅🎉❌]/;
40
-
41
- function latestProgressLine(log: string): string | null {
42
- if (!log) return null;
43
- const lines = log.split('\n').map((l) => l.trim()).filter((l) => STAGE_EMOJI_RE.test(l));
44
- return lines.length > 0 ? lines[lines.length - 1] : null;
45
- }
46
-
47
- const FAILURE_PATTERNS: Array<{ pattern: RegExp; reason: string; fix: string }> = [
48
- { pattern: /npm ci.*did not complete|npm ERR! cipm can only install/i,
49
- reason: 'npm ci failed — package-lock.json missing or out of sync.',
50
- fix: 'Run `npm install` locally, commit the generated package-lock.json, redeploy.' },
51
- { pattern: /Cannot find module|Module not found|Can't resolve/i,
52
- reason: 'A required dependency or file is missing.',
53
- fix: 'Ensure all imports are listed in package.json and referenced files exist in the repo.' },
54
- { pattern: /EACCES|permission denied/i,
55
- reason: 'File permission error during build.',
56
- fix: 'Dailey OS builds run non-root. Remove anything that assumes root.' },
57
- { pattern: /ERR_SOCKET_TIMEOUT|ETIMEDOUT|EAI_AGAIN/i,
58
- reason: 'Network timeout fetching dependencies.',
59
- fix: 'Usually transient. Redeploy.' },
60
- { pattern: /exit code: 1.*build|build.*exit code: 1/i,
61
- reason: "The app's build command failed.",
62
- fix: 'Run the build locally and fix errors before redeploying.' },
63
- { pattern: /port.*in use|EADDRINUSE/i,
64
- reason: 'App trying to bind a port already in use.',
65
- fix: 'Read port from `process.env.PORT` (default 3000), not hardcoded.' },
66
- { pattern: /ERR_DLOPEN_FAILED|native.*module|node-gyp/i,
67
- reason: 'Native Node module failed to compile.',
68
- fix: 'Needs Linux build. Add a Dockerfile or use a pure-JS alternative.' },
69
- { pattern: /ENOMEM|heap.*limit|out of memory/i,
70
- reason: 'Build ran out of memory.',
71
- fix: 'Contact support to bump build memory limit.' },
72
- { pattern: /Dockerfile.*not found|no.*Dockerfile/i,
73
- reason: 'No Dockerfile found and stack auto-detection failed.',
74
- fix: 'Add a Dockerfile or ensure package.json / requirements.txt / go.mod / index.html exists at repo root.' },
75
- ];
76
-
77
- function getFailureGuidance(log: string): { reason: string; fix: string } | null {
78
- if (!log) return null;
79
- for (const { pattern, reason, fix } of FAILURE_PATTERNS) {
80
- if (pattern.test(log)) return { reason, fix };
81
- }
82
- return null;
83
- }
84
-
85
- const RUNTIME_CRASH_PATTERNS: Array<{ pattern: RegExp; summary: string; fix: string }> = [
86
- {
87
- pattern: /P3009|migrate found failed migrations/i,
88
- summary: 'Prisma migration failed on startup (P3009). A previous migration left the database in a dirty state and Prisma is blocking all further migrations.',
89
- fix: 'Run `npx prisma migrate resolve --rolled-back <migration_name>` to mark the failed migration as rolled back, then redeploy. If the database is fresh with no real data, you can clear `_prisma_migrations` entirely and redeploy to run all migrations from scratch. Use `dailey_db_exec` to inspect the `_prisma_migrations` table.',
90
- },
91
- {
92
- pattern: /Cannot find module|MODULE_NOT_FOUND/,
93
- summary: 'App crashed at startup — a required module or file is missing at runtime.',
94
- fix: 'A file is imported but does not exist in the deployed image. Search for the import in your source, check if the file was deleted or renamed, and fix the import before redeploying. Run `npx tsc --noEmit` locally to catch this before deploying.',
95
- },
96
- {
97
- pattern: /password authentication failed|ECONNREFUSED.*5432|ECONNREFUSED.*3306|connection refused.*database/i,
98
- summary: 'App crashed — cannot connect to the database.',
99
- fix: 'Check that the database is provisioned and DATABASE_URL is set. Run `dailey_env_list` to verify the env var is present. If the database was recently created, it may still be initialising — wait 30 seconds and redeploy.',
100
- },
101
- {
102
- pattern: /EADDRINUSE/i,
103
- summary: 'App crashed — port already in use.',
104
- fix: 'The app is trying to bind a hardcoded port. Read the port from `process.env.PORT` and bind to `0.0.0.0`, not localhost.',
105
- },
106
- {
107
- pattern: /ENOMEM|heap out of memory|JavaScript heap out of memory/i,
108
- summary: 'App crashed — out of memory (OOM).',
109
- fix: 'The app exceeded its RAM limit. Scale up RAM from the dashboard, or add `--max-old-space-size=<MB>` to NODE_OPTIONS env var to cap Node.js heap below the container limit.',
110
- },
111
- {
112
- pattern: /missing required env|required environment variable|env.*not.*set|getenv.*undefined/i,
113
- summary: 'App crashed — a required environment variable is not set.',
114
- fix: 'Run `dailey_env_list` to see what env vars are set. Add the missing variable with `dailey_env_set`, then redeploy.',
115
- },
116
- {
117
- pattern: /PRISMA_CLIENT_NOT_GENERATED|@prisma\/client did not initialize/i,
118
- summary: 'Prisma Client was not generated before the app started.',
119
- fix: 'Add `prisma generate` to your build step or postinstall script. In package.json: `"postinstall": "prisma generate"`.',
120
- },
121
- {
122
- pattern: /SyntaxError|unexpected token|Cannot use import/i,
123
- summary: 'App crashed — JavaScript syntax error or ESM/CJS module incompatibility.',
124
- fix: 'The compiled output has a syntax error or module format mismatch. Check your tsconfig `module` and `target` settings. Run `npm run build` locally and start the compiled output to reproduce.',
125
- },
126
- ];
127
-
128
- function getRuntimeCrashGuidance(logs: string): { summary: string; fix: string } | null {
129
- if (!logs) return null;
130
- for (const { pattern, summary, fix } of RUNTIME_CRASH_PATTERNS) {
131
- if (pattern.test(logs)) return { summary, fix };
132
- }
133
- return null;
134
- }
135
-
136
- export function registerDeployStatusTools(server: McpServer) {
137
- // Project-level pre-deploy status: can I deploy? is a build running? is there a new commit?
138
- // Also fetches the latest build row to show progress emojis during active builds.
139
- server.tool(
140
- 'dailey_deploy_status',
141
- 'Check deploy status for a project: whether a new version exists, whether a build is in progress, the current progress stage (⚙📦🚀✅🎉) if building, and whether it is safe to trigger a new deploy. Call this AFTER dailey_deploy_multi or dailey_run_image to watch progress.',
142
- { project_id: z.string().describe('The project ID') },
143
- async ({ project_id }) => {
144
- const statusRes = await apiRequest<DeployStatus>('GET', `/projects/${project_id}/deploy-status`);
145
- if (!statusRes.ok) return textResult(formatError(statusRes));
146
-
147
- const status = statusRes.data;
148
- const lines: string[] = [];
149
-
150
- if (status.mode === 'image') {
151
- lines.push(`Deploy mode: Docker image`);
152
- lines.push(`Image: ${status.image || '-'}`);
153
- lines.push(`Deployed at: ${status.deployed_at || 'never'}`);
154
- lines.push(`Can deploy: ${status.can_deploy ? 'yes' : 'no'}`);
155
- } else {
156
- lines.push(`Deploy mode: Git`);
157
- lines.push(`Branch: ${status.branch || 'main'}`);
158
- lines.push(`Deployed SHA: ${status.current_sha || 'never'}`);
159
- lines.push(`Deployed at: ${status.deployed_at || 'never'}`);
160
- // Only show Latest SHA when the upstream lookup actually returned
161
- // something. Emitting "Latest SHA: unknown" on every healthy project
162
- // is noise that implies something is broken (it's almost always just
163
- // that the GH token hasn't been connected, or there's no activity).
164
- if (status.latest_sha) {
165
- lines.push(`Latest SHA: ${status.latest_sha}`);
166
- }
167
- if (status.latest_message) {
168
- lines.push(`Latest msg: ${status.latest_message}`);
169
- }
170
- // Only show New version when we actually have a Latest SHA to
171
- // compare against — otherwise the "no" is meaningless.
172
- if (status.latest_sha) {
173
- lines.push(`New version: ${status.has_new_version ? `yes (${status.new_commits || '?'} new commits)` : 'no'}`);
174
- }
175
- lines.push(`Building: ${status.is_building ? 'yes' : 'no'}`);
176
- lines.push(`Can deploy: ${status.can_deploy ? 'yes' : 'no'}`);
177
- }
178
-
179
- // If there's an active or recent build, fetch its progress.
180
- const historyRes = await apiRequest<{ builds: Build[] }>('GET', `/projects/${project_id}/deploys`);
181
- if (historyRes.ok && historyRes.data.builds?.length) {
182
- const latest = historyRes.data.builds[0];
183
- lines.push('');
184
- lines.push(`Latest build: ${latest.id}`);
185
- lines.push(` Status: ${latest.status || 'unknown'}`);
186
- lines.push(` Started: ${latest.started_at || '-'}`);
187
- if (latest.finished_at) lines.push(` Finished: ${latest.finished_at}`);
188
-
189
- // Fetch build detail (includes log) for progress + failure info.
190
- const buildRes = await apiRequest<BuildRow>('GET', `/builds/${latest.id}`);
191
- if (buildRes.ok) {
192
- const buildData = buildRes.data;
193
- const log = buildData.log || '';
194
- const progress = latestProgressLine(log);
195
- if (progress) {
196
- lines.push(` Progress: ${progress}`);
197
- }
198
- // Runtime crash — build succeeded but pod is CrashLoopBackOff
199
- if (status.pod_crash) {
200
- const crash = status.pod_crash;
201
- const guidance = getRuntimeCrashGuidance(crash.recent_logs);
202
- lines.push('');
203
- lines.push(`⚠️ RUNTIME CRASH (build succeeded, app crashes on startup)`);
204
- lines.push(` Restarts: ${crash.restart_count}`);
205
- if (guidance) {
206
- lines.push(` Error: ${guidance.summary}`);
207
- lines.push(` Fix: ${guidance.fix}`);
208
- } else {
209
- lines.push(` Logs (last 40 lines):`);
210
- crash.recent_logs.split('\n').slice(-20).filter(Boolean).forEach((l) => {
211
- lines.push(` ${l}`);
212
- });
213
- lines.push(` Tip: call dailey_app_logs with project_id=${project_id} for full logs.`);
214
- }
215
- }
216
-
217
- if (latest.status === 'failed') {
218
- // Prefer the structured diagnosis fields surfaced by the deploy-service
219
- // (build_error_summary / build_error_fix) over the local pattern matching.
220
- // These are synthesised from the stored log by the deploy-service and are
221
- // more accurate than re-running regexes against a potentially truncated log.
222
- if (buildData.build_error_summary) {
223
- lines.push('');
224
- lines.push(`❌ BUILD FAILED`);
225
- lines.push(` Error: ${buildData.build_error_summary}`);
226
- if (buildData.build_error_fix) {
227
- lines.push(` Fix: ${buildData.build_error_fix}`);
228
- }
229
- } else {
230
- // Fall back to local pattern matching if no structured diagnosis
231
- const guidance = getFailureGuidance(log);
232
- if (guidance) {
233
- lines.push('');
234
- lines.push(`❌ Failure reason: ${guidance.reason}`);
235
- lines.push(` How to fix: ${guidance.fix}`);
236
- }
237
- }
238
- lines.push('');
239
- lines.push(`Tip: call dailey_build_logs with build_id=${latest.id} for the full build log.`);
240
- }
241
- }
242
- }
243
-
244
- return textResult(lines.join('\n'));
245
- },
246
- );
247
- }