@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,69 @@
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 ServiceLink {
6
+ id: string;
7
+ target_project_id: string;
8
+ target_name?: string;
9
+ target_slug?: string;
10
+ target_status?: string;
11
+ env_key?: string;
12
+ url?: string;
13
+ }
14
+
15
+ export function registerLinkTools(server: McpServer) {
16
+ server.tool(
17
+ 'dailey_service_links',
18
+ 'Manage service-to-service links. A link injects an env var pointing at another project (e.g., DATABASE_URL=http://mydb). After add/remove, redeploy to pick up env changes.',
19
+ {
20
+ project_id: z.string().describe('The source project ID'),
21
+ action: z.enum(['list', 'add', 'remove']).describe('list | add | remove'),
22
+ target_project_id: z.string().optional().describe('Target project to link to (add)'),
23
+ env_key: z.string().optional().describe('Env var name to inject (add, optional — auto-generated from target name)'),
24
+ link_id: z.string().optional().describe('Link ID to remove (remove)'),
25
+ },
26
+ async ({ project_id, action, target_project_id, env_key, link_id }) => {
27
+ if (action === 'list') {
28
+ const res = await apiRequest<{ links: ServiceLink[] }>('GET', `/projects/${project_id}/links`);
29
+ if (!res.ok) return textResult(formatError(res));
30
+
31
+ const links = res.data.links || [];
32
+ if (links.length === 0) return textResult('No service links.');
33
+
34
+ const lines = [
35
+ `Service Links (${links.length})`,
36
+ '─'.repeat(70),
37
+ ];
38
+ for (const l of links) {
39
+ lines.push(`• ${l.env_key}=${l.url} → ${l.target_name} (${l.target_slug}, ${l.target_status})`);
40
+ lines.push(` link_id: ${l.id}`);
41
+ }
42
+ return textResult(lines.join('\n'));
43
+ }
44
+
45
+ if (action === 'add') {
46
+ if (!target_project_id) return textResult('Error: target_project_id is required for add.');
47
+ const body: Record<string, string> = { target_project_id };
48
+ if (env_key) body.env_key = env_key;
49
+ const res = await apiRequest<any>('POST', `/projects/${project_id}/links`, body);
50
+ if (!res.ok) return textResult(formatError(res));
51
+ const l = res.data.link;
52
+ return textResult([
53
+ `Link created: ${l.env_key}=${l.url} → ${l.target_name}`,
54
+ '',
55
+ `Redeploy this project to pick up the new env var: dailey_deploy_multi project_id=${project_id}`,
56
+ ].join('\n'));
57
+ }
58
+
59
+ if (action === 'remove') {
60
+ if (!link_id) return textResult('Error: link_id is required for remove.');
61
+ const res = await apiRequest('DELETE', `/projects/${project_id}/links/${link_id}`);
62
+ if (!res.ok) return textResult(formatError(res));
63
+ return textResult(`Link ${link_id} removed. Redeploy to reflect the env change.`);
64
+ }
65
+
66
+ return textResult('Invalid action. Use list, add, or remove.');
67
+ },
68
+ );
69
+ }
@@ -0,0 +1,172 @@
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 Process {
6
+ name: string;
7
+ type?: string;
8
+ command?: string;
9
+ port?: number;
10
+ replicas?: number;
11
+ cpu_millicores?: number;
12
+ memory_mb?: number;
13
+ timeout_seconds?: number;
14
+ namespace?: string;
15
+ domain?: string;
16
+ status?: string;
17
+ }
18
+
19
+ interface ProcessLogsResponse {
20
+ pods?: Array<{ pod: string; status: string; node: string; restarts: number; log: string }>;
21
+ logs?: string[];
22
+ }
23
+
24
+ interface ProcessMetricsResponse {
25
+ usage?: {
26
+ cpu_millicores?: number;
27
+ memory_mb?: number;
28
+ pods_ready?: number;
29
+ pods_total?: number;
30
+ restarts?: number;
31
+ };
32
+ resources?: {
33
+ cpu_limit_millicores?: number;
34
+ memory_limit_mb?: number;
35
+ replicas?: number;
36
+ };
37
+ pods?: Array<{ name: string; node: string }>;
38
+ }
39
+
40
+ export function registerProcessTools(server: McpServer) {
41
+ server.tool(
42
+ 'dailey_processes',
43
+ 'List processes defined in a project (from dailey.yaml). Shows web/worker/release processes with resource limits and status.',
44
+ { project_id: z.string().describe('The project ID') },
45
+ async ({ project_id }) => {
46
+ const res = await apiRequest<{ processes: Process[] }>('GET', `/projects/${project_id}/processes`);
47
+ if (!res.ok) return textResult(formatError(res));
48
+
49
+ const procs = res.data.processes || [];
50
+ if (procs.length === 0) {
51
+ return textResult('No processes defined. This project runs as a single process.');
52
+ }
53
+
54
+ const lines = [
55
+ `Processes (${procs.length})`,
56
+ `${'Name'.padEnd(20)} ${'Type'.padEnd(10)} ${'Replicas'.padEnd(9)} ${'CPU'.padEnd(8)} ${'Memory'.padEnd(10)} Status`,
57
+ '─'.repeat(80),
58
+ ];
59
+ for (const p of procs) {
60
+ lines.push(
61
+ `${(p.name || '').padEnd(20)} ${(p.type || '-').padEnd(10)} ${String(p.replicas ?? '-').padEnd(9)} ${String(p.cpu_millicores ?? '-').padEnd(8)} ${String(p.memory_mb ?? '-').padEnd(10)} ${p.status || '-'}`,
62
+ );
63
+ if (p.command) lines.push(` cmd: ${p.command}`);
64
+ }
65
+ return textResult(lines.join('\n'));
66
+ },
67
+ );
68
+
69
+ server.tool(
70
+ 'dailey_process_logs',
71
+ 'Fetch logs for a specific process in a multi-process project.',
72
+ {
73
+ project_id: z.string().describe('The project ID'),
74
+ process_name: z.string().describe('The process name (from dailey_processes)'),
75
+ tail: z.number().int().min(1).max(2000).optional().describe('Number of log lines to fetch (default: 100)'),
76
+ },
77
+ async ({ project_id, process_name, tail }) => {
78
+ const query = tail ? `?tail=${tail}` : '?tail=100';
79
+ const res = await apiRequest<ProcessLogsResponse>(
80
+ 'GET',
81
+ `/projects/${project_id}/processes/${encodeURIComponent(process_name)}/logs${query}`,
82
+ );
83
+ if (!res.ok) return textResult(formatError(res));
84
+
85
+ const logs = res.data.logs || [];
86
+ if (logs.length === 0) return textResult(`No logs for process ${process_name}.`);
87
+ return textResult([`Logs for ${process_name} (last ${tail || 100} lines):`, '', ...logs].join('\n'));
88
+ },
89
+ );
90
+
91
+ server.tool(
92
+ 'dailey_process_restart',
93
+ 'Restart a single process (rolling restart). Only affects the named process — other processes keep running.',
94
+ {
95
+ project_id: z.string().describe('The project ID'),
96
+ process_name: z.string().describe('The process name to restart'),
97
+ },
98
+ async ({ project_id, process_name }) => {
99
+ const res = await apiRequest(
100
+ 'POST',
101
+ `/projects/${project_id}/processes/${encodeURIComponent(process_name)}/restart`,
102
+ );
103
+ if (!res.ok) return textResult(formatError(res));
104
+ return textResult(`Restart initiated for process ${process_name}. Pods will roll one-by-one.`);
105
+ },
106
+ );
107
+
108
+ server.tool(
109
+ 'dailey_process_metrics',
110
+ 'Get live resource usage and pod health for a process: pods ready, restarts, CPU/memory limits.',
111
+ {
112
+ project_id: z.string().describe('The project ID'),
113
+ process_name: z.string().describe('The process name'),
114
+ },
115
+ async ({ project_id, process_name }) => {
116
+ const res = await apiRequest<ProcessMetricsResponse>(
117
+ 'GET',
118
+ `/projects/${project_id}/processes/${encodeURIComponent(process_name)}/metrics`,
119
+ );
120
+ if (!res.ok) return textResult(formatError(res));
121
+
122
+ const usage = res.data.usage || {};
123
+ const resources = res.data.resources || {};
124
+ const pods = res.data.pods || [];
125
+
126
+ const lines = [
127
+ `Process: ${process_name}`,
128
+ '─'.repeat(40),
129
+ `Pods ready: ${usage.pods_ready ?? 0} / ${usage.pods_total ?? 0}`,
130
+ `Restarts: ${usage.restarts ?? 0}`,
131
+ `CPU limit: ${resources.cpu_limit_millicores ?? '-'}m`,
132
+ `Mem limit: ${resources.memory_limit_mb ?? '-'} MB`,
133
+ `Replicas: ${resources.replicas ?? '-'}`,
134
+ ];
135
+ if (pods.length > 0) {
136
+ lines.push('');
137
+ lines.push('Pods:');
138
+ for (const pod of pods) lines.push(` ${pod.name} on ${pod.node}`);
139
+ }
140
+ return textResult(lines.join('\n'));
141
+ },
142
+ );
143
+
144
+ server.tool(
145
+ 'dailey_process_resources',
146
+ 'Update replicas, CPU, or memory limits for a specific process. Omit fields you do not want to change.',
147
+ {
148
+ project_id: z.string().describe('The project ID'),
149
+ process_name: z.string().describe('The process name'),
150
+ replicas: z.number().int().min(0).max(20).optional().describe('Replicas (0-20)'),
151
+ cpu_millicores: z.number().int().min(10).max(8000).optional().describe('CPU limit in millicores (10-8000)'),
152
+ memory_mb: z.number().int().min(64).max(32768).optional().describe('Memory limit in MB (64-32768)'),
153
+ },
154
+ async ({ project_id, process_name, replicas, cpu_millicores, memory_mb }) => {
155
+ const body: Record<string, number> = {};
156
+ if (replicas !== undefined) body.replicas = replicas;
157
+ if (cpu_millicores !== undefined) body.cpu_millicores = cpu_millicores;
158
+ if (memory_mb !== undefined) body.memory_mb = memory_mb;
159
+ if (Object.keys(body).length === 0) {
160
+ return textResult('Error: specify at least one of replicas, cpu_millicores, or memory_mb.');
161
+ }
162
+ const res = await apiRequest(
163
+ 'POST',
164
+ `/projects/${project_id}/processes/${encodeURIComponent(process_name)}/resources`,
165
+ body,
166
+ );
167
+ if (!res.ok) return textResult(formatError(res));
168
+ const changed = Object.entries(body).map(([k, v]) => `${k}=${v}`).join(', ');
169
+ return textResult(`Updated process ${process_name}: ${changed}`);
170
+ },
171
+ );
172
+ }
@@ -142,17 +142,31 @@ export function registerProjectTools(server: McpServer) {
142
142
  services = manifest.entries.filter((e: any) => e.type === 'managed' || e.type === 'app_service');
143
143
  }
144
144
 
145
+ // Safety: ensure at least one service is marked 'app_service' so the
146
+ // deployer knows which one gets the public ingress. Without this, all
147
+ // services deploy as "internal only" and the project is unreachable
148
+ // with no warning. (Scott hit this on 2026-04-20.)
149
+ const hasAppService = services?.some((s: any) => s.type === 'app_service');
150
+ if (services?.length && !hasAppService) {
151
+ services[0].type = 'app_service';
152
+ }
153
+
145
154
  const res = await apiRequest<any>('POST', `/projects/${project_id}/deploy-multi`, {
146
155
  selected_services: services,
147
156
  });
148
157
  if (!res.ok) return textResult(formatError(res));
149
158
 
159
+ const primary = services?.find((s: any) => s.type === 'app_service')?.name;
150
160
  return textResult([
151
161
  `Multi-container deploy triggered!`,
152
162
  ``,
153
163
  `Build ID: ${res.data.build_id}`,
154
164
  `Deploy Group: ${res.data.deploy_group_id}`,
155
165
  `Services: ${services?.length || 0}`,
166
+ `Primary (web): ${primary || 'none — check deploy log'}`,
167
+ ``,
168
+ `Next: call dailey_deploy_status with project_id=${project_id} to watch progress.`,
169
+ ` If it fails, call dailey_build_logs with project_id=${project_id} for full output.`,
156
170
  ].join('\n'));
157
171
  },
158
172
  );
@@ -0,0 +1,84 @@
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 ResourceConfigResponse {
6
+ cpu?: number;
7
+ memory_mb?: number;
8
+ storage_gb?: number;
9
+ replicas?: number;
10
+ project?: {
11
+ cpu_request?: string;
12
+ cpu_limit?: string;
13
+ memory_request?: string;
14
+ memory_limit?: string;
15
+ storage_limit?: string;
16
+ replicas?: number;
17
+ };
18
+ pool?: {
19
+ plan?: string;
20
+ cpu_total?: number;
21
+ cpu_used?: number;
22
+ memory_total_mb?: number;
23
+ memory_used_mb?: number;
24
+ storage_total_gb?: number;
25
+ storage_used_gb?: number;
26
+ };
27
+ }
28
+
29
+ export function registerResourceConfigTools(server: McpServer) {
30
+ server.tool(
31
+ 'dailey_resource_config',
32
+ 'Get or set CPU/memory/storage limits for a project. Pool shows remaining plan capacity.',
33
+ {
34
+ project_id: z.string().describe('The project ID'),
35
+ action: z.enum(['get', 'set']).describe('get | set'),
36
+ cpu: z.number().optional().describe('CPU cores (e.g., 0.5, 1, 2). Used by set.'),
37
+ memory_mb: z.number().int().optional().describe('Memory in MB. Used by set.'),
38
+ storage_gb: z.number().optional().describe('Storage in GB. Used by set.'),
39
+ replicas: z.number().int().min(0).max(20).optional().describe('Replicas. Used by set.'),
40
+ },
41
+ async ({ project_id, action, cpu, memory_mb, storage_gb, replicas }) => {
42
+ if (action === 'get') {
43
+ const res = await apiRequest<ResourceConfigResponse>('GET', `/projects/${project_id}/resource-config`);
44
+ if (!res.ok) return textResult(formatError(res));
45
+
46
+ const d = res.data;
47
+ const proj = d.project || {};
48
+ const pool = d.pool || {};
49
+
50
+ const lines = [
51
+ `Resource config for project ${project_id}`,
52
+ '─'.repeat(50),
53
+ `CPU: ${d.cpu ?? 0} cores (limit: ${proj.cpu_limit || '-'}, request: ${proj.cpu_request || '-'})`,
54
+ `Memory: ${d.memory_mb ?? 0} MB (limit: ${proj.memory_limit || '-'}, request: ${proj.memory_request || '-'})`,
55
+ `Storage: ${d.storage_gb ?? 0} GB (limit: ${proj.storage_limit || '-'})`,
56
+ `Replicas: ${d.replicas ?? 1}`,
57
+ '',
58
+ `Plan: ${pool.plan || 'unknown'}`,
59
+ `CPU pool: ${pool.cpu_used ?? 0}/${pool.cpu_total ?? 0} cores used`,
60
+ `Memory pool: ${pool.memory_used_mb ?? 0}/${pool.memory_total_mb ?? 0} MB used`,
61
+ `Storage pool: ${pool.storage_used_gb ?? 0}/${pool.storage_total_gb ?? 0} GB used`,
62
+ ];
63
+ return textResult(lines.join('\n'));
64
+ }
65
+
66
+ if (action === 'set') {
67
+ const body: Record<string, number> = {};
68
+ if (cpu !== undefined) body.cpu = cpu;
69
+ if (memory_mb !== undefined) body.memory_mb = memory_mb;
70
+ if (storage_gb !== undefined) body.storage_gb = storage_gb;
71
+ if (replicas !== undefined) body.replicas = replicas;
72
+ if (Object.keys(body).length === 0) {
73
+ return textResult('Error: specify at least one of cpu, memory_mb, storage_gb, replicas.');
74
+ }
75
+ const res = await apiRequest('PUT', `/projects/${project_id}/resource-config`, body);
76
+ if (!res.ok) return textResult(formatError(res));
77
+ const changed = Object.entries(body).map(([k, v]) => `${k}=${v}`).join(', ');
78
+ return textResult(`Resource config updated: ${changed}.\n\nChanges take effect on the next deploy (or use dailey_process_restart).`);
79
+ }
80
+
81
+ return textResult('Invalid action. Use get or set.');
82
+ },
83
+ );
84
+ }
@@ -2,18 +2,32 @@ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
2
  import { z } from 'zod';
3
3
  import { apiRequest, formatError, textResult } from '../api.js';
4
4
 
5
+ interface ScaleResponse {
6
+ scaled?: boolean;
7
+ replicas?: number;
8
+ warning?: string;
9
+ }
10
+
5
11
  export function registerScaleTools(server: McpServer) {
6
12
  server.tool(
7
13
  'dailey_scale',
8
- 'Scale project replicas up or down',
14
+ 'Scale project replicas up or down. Surfaces warnings if the DB updated but k8s did not apply (e.g., deployment missing).',
9
15
  {
10
16
  project_id: z.string().describe('The project ID'),
11
17
  replicas: z.number().describe('Number of replicas to scale to'),
12
18
  },
13
19
  async ({ project_id, replicas }) => {
14
- const res = await apiRequest('POST', `/projects/${project_id}/scale`, { replicas });
20
+ const res = await apiRequest<ScaleResponse>('POST', `/projects/${project_id}/scale`, { replicas });
15
21
  if (!res.ok) return textResult(formatError(res));
16
- return textResult(`Project ${project_id} scaled to ${replicas} replica(s).`);
22
+
23
+ const lines = [`Project ${project_id} scaled to ${replicas} replica(s).`];
24
+ if (res.data?.warning) {
25
+ lines.push('');
26
+ lines.push(`⚠ Warning: ${res.data.warning}`);
27
+ lines.push('');
28
+ lines.push('Next steps: check dailey_project_resources to see if pods are actually running. If the deployment is missing, trigger a redeploy.');
29
+ }
30
+ return textResult(lines.join('\n'));
17
31
  },
18
32
  );
19
33
  }
@@ -0,0 +1,149 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * End-to-end MCP-protocol smoke test.
4
+ *
5
+ * Spawns the compiled MCP server, speaks the JSON-RPC stdio protocol, lists
6
+ * all tools, and calls a representative read-only tool. This exercises the
7
+ * actual MCP surface LLMs see.
8
+ */
9
+ import { spawn } from 'node:child_process';
10
+ import path from 'node:path';
11
+
12
+ const binary = path.resolve(new URL('.', import.meta.url).pathname, '..', 'dist/index.js');
13
+
14
+ const env = {
15
+ ...process.env,
16
+ DAILEY_API_URL: process.env.DAILEY_API_URL || 'https://os.dailey.cloud/api',
17
+ DAILEY_EMAIL: process.env.DAILEY_EMAIL,
18
+ DAILEY_PASSWORD: process.env.DAILEY_PASSWORD,
19
+ };
20
+
21
+ if (!env.DAILEY_EMAIL || !env.DAILEY_PASSWORD) {
22
+ console.error('DAILEY_EMAIL and DAILEY_PASSWORD must be set');
23
+ process.exit(1);
24
+ }
25
+
26
+ const child = spawn('node', [binary], { env, stdio: ['pipe', 'pipe', 'pipe'] });
27
+
28
+ let nextId = 1;
29
+ const pending = new Map();
30
+ let buffer = '';
31
+
32
+ child.stdout.on('data', (chunk) => {
33
+ buffer += chunk.toString();
34
+ const lines = buffer.split('\n');
35
+ buffer = lines.pop();
36
+ for (const line of lines) {
37
+ if (!line.trim()) continue;
38
+ try {
39
+ const msg = JSON.parse(line);
40
+ if (msg.id && pending.has(msg.id)) {
41
+ const { resolve } = pending.get(msg.id);
42
+ pending.delete(msg.id);
43
+ resolve(msg);
44
+ }
45
+ } catch { /* ignore */ }
46
+ }
47
+ });
48
+
49
+ child.stderr.on('data', (chunk) => {
50
+ process.stderr.write(`[mcp-server] ${chunk}`);
51
+ });
52
+
53
+ function send(method, params) {
54
+ return new Promise((resolve, reject) => {
55
+ const id = nextId++;
56
+ pending.set(id, { resolve, reject });
57
+ child.stdin.write(JSON.stringify({ jsonrpc: '2.0', id, method, params }) + '\n');
58
+ setTimeout(() => {
59
+ if (pending.has(id)) {
60
+ pending.delete(id);
61
+ reject(new Error(`Timeout waiting for ${method}`));
62
+ }
63
+ }, 15000);
64
+ });
65
+ }
66
+
67
+ async function main() {
68
+ console.log('Spawning MCP server...');
69
+
70
+ // MCP handshake
71
+ const init = await send('initialize', {
72
+ protocolVersion: '2024-11-05',
73
+ capabilities: {},
74
+ clientInfo: { name: 'smoke-test', version: '1.0.0' },
75
+ });
76
+ console.log(`✓ initialized (server: ${init.result?.serverInfo?.name} v${init.result?.serverInfo?.version})`);
77
+
78
+ // Notify initialized (required by some clients)
79
+ child.stdin.write(JSON.stringify({ jsonrpc: '2.0', method: 'notifications/initialized' }) + '\n');
80
+
81
+ // List tools
82
+ const toolsMsg = await send('tools/list', {});
83
+ const tools = toolsMsg.result?.tools || [];
84
+ console.log(`✓ tools/list returned ${tools.length} tools`);
85
+
86
+ const expected = [
87
+ 'dailey_whoami',
88
+ 'dailey_list_projects',
89
+ 'dailey_project_info',
90
+ 'dailey_deploy_status',
91
+ 'dailey_build_logs',
92
+ 'dailey_processes',
93
+ 'dailey_process_logs',
94
+ 'dailey_process_restart',
95
+ 'dailey_process_metrics',
96
+ 'dailey_process_resources',
97
+ 'dailey_pause',
98
+ 'dailey_resume',
99
+ 'dailey_backups',
100
+ 'dailey_resource_config',
101
+ 'dailey_service_links',
102
+ 'dailey_reveal_credential',
103
+ 'dailey_analyze_repo',
104
+ 'dailey_db_validate',
105
+ 'dailey_db_tunnel',
106
+ 'dailey_scale',
107
+ 'dailey_domains',
108
+ ];
109
+
110
+ const names = new Set(tools.map((t) => t.name));
111
+ const missing = expected.filter((n) => !names.has(n));
112
+ if (missing.length) {
113
+ console.log(`✗ missing tools: ${missing.join(', ')}`);
114
+ process.exit(1);
115
+ }
116
+ console.log(`✓ all expected new tools registered`);
117
+
118
+ // Call a real tool — dailey_whoami — to verify end-to-end flow.
119
+ const whoamiMsg = await send('tools/call', { name: 'dailey_whoami', arguments: {} });
120
+ const text = whoamiMsg.result?.content?.[0]?.text || '';
121
+ if (!text.includes('@') && !text.toLowerCase().includes('email')) {
122
+ console.log(`✗ dailey_whoami returned unexpected output: ${text.slice(0, 100)}`);
123
+ process.exit(1);
124
+ }
125
+ console.log(`✓ dailey_whoami call succeeded (${text.split('\n')[0]})`);
126
+
127
+ // Call a new tool — dailey_analyze_repo on nginx:alpine.
128
+ const analyzeMsg = await send('tools/call', {
129
+ name: 'dailey_analyze_repo',
130
+ arguments: { repo_url: 'nginx:alpine' },
131
+ });
132
+ const analyzeText = analyzeMsg.result?.content?.[0]?.text || '';
133
+ if (!analyzeText.includes('Analysis') || !analyzeText.includes('nginx:alpine')) {
134
+ console.log(`✗ dailey_analyze_repo returned unexpected output: ${analyzeText.slice(0, 200)}`);
135
+ process.exit(1);
136
+ }
137
+ console.log(`✓ dailey_analyze_repo call succeeded`);
138
+
139
+ child.kill();
140
+ console.log('');
141
+ console.log(`All checks passed. ${tools.length} tools registered, new tools callable.`);
142
+ process.exit(0);
143
+ }
144
+
145
+ main().catch((err) => {
146
+ console.error('TEST CRASH:', err);
147
+ child.kill();
148
+ process.exit(2);
149
+ });