@daileyos/mcp-server 1.0.2 → 1.2.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.
Files changed (79) hide show
  1. package/.github/workflows/publish.yml +93 -0
  2. package/LICENSE +21 -0
  3. package/README.md +130 -0
  4. package/dist/index.js +31 -7
  5. package/dist/index.js.map +1 -1
  6. package/dist/tools/analyze.d.ts +3 -0
  7. package/dist/tools/analyze.d.ts.map +1 -0
  8. package/dist/tools/analyze.js +67 -0
  9. package/dist/tools/analyze.js.map +1 -0
  10. package/dist/tools/backups.d.ts +3 -0
  11. package/dist/tools/backups.d.ts.map +1 -0
  12. package/dist/tools/backups.js +55 -0
  13. package/dist/tools/backups.js.map +1 -0
  14. package/dist/tools/build-logs.d.ts +3 -0
  15. package/dist/tools/build-logs.d.ts.map +1 -0
  16. package/dist/tools/build-logs.js +39 -0
  17. package/dist/tools/build-logs.js.map +1 -0
  18. package/dist/tools/cli.d.ts +3 -0
  19. package/dist/tools/cli.d.ts.map +1 -0
  20. package/dist/tools/cli.js +61 -0
  21. package/dist/tools/cli.js.map +1 -0
  22. package/dist/tools/credentials-reveal.d.ts +3 -0
  23. package/dist/tools/credentials-reveal.d.ts.map +1 -0
  24. package/dist/tools/credentials-reveal.js +19 -0
  25. package/dist/tools/credentials-reveal.js.map +1 -0
  26. package/dist/tools/db.d.ts.map +1 -1
  27. package/dist/tools/db.js +93 -1
  28. package/dist/tools/db.js.map +1 -1
  29. package/dist/tools/deploy-status.d.ts +3 -0
  30. package/dist/tools/deploy-status.d.ts.map +1 -0
  31. package/dist/tools/deploy-status.js +109 -0
  32. package/dist/tools/deploy-status.js.map +1 -0
  33. package/dist/tools/domains.d.ts.map +1 -1
  34. package/dist/tools/domains.js +81 -17
  35. package/dist/tools/domains.js.map +1 -1
  36. package/dist/tools/images.d.ts.map +1 -1
  37. package/dist/tools/images.js +2 -1
  38. package/dist/tools/images.js.map +1 -1
  39. package/dist/tools/lifecycle.d.ts +3 -0
  40. package/dist/tools/lifecycle.d.ts.map +1 -0
  41. package/dist/tools/lifecycle.js +53 -0
  42. package/dist/tools/lifecycle.js.map +1 -0
  43. package/dist/tools/links.d.ts +3 -0
  44. package/dist/tools/links.d.ts.map +1 -0
  45. package/dist/tools/links.js +55 -0
  46. package/dist/tools/links.js.map +1 -0
  47. package/dist/tools/processes.d.ts +3 -0
  48. package/dist/tools/processes.d.ts.map +1 -0
  49. package/dist/tools/processes.js +98 -0
  50. package/dist/tools/processes.js.map +1 -0
  51. package/dist/tools/projects.d.ts.map +1 -1
  52. package/dist/tools/projects.js +13 -0
  53. package/dist/tools/projects.js.map +1 -1
  54. package/dist/tools/resource-config.d.ts +3 -0
  55. package/dist/tools/resource-config.d.ts.map +1 -0
  56. package/dist/tools/resource-config.js +56 -0
  57. package/dist/tools/resource-config.js.map +1 -0
  58. package/dist/tools/scale.d.ts.map +1 -1
  59. package/dist/tools/scale.js +9 -2
  60. package/dist/tools/scale.js.map +1 -1
  61. package/package.json +1 -1
  62. package/src/index.ts +36 -7
  63. package/src/tools/analyze.ts +98 -0
  64. package/src/tools/backups.ts +84 -0
  65. package/src/tools/build-logs.ts +65 -0
  66. package/src/tools/cli.ts +76 -0
  67. package/src/tools/credentials-reveal.ts +31 -0
  68. package/src/tools/db.ts +105 -1
  69. package/src/tools/deploy-status.ts +149 -0
  70. package/src/tools/domains.ts +116 -21
  71. package/src/tools/images.ts +2 -1
  72. package/src/tools/lifecycle.ts +75 -0
  73. package/src/tools/links.ts +69 -0
  74. package/src/tools/processes.ts +172 -0
  75. package/src/tools/projects.ts +14 -0
  76. package/src/tools/resource-config.ts +84 -0
  77. package/src/tools/scale.ts +17 -3
  78. package/tests/mcp-protocol-smoke.mjs +149 -0
  79. package/tests/new-tools-smoke.mjs +211 -0
@@ -0,0 +1,76 @@
1
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ import { z } from 'zod';
3
+ import { textResult } from '../api.js';
4
+
5
+ function shellQuote(s: string): string {
6
+ if (/^[A-Za-z0-9_.\-\/]+$/.test(s)) return s;
7
+ return `'${s.replace(/'/g, `'\\''`)}'`;
8
+ }
9
+
10
+ export function registerCliTools(server: McpServer): void {
11
+ server.tool(
12
+ 'dailey_cli_suggest_import',
13
+ "Construct a correct `dailey db import` CLI invocation from semantic inputs. Read-only: does no I/O, makes no API calls. Pure string construction. The agent should run the returned command via its host shell (with user approval). A dry-run must precede any commit; the returned command defaults to --dry-run. Before suggesting, invoke `dailey_db_schema` to verify the payload shape fits the target table. For writes, this tool is the path — `dailey_db_recall` is read-only.",
14
+ {
15
+ project: z.string().describe('Project slug or id (e.g. "wordgym")'),
16
+ table: z.string().describe('Target table name'),
17
+ file: z
18
+ .string()
19
+ .describe(
20
+ 'Local file path to JSON array or CSV file (must exist on the user machine when the command runs)',
21
+ ),
22
+ mode: z.enum(['insert', 'upsert']).describe('Write mode'),
23
+ conflict_keys: z
24
+ .array(z.string())
25
+ .optional()
26
+ .describe('Conflict keys; required if mode=upsert'),
27
+ dry_run: z
28
+ .boolean()
29
+ .optional()
30
+ .default(true)
31
+ .describe(
32
+ 'Default true — constructs a command with --dry-run. Set false to construct a --confirm variant (the caller supplies the token from a prior dry-run output).',
33
+ ),
34
+ },
35
+ async ({ project, table, file, mode, conflict_keys, dry_run }) => {
36
+ if (mode === 'upsert' && (!conflict_keys || conflict_keys.length === 0)) {
37
+ return textResult('error: mode=upsert requires conflict_keys');
38
+ }
39
+
40
+ const parts = [
41
+ 'dailey db import',
42
+ shellQuote(project),
43
+ shellQuote(file),
44
+ `--table ${shellQuote(table)}`,
45
+ `--mode ${mode}`,
46
+ ];
47
+ if (mode === 'upsert' && conflict_keys) {
48
+ for (const k of conflict_keys) parts.push(`--key ${shellQuote(k)}`);
49
+ }
50
+ if (dry_run) parts.push('--dry-run');
51
+ parts.push('--json');
52
+
53
+ const command = parts.join(' ');
54
+ const explanation =
55
+ mode === 'upsert'
56
+ ? `Upserts rows from ${file} into ${table}; conflicts resolve on ${(conflict_keys ?? []).join(', ')}. ${dry_run ? 'Dry-run only — server returns a confirmation token for a follow-up commit.' : 'Commit phase — expects --confirm <token> from a prior dry-run.'}`
57
+ : `Inserts rows from ${file} into ${table}. ${dry_run ? 'Dry-run only — server returns a confirmation token for a follow-up commit.' : 'Commit phase — expects --confirm <token> from a prior dry-run.'}`;
58
+
59
+ const preflight = [
60
+ { check: 'file_exists', path: file },
61
+ { check: 'schema_compatible', table },
62
+ ];
63
+
64
+ const output = {
65
+ command,
66
+ explanation,
67
+ preflight,
68
+ expected_output: 'json',
69
+ on_dry_run_success:
70
+ 're-run with --confirm <token_from_dry_run_output> (remove --dry-run)',
71
+ };
72
+
73
+ return textResult(JSON.stringify(output, null, 2));
74
+ },
75
+ );
76
+ }
@@ -0,0 +1,31 @@
1
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ import { z } from 'zod';
3
+ import { apiRequest, formatError, textResult } from '../api.js';
4
+
5
+ export function registerCredentialRevealTools(server: McpServer) {
6
+ server.tool(
7
+ 'dailey_reveal_credential',
8
+ 'Reveal the actual value of a single project credential (e.g., DB_PASSWORD). Requires password re-auth for audit. Uses DAILEY_PASSWORD env var if set, otherwise provide password argument. Every reveal is logged.',
9
+ {
10
+ project_id: z.string().describe('The project ID'),
11
+ key: z.string().describe('Credential key (e.g., DB_PASSWORD, WORDPRESS_ADMIN_PASSWORD)'),
12
+ password: z.string().optional().describe('Account password for re-auth (falls back to DAILEY_PASSWORD env var)'),
13
+ },
14
+ async ({ project_id, key, password }) => {
15
+ const pw = password || process.env.DAILEY_PASSWORD;
16
+ if (!pw) {
17
+ return textResult(
18
+ 'Error: re-auth password required. Set DAILEY_PASSWORD env var or pass password argument. Every reveal is audited.',
19
+ );
20
+ }
21
+
22
+ const res = await apiRequest<{ key: string; value: string }>(
23
+ 'POST',
24
+ `/projects/${project_id}/credentials/reveal`,
25
+ { key, password: pw },
26
+ );
27
+ if (!res.ok) return textResult(formatError(res));
28
+ return textResult(`${res.data.key}: ${res.data.value}`);
29
+ },
30
+ );
31
+ }
package/src/tools/db.ts CHANGED
@@ -110,7 +110,7 @@ export function registerDbTools(server: McpServer) {
110
110
 
111
111
  server.tool(
112
112
  'dailey_db_recall',
113
- 'Recall records with a safe read-only SQL query',
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
114
  {
115
115
  project_id: z.string().describe('The project ID'),
116
116
  sql: z.string().describe('A read-only SQL query such as SELECT, SHOW, or DESCRIBE'),
@@ -143,6 +143,110 @@ export function registerDbTools(server: McpServer) {
143
143
  },
144
144
  );
145
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. A tunnel issues a per-session MySQL/Postgres user for GUI access (e.g., TablePlus, DBeaver). Sessions auto-expire after ~1 hour.',
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
+ return textResult([
208
+ `Database tunnel opened`,
209
+ '─'.repeat(40),
210
+ `Session ID: ${d.session_id}`,
211
+ `Engine: ${d.engine}`,
212
+ `Host: ${d.host}:${d.port}`,
213
+ `Database: ${d.database}`,
214
+ `Username: ${d.username}`,
215
+ `Password: ${d.password}`,
216
+ `Expires at: ${d.expires_at} (${d.ttl_seconds}s)`,
217
+ '',
218
+ `${d.message}`,
219
+ '',
220
+ `Close with: dailey_db_tunnel action=close session_id=${d.session_id}`,
221
+ ].join('\n'));
222
+ }
223
+
224
+ if (action === 'close') {
225
+ if (!session_id) return textResult('Error: session_id is required to close.');
226
+ const res = await apiRequest(
227
+ 'DELETE',
228
+ `/projects/${project_id}/database/tunnel/${encodeURIComponent(session_id)}`,
229
+ );
230
+ if (!res.ok) return textResult(formatError(res));
231
+ return textResult(`Tunnel session ${session_id} closed.`);
232
+ }
233
+
234
+ if (action === 'list') {
235
+ const res = await apiRequest<{ sessions: any[] }>('GET', `/projects/${project_id}/database/tunnel`);
236
+ if (!res.ok) return textResult(formatError(res));
237
+ const sessions = res.data.sessions || [];
238
+ if (sessions.length === 0) return textResult('No active tunnel sessions.');
239
+ const lines = [`Active tunnel sessions (${sessions.length})`, '─'.repeat(40)];
240
+ for (const s of sessions) {
241
+ lines.push(`• ${s.sessionId} engine=${s.engine} expires=${new Date(s.expiresAt).toISOString()}`);
242
+ }
243
+ return textResult(lines.join('\n'));
244
+ }
245
+
246
+ return textResult('Invalid action. Use open, close, or list.');
247
+ },
248
+ );
249
+
146
250
  server.tool(
147
251
  'dailey_db_migrations',
148
252
  'Show migration status for a project database',
@@ -0,0 +1,149 @@
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
+ }
18
+
19
+ interface Build {
20
+ id: string;
21
+ status?: string;
22
+ started_at?: string;
23
+ finished_at?: string;
24
+ commit_sha?: string;
25
+ }
26
+
27
+ interface BuildRow {
28
+ id: string;
29
+ status: string;
30
+ log?: string;
31
+ started_at?: string;
32
+ finished_at?: string;
33
+ commit_sha?: string;
34
+ }
35
+
36
+ const STAGE_EMOJI_RE = /^[⚙📦🚀✅🎉❌]/;
37
+
38
+ function latestProgressLine(log: string): string | null {
39
+ if (!log) return null;
40
+ const lines = log.split('\n').map((l) => l.trim()).filter((l) => STAGE_EMOJI_RE.test(l));
41
+ return lines.length > 0 ? lines[lines.length - 1] : null;
42
+ }
43
+
44
+ const FAILURE_PATTERNS: Array<{ pattern: RegExp; reason: string; fix: string }> = [
45
+ { pattern: /npm ci.*did not complete|npm ERR! cipm can only install/i,
46
+ reason: 'npm ci failed — package-lock.json missing or out of sync.',
47
+ fix: 'Run `npm install` locally, commit the generated package-lock.json, redeploy.' },
48
+ { pattern: /Cannot find module|Module not found|Can't resolve/i,
49
+ reason: 'A required dependency or file is missing.',
50
+ fix: 'Ensure all imports are listed in package.json and referenced files exist in the repo.' },
51
+ { pattern: /EACCES|permission denied/i,
52
+ reason: 'File permission error during build.',
53
+ fix: 'Dailey OS builds run non-root. Remove anything that assumes root.' },
54
+ { pattern: /ERR_SOCKET_TIMEOUT|ETIMEDOUT|EAI_AGAIN/i,
55
+ reason: 'Network timeout fetching dependencies.',
56
+ fix: 'Usually transient. Redeploy.' },
57
+ { pattern: /exit code: 1.*build|build.*exit code: 1/i,
58
+ reason: "The app's build command failed.",
59
+ fix: 'Run the build locally and fix errors before redeploying.' },
60
+ { pattern: /port.*in use|EADDRINUSE/i,
61
+ reason: 'App trying to bind a port already in use.',
62
+ fix: 'Read port from `process.env.PORT` (default 3000), not hardcoded.' },
63
+ { pattern: /ERR_DLOPEN_FAILED|native.*module|node-gyp/i,
64
+ reason: 'Native Node module failed to compile.',
65
+ fix: 'Needs Linux build. Add a Dockerfile or use a pure-JS alternative.' },
66
+ { pattern: /ENOMEM|heap.*limit|out of memory/i,
67
+ reason: 'Build ran out of memory.',
68
+ fix: 'Contact support to bump build memory limit.' },
69
+ { pattern: /Dockerfile.*not found|no.*Dockerfile/i,
70
+ reason: 'No Dockerfile found and stack auto-detection failed.',
71
+ fix: 'Add a Dockerfile or ensure package.json / requirements.txt / go.mod / index.html exists at repo root.' },
72
+ ];
73
+
74
+ function getFailureGuidance(log: string): { reason: string; fix: string } | null {
75
+ if (!log) return null;
76
+ for (const { pattern, reason, fix } of FAILURE_PATTERNS) {
77
+ if (pattern.test(log)) return { reason, fix };
78
+ }
79
+ return null;
80
+ }
81
+
82
+ export function registerDeployStatusTools(server: McpServer) {
83
+ // Project-level pre-deploy status: can I deploy? is a build running? is there a new commit?
84
+ // Also fetches the latest build row to show progress emojis during active builds.
85
+ server.tool(
86
+ 'dailey_deploy_status',
87
+ '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.',
88
+ { project_id: z.string().describe('The project ID') },
89
+ async ({ project_id }) => {
90
+ const statusRes = await apiRequest<DeployStatus>('GET', `/projects/${project_id}/deploy-status`);
91
+ if (!statusRes.ok) return textResult(formatError(statusRes));
92
+
93
+ const status = statusRes.data;
94
+ const lines: string[] = [];
95
+
96
+ if (status.mode === 'image') {
97
+ lines.push(`Deploy mode: Docker image`);
98
+ lines.push(`Image: ${status.image || '-'}`);
99
+ lines.push(`Deployed at: ${status.deployed_at || 'never'}`);
100
+ lines.push(`Can deploy: ${status.can_deploy ? 'yes' : 'no'}`);
101
+ } else {
102
+ lines.push(`Deploy mode: Git`);
103
+ lines.push(`Branch: ${status.branch || 'main'}`);
104
+ lines.push(`Deployed SHA: ${status.current_sha || 'never'}`);
105
+ lines.push(`Deployed at: ${status.deployed_at || 'never'}`);
106
+ lines.push(`Latest SHA: ${status.latest_sha || 'unknown'}`);
107
+ if (status.latest_message) {
108
+ lines.push(`Latest msg: ${status.latest_message}`);
109
+ }
110
+ lines.push(`New version: ${status.has_new_version ? `yes (${status.new_commits || '?'} new commits)` : 'no'}`);
111
+ lines.push(`Building: ${status.is_building ? 'yes' : 'no'}`);
112
+ lines.push(`Can deploy: ${status.can_deploy ? 'yes' : 'no'}`);
113
+ }
114
+
115
+ // If there's an active or recent build, fetch its progress.
116
+ const historyRes = await apiRequest<{ builds: Build[] }>('GET', `/projects/${project_id}/deploys`);
117
+ if (historyRes.ok && historyRes.data.builds?.length) {
118
+ const latest = historyRes.data.builds[0];
119
+ lines.push('');
120
+ lines.push(`Latest build: ${latest.id}`);
121
+ lines.push(` Status: ${latest.status || 'unknown'}`);
122
+ lines.push(` Started: ${latest.started_at || '-'}`);
123
+ if (latest.finished_at) lines.push(` Finished: ${latest.finished_at}`);
124
+
125
+ // Fetch build detail (includes log) for progress + failure info.
126
+ const buildRes = await apiRequest<BuildRow>('GET', `/builds/${latest.id}`);
127
+ if (buildRes.ok) {
128
+ const log = buildRes.data.log || '';
129
+ const progress = latestProgressLine(log);
130
+ if (progress) {
131
+ lines.push(` Progress: ${progress}`);
132
+ }
133
+ if (latest.status === 'failed') {
134
+ const guidance = getFailureGuidance(log);
135
+ if (guidance) {
136
+ lines.push('');
137
+ lines.push(`❌ Failure reason: ${guidance.reason}`);
138
+ lines.push(` How to fix: ${guidance.fix}`);
139
+ }
140
+ lines.push('');
141
+ lines.push(`Tip: call dailey_build_logs with build_id=${latest.id} for the full build log.`);
142
+ }
143
+ }
144
+ }
145
+
146
+ return textResult(lines.join('\n'));
147
+ },
148
+ );
149
+ }
@@ -3,19 +3,49 @@ import { z } from 'zod';
3
3
  import { apiRequest, formatError, textResult } from '../api.js';
4
4
 
5
5
  interface Domain {
6
- domain: string;
7
- status?: string;
6
+ hostname: string;
7
+ is_default?: boolean;
8
+ verified?: boolean;
9
+ cert_status?: string;
10
+ cert_issuer?: string;
11
+ removable?: boolean;
8
12
  created_at?: string;
9
13
  }
10
14
 
15
+ interface DnsCheckResponse {
16
+ domain: string;
17
+ expected_cname: string;
18
+ expected_a_records: string[];
19
+ actual_cname: string[];
20
+ actual_a_records: string[];
21
+ matched: boolean;
22
+ match_type: string | null;
23
+ cloudflare_proxied: boolean;
24
+ hint: string;
25
+ }
26
+
27
+ interface CertStatusResponse {
28
+ domain: string;
29
+ cert: {
30
+ subject_cn?: string;
31
+ subject_alt_names?: string[];
32
+ issuer?: string;
33
+ valid_from?: string;
34
+ valid_to?: string;
35
+ days_remaining?: number | null;
36
+ } | null;
37
+ status: string;
38
+ hint: string;
39
+ }
40
+
11
41
  export function registerDomainTools(server: McpServer) {
12
42
  server.tool(
13
43
  'dailey_domains',
14
- 'List, add, or remove custom domains for a project',
44
+ 'Manage custom domains: list, add, remove, check DNS, or check TLS cert status for a custom domain.',
15
45
  {
16
46
  project_id: z.string().describe('The project ID'),
17
- action: z.enum(['list', 'add', 'remove']).describe('Action: list, add, or remove'),
18
- domain: z.string().optional().describe('Domain name (required for add/remove)'),
47
+ action: z.enum(['list', 'add', 'remove', 'dns_check', 'cert_status']).describe('list | add | remove | dns_check | cert_status'),
48
+ domain: z.string().optional().describe('Domain name (required for add/remove/dns_check/cert_status)'),
19
49
  },
20
50
  async ({ project_id, action, domain }) => {
21
51
  if (action === 'list') {
@@ -27,35 +57,100 @@ export function registerDomainTools(server: McpServer) {
27
57
  return textResult('No custom domains configured.');
28
58
  }
29
59
 
30
- const lines = [
31
- `Custom Domains (${domains.length})`,
32
- '─'.repeat(50),
33
- ];
60
+ const lines = [`Domains (${domains.length})`, '─'.repeat(60)];
34
61
  for (const d of domains) {
35
- lines.push(`${d.domain}${d.status ? ` (${d.status})` : ''}`);
62
+ const flags: string[] = [];
63
+ if (d.is_default) flags.push('default');
64
+ if (d.verified) flags.push('verified');
65
+ if (d.cert_status) flags.push(`cert=${d.cert_status}`);
66
+ lines.push(`${d.hostname}${flags.length ? ` [${flags.join(', ')}]` : ''}`);
36
67
  }
37
68
  return textResult(lines.join('\n'));
38
69
  }
39
70
 
40
71
  if (action === 'add') {
41
- if (!domain) {
42
- return textResult('Error: domain is required for add action.');
43
- }
44
- const res = await apiRequest('POST', `/projects/${project_id}/domains`, { domain });
72
+ if (!domain) return textResult('Error: domain is required for add action.');
73
+ const res = await apiRequest<any>('POST', `/projects/${project_id}/domains`, { hostname: domain });
45
74
  if (!res.ok) return textResult(formatError(res));
46
- return textResult(`Domain ${domain} added to project.`);
75
+ const d = res.data;
76
+ const lines = [`Domain ${d.hostname || domain} added.`, ''];
77
+ if (d.instructions) {
78
+ lines.push(d.instructions);
79
+ lines.push('');
80
+ }
81
+ lines.push(`After DNS propagates (~1-60 min):`);
82
+ lines.push(` 1. dailey_domains action=dns_check domain=${domain} — verify DNS`);
83
+ lines.push(` 2. Let's Encrypt issues a cert automatically (~30s)`);
84
+ lines.push(` 3. dailey_domains action=cert_status domain=${domain} — confirm cert`);
85
+ return textResult(lines.join('\n'));
47
86
  }
48
87
 
49
88
  if (action === 'remove') {
50
- if (!domain) {
51
- return textResult('Error: domain is required for remove action.');
52
- }
53
- const res = await apiRequest('DELETE', `/projects/${project_id}/domains`, { domain });
89
+ if (!domain) return textResult('Error: domain is required for remove action.');
90
+ const res = await apiRequest('DELETE', `/projects/${project_id}/domains`, { hostname: domain });
54
91
  if (!res.ok) return textResult(formatError(res));
55
- return textResult(`Domain ${domain} removed from project.`);
92
+ return textResult(`Domain ${domain} removed.`);
93
+ }
94
+
95
+ if (action === 'dns_check') {
96
+ if (!domain) return textResult('Error: domain is required for dns_check.');
97
+ const res = await apiRequest<DnsCheckResponse>(
98
+ 'GET',
99
+ `/projects/${project_id}/domains/dns-check?domain=${encodeURIComponent(domain)}`,
100
+ );
101
+ if (!res.ok) return textResult(formatError(res));
102
+
103
+ const d = res.data;
104
+ const lines = [
105
+ `DNS check for ${d.domain}`,
106
+ '─'.repeat(50),
107
+ `Expected CNAME: ${d.expected_cname}`,
108
+ `Expected A: ${d.expected_a_records?.join(', ') || '-'}`,
109
+ `Actual CNAME: ${d.actual_cname?.join(', ') || '(none)'}`,
110
+ `Actual A: ${d.actual_a_records?.join(', ') || '(none)'}`,
111
+ `Match: ${d.matched ? '✅ yes' : '❌ no'} ${d.match_type ? `(${d.match_type})` : ''}`,
112
+ `Cloudflare proxy: ${d.cloudflare_proxied ? 'yes' : 'no'}`,
113
+ '',
114
+ `Hint: ${d.hint}`,
115
+ ];
116
+ return textResult(lines.join('\n'));
117
+ }
118
+
119
+ if (action === 'cert_status') {
120
+ if (!domain) return textResult('Error: domain is required for cert_status.');
121
+ const res = await apiRequest<CertStatusResponse>(
122
+ 'GET',
123
+ `/projects/${project_id}/domains/cert-status?domain=${encodeURIComponent(domain)}`,
124
+ );
125
+ if (!res.ok) return textResult(formatError(res));
126
+
127
+ const d = res.data;
128
+ if (!d.cert) {
129
+ return textResult([
130
+ `Cert status for ${d.domain}`,
131
+ '─'.repeat(50),
132
+ `Status: ${d.status}`,
133
+ '',
134
+ `Hint: ${d.hint}`,
135
+ ].join('\n'));
136
+ }
137
+ const lines = [
138
+ `Cert status for ${d.domain}`,
139
+ '─'.repeat(50),
140
+ `Status: ${d.status}`,
141
+ `Subject: ${d.cert.subject_cn || '-'}`,
142
+ `SANs: ${d.cert.subject_alt_names?.join(', ') || '-'}`,
143
+ `Issuer: ${d.cert.issuer || '-'}`,
144
+ `Valid from: ${d.cert.valid_from || '-'}`,
145
+ `Valid to: ${d.cert.valid_to || '-'}`,
146
+ `Days left: ${d.cert.days_remaining ?? '-'}`,
147
+ '',
148
+ `Hint: ${d.hint}`,
149
+ ];
150
+ return textResult(lines.join('\n'));
56
151
  }
57
152
 
58
- return textResult('Error: Invalid action. Use list, add, or remove.');
153
+ return textResult('Error: Invalid action. Use list, add, remove, dns_check, or cert_status.');
59
154
  },
60
155
  );
61
156
  }
@@ -53,7 +53,8 @@ export function registerImageTools(server: McpServer) {
53
53
  }
54
54
 
55
55
  result += `\nBuild ID: ${deployRes.data?.build_id || 'pending'}\n`;
56
- result += `View logs: dailey logs ${project.slug}`;
56
+ result += `\nNext: call dailey_deploy_status with project_id=${project.id} to watch progress.\n`;
57
+ result += ` If it fails, call dailey_build_logs with project_id=${project.id} for full output.`;
57
58
 
58
59
  return textResult(result);
59
60
  },
@@ -0,0 +1,75 @@
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 PauseResponse {
6
+ paused?: boolean;
7
+ already_paused?: boolean;
8
+ scaled?: Array<{ process: string; deployment: string }>;
9
+ failures?: Array<{ process: string; deployment: string; error: string }>;
10
+ }
11
+
12
+ interface ResumeResponse {
13
+ resumed?: boolean;
14
+ already_running?: boolean;
15
+ scaled?: Array<{ process: string; deployment: string; replicas: number }>;
16
+ failures?: Array<{ process: string; deployment: string; error: string }>;
17
+ }
18
+
19
+ export function registerLifecycleTools(server: McpServer) {
20
+ server.tool(
21
+ 'dailey_pause',
22
+ 'Pause a project — scales all processes to 0 replicas but preserves DB, storage, ingress, and the desired replica count. Use this instead of dailey_scale 0 when you want to temporarily stop a project without losing config.',
23
+ { project_id: z.string().describe('The project ID') },
24
+ async ({ project_id }) => {
25
+ const res = await apiRequest<PauseResponse>('POST', `/projects/${project_id}/pause`);
26
+ if (!res.ok) return textResult(formatError(res));
27
+
28
+ const data = res.data;
29
+ if (data.already_paused) return textResult('Project was already paused.');
30
+
31
+ const scaled = data.scaled || [];
32
+ const failures = data.failures || [];
33
+ const lines = [
34
+ `Project ${project_id} paused.`,
35
+ `Scaled to zero: ${scaled.length} process(es).`,
36
+ ];
37
+ for (const s of scaled) lines.push(` • ${s.process} (${s.deployment})`);
38
+ if (failures.length) {
39
+ lines.push('');
40
+ lines.push(`⚠ ${failures.length} failure(s):`);
41
+ for (const f of failures) lines.push(` ✗ ${f.process}: ${f.error}`);
42
+ }
43
+ lines.push('');
44
+ lines.push('Resume later with: dailey_resume project_id=' + project_id);
45
+ return textResult(lines.join('\n'));
46
+ },
47
+ );
48
+
49
+ server.tool(
50
+ 'dailey_resume',
51
+ 'Resume a paused project — scales processes back to their previous replica count.',
52
+ { project_id: z.string().describe('The project ID') },
53
+ async ({ project_id }) => {
54
+ const res = await apiRequest<ResumeResponse>('POST', `/projects/${project_id}/resume`);
55
+ if (!res.ok) return textResult(formatError(res));
56
+
57
+ const data = res.data;
58
+ if (data.already_running) return textResult('Project was already running.');
59
+
60
+ const scaled = data.scaled || [];
61
+ const failures = data.failures || [];
62
+ const lines = [
63
+ `Project ${project_id} resumed.`,
64
+ `Scaled up: ${scaled.length} process(es).`,
65
+ ];
66
+ for (const s of scaled) lines.push(` • ${s.process} → ${s.replicas} replica(s)`);
67
+ if (failures.length) {
68
+ lines.push('');
69
+ lines.push(`⚠ ${failures.length} failure(s):`);
70
+ for (const f of failures) lines.push(` ✗ ${f.process}: ${f.error}`);
71
+ }
72
+ return textResult(lines.join('\n'));
73
+ },
74
+ );
75
+ }