@daileyos/mcp-server 1.9.1 → 1.11.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.
- package/dist/api.d.ts +13 -0
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +78 -4
- package/dist/api.js.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/tools/cli.js +1 -1
- package/dist/tools/cli.js.map +1 -1
- package/dist/tools/diagnose.d.ts +3 -0
- package/dist/tools/diagnose.d.ts.map +1 -0
- package/dist/tools/diagnose.js +328 -0
- package/dist/tools/diagnose.js.map +1 -0
- package/dist/tools/env.d.ts.map +1 -1
- package/dist/tools/env.js +80 -3
- package/dist/tools/env.js.map +1 -1
- package/dist/tools/projects.d.ts.map +1 -1
- package/dist/tools/projects.js +37 -1
- package/dist/tools/projects.js.map +1 -1
- package/dist/tools/storage.d.ts.map +1 -1
- package/dist/tools/storage.js +28 -4
- package/dist/tools/storage.js.map +1 -1
- package/package.json +1 -1
- package/src/api.ts +76 -4
- package/src/index.ts +4 -0
- package/src/tools/cli.ts +1 -1
- package/src/tools/diagnose.ts +384 -0
- package/src/tools/env.ts +127 -6
- package/src/tools/projects.ts +38 -3
- package/src/tools/storage.ts +27 -4
- package/tests/pack6-smoke.mjs +222 -0
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { apiRequest, textResult } from '../api.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* dailey_diagnose — single MCP tool that runs every health check and returns
|
|
7
|
+
* a structured summary. Customer-feedback Scott Waters platform-wishlist
|
|
8
|
+
* 2026-04-25, section 8: "the kind of thing an AI agent reaches for when a
|
|
9
|
+
* customer says 'something's broken.'"
|
|
10
|
+
*
|
|
11
|
+
* Strategy: piggyback on existing endpoints (deploy-status, /resources,
|
|
12
|
+
* /storage, /database, /env/runtime, /logs). No new backend endpoints.
|
|
13
|
+
* Calls run in parallel; each lane is wrapped so one failing lane doesn't
|
|
14
|
+
* abort the rest. Final verdict aggregates lane-level statuses into one
|
|
15
|
+
* of: healthy / degraded / broken.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
type LaneStatus = 'ok' | 'warn' | 'fail' | 'skip';
|
|
19
|
+
|
|
20
|
+
interface Lane {
|
|
21
|
+
name: string;
|
|
22
|
+
status: LaneStatus;
|
|
23
|
+
summary: string;
|
|
24
|
+
detail?: Record<string, unknown>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface ProjectListEntry {
|
|
28
|
+
id: string;
|
|
29
|
+
name?: string;
|
|
30
|
+
slug?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const ERROR_LINE_PATTERN = /(error|fatal|panic|exception|uncaught|unhandled)/i;
|
|
34
|
+
|
|
35
|
+
async function resolveProjectId(
|
|
36
|
+
projectOrSlug: string,
|
|
37
|
+
): Promise<{ id: string | null; matched_by: 'id' | 'slug' | 'name' | 'none'; hint?: string }> {
|
|
38
|
+
// Try as ID first — a UUID-shaped string is almost always a real ID.
|
|
39
|
+
const looksLikeId = /^[0-9a-f-]{8,}$/i.test(projectOrSlug);
|
|
40
|
+
if (looksLikeId) {
|
|
41
|
+
const direct = await apiRequest<any>('GET', `/projects/${projectOrSlug}`);
|
|
42
|
+
if (direct.ok) return { id: projectOrSlug, matched_by: 'id' };
|
|
43
|
+
// fall through to slug lookup if 404
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const list = await apiRequest<{ projects: ProjectListEntry[] }>('GET', '/projects');
|
|
47
|
+
if (!list.ok) {
|
|
48
|
+
return { id: null, matched_by: 'none', hint: 'Could not list projects to resolve slug.' };
|
|
49
|
+
}
|
|
50
|
+
const projects = list.data.projects || [];
|
|
51
|
+
const bySlug = projects.find((p) => p.slug === projectOrSlug);
|
|
52
|
+
if (bySlug?.id) return { id: bySlug.id, matched_by: 'slug' };
|
|
53
|
+
const byName = projects.find((p) => p.name === projectOrSlug);
|
|
54
|
+
if (byName?.id) return { id: byName.id, matched_by: 'name' };
|
|
55
|
+
return { id: null, matched_by: 'none', hint: `No project found matching "${projectOrSlug}".` };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async function checkDeploy(projectId: string): Promise<Lane> {
|
|
59
|
+
const status = await apiRequest<any>('GET', `/projects/${projectId}/deploy-status`);
|
|
60
|
+
if (!status.ok) {
|
|
61
|
+
return { name: 'deploy', status: 'fail', summary: `deploy-status returned ${status.status}` };
|
|
62
|
+
}
|
|
63
|
+
const builds = await apiRequest<{ builds: any[] }>('GET', `/projects/${projectId}/deploys`);
|
|
64
|
+
const latest = builds.ok ? builds.data.builds?.[0] : null;
|
|
65
|
+
const deployedAt = status.data.deployed_at;
|
|
66
|
+
const isBuilding = !!status.data.is_building;
|
|
67
|
+
|
|
68
|
+
let laneStatus: LaneStatus = 'ok';
|
|
69
|
+
let summary = `Deployed ${deployedAt || 'never'}`;
|
|
70
|
+
|
|
71
|
+
if (latest?.status === 'failed') {
|
|
72
|
+
laneStatus = 'fail';
|
|
73
|
+
summary = `Latest build ${latest.id} failed (${latest.finished_at || 'unknown time'}).`;
|
|
74
|
+
} else if (isBuilding) {
|
|
75
|
+
laneStatus = 'warn';
|
|
76
|
+
summary = `Build in progress (${latest?.id || 'unknown'}).`;
|
|
77
|
+
} else if (!deployedAt) {
|
|
78
|
+
laneStatus = 'warn';
|
|
79
|
+
summary = 'Project has never been deployed.';
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
name: 'deploy',
|
|
84
|
+
status: laneStatus,
|
|
85
|
+
summary,
|
|
86
|
+
detail: {
|
|
87
|
+
mode: status.data.mode,
|
|
88
|
+
deployed_at: deployedAt,
|
|
89
|
+
is_building: isBuilding,
|
|
90
|
+
can_deploy: status.data.can_deploy,
|
|
91
|
+
latest_build: latest
|
|
92
|
+
? { id: latest.id, status: latest.status, finished_at: latest.finished_at }
|
|
93
|
+
: null,
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async function checkPods(projectId: string): Promise<Lane> {
|
|
99
|
+
// /resources is the single-call source for pod ready/total + restart counts.
|
|
100
|
+
const res = await apiRequest<any>('GET', `/projects/${projectId}/resources`);
|
|
101
|
+
if (!res.ok) {
|
|
102
|
+
return {
|
|
103
|
+
name: 'pods',
|
|
104
|
+
status: 'fail',
|
|
105
|
+
summary: `Could not fetch pod resources (${res.status}).`,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
const pods = res.data.pods || [];
|
|
109
|
+
const ready = pods.filter((p: any) => p.ready === true).length;
|
|
110
|
+
const total = pods.length;
|
|
111
|
+
const restarts = pods.reduce((sum: number, p: any) => sum + (p.restarts || 0), 0);
|
|
112
|
+
|
|
113
|
+
// Recent crash reasons — pull anything the API exposes per pod.
|
|
114
|
+
const crashReasons: string[] = [];
|
|
115
|
+
for (const p of pods) {
|
|
116
|
+
if (p.last_termination_reason) crashReasons.push(`${p.name || '?'}: ${p.last_termination_reason}`);
|
|
117
|
+
if (p.status && p.status !== 'Running' && p.status !== 'Pending') {
|
|
118
|
+
crashReasons.push(`${p.name || '?'}: ${p.status}`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
let laneStatus: LaneStatus = 'ok';
|
|
123
|
+
let summary = `${ready}/${total} pods ready, ${restarts} total restarts`;
|
|
124
|
+
|
|
125
|
+
if (total === 0) {
|
|
126
|
+
laneStatus = 'warn';
|
|
127
|
+
summary = 'No pods running. Project may be paused or never deployed.';
|
|
128
|
+
} else if (ready === 0) {
|
|
129
|
+
laneStatus = 'fail';
|
|
130
|
+
summary = `0/${total} pods ready — service is down.`;
|
|
131
|
+
} else if (ready < total) {
|
|
132
|
+
laneStatus = 'warn';
|
|
133
|
+
summary = `${ready}/${total} pods ready (some not ready).`;
|
|
134
|
+
} else if (restarts > 5) {
|
|
135
|
+
laneStatus = 'warn';
|
|
136
|
+
summary = `${ready}/${total} pods ready but ${restarts} restarts — investigate.`;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return {
|
|
140
|
+
name: 'pods',
|
|
141
|
+
status: laneStatus,
|
|
142
|
+
summary,
|
|
143
|
+
detail: {
|
|
144
|
+
pods_ready: ready,
|
|
145
|
+
pods_total: total,
|
|
146
|
+
total_restarts: restarts,
|
|
147
|
+
crash_reasons: crashReasons.slice(0, 5),
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
async function checkStorage(projectId: string): Promise<Lane> {
|
|
153
|
+
// Piggyback on /storage. A successful response means the binding row
|
|
154
|
+
// exists and the platform-side storage info is reachable. The full
|
|
155
|
+
// "HeadBucket with auto-injected creds" probe needs a backend extension
|
|
156
|
+
// (tracked separately); for now, "binding info reachable" is the proxy.
|
|
157
|
+
const res = await apiRequest<any>('GET', `/projects/${projectId}/storage`);
|
|
158
|
+
if (!res.ok) {
|
|
159
|
+
if (res.status === 404) {
|
|
160
|
+
return { name: 'storage', status: 'skip', summary: 'No storage binding for this project.' };
|
|
161
|
+
}
|
|
162
|
+
return {
|
|
163
|
+
name: 'storage',
|
|
164
|
+
status: 'fail',
|
|
165
|
+
summary: `Could not fetch storage info (${res.status}).`,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
const binding = res.data.binding || {};
|
|
169
|
+
const usage = binding.usage || {};
|
|
170
|
+
return {
|
|
171
|
+
name: 'storage',
|
|
172
|
+
status: 'ok',
|
|
173
|
+
summary: `Bucket ${binding.bucket || '?'} reachable (${usage.total_objects || 0} objects, ${usage.total_size_mb || 0} MB).`,
|
|
174
|
+
detail: {
|
|
175
|
+
bucket: binding.bucket,
|
|
176
|
+
provider: binding.provider,
|
|
177
|
+
objects: usage.total_objects,
|
|
178
|
+
size_mb: usage.total_size_mb,
|
|
179
|
+
// The auto-injected `<slug>-storage-credentials` secret is created and
|
|
180
|
+
// refreshed by storage-credential-refresher (24h cycle). A binding row
|
|
181
|
+
// present + storage info endpoint OK is strong evidence the secret is
|
|
182
|
+
// valid; a HeadBucket probe with the per-pod creds would be stronger
|
|
183
|
+
// and is a planned backend addition.
|
|
184
|
+
note: 'Per-pod cred HeadBucket probe pending backend extension.',
|
|
185
|
+
},
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
async function checkDatabase(projectId: string): Promise<Lane> {
|
|
190
|
+
const info = await apiRequest<any>('GET', `/projects/${projectId}/database`);
|
|
191
|
+
if (!info.ok) {
|
|
192
|
+
return {
|
|
193
|
+
name: 'database',
|
|
194
|
+
status: 'fail',
|
|
195
|
+
summary: `Could not fetch database info (${info.status}).`,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
// A project without a managed DB returns either status='not-configured' or
|
|
199
|
+
// an error mode. Either way → skip lane, not fail.
|
|
200
|
+
if (!info.data.host || info.data.status === 'not-configured') {
|
|
201
|
+
return { name: 'database', status: 'skip', summary: 'No managed database for this project.' };
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const startedAt = Date.now();
|
|
205
|
+
const probe = await apiRequest<any>('POST', `/projects/${projectId}/database/exec`, {
|
|
206
|
+
sql: 'SELECT 1',
|
|
207
|
+
confirm: false,
|
|
208
|
+
});
|
|
209
|
+
const latencyMs = Date.now() - startedAt;
|
|
210
|
+
|
|
211
|
+
if (!probe.ok) {
|
|
212
|
+
return {
|
|
213
|
+
name: 'database',
|
|
214
|
+
status: 'fail',
|
|
215
|
+
summary: `SELECT 1 failed (${probe.status}). DB is unreachable or auth is broken.`,
|
|
216
|
+
detail: { latency_ms: latencyMs, error: probe.data },
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
return {
|
|
220
|
+
name: 'database',
|
|
221
|
+
status: 'ok',
|
|
222
|
+
summary: `SELECT 1 OK in ${latencyMs}ms (${info.data.type || 'db'}).`,
|
|
223
|
+
detail: {
|
|
224
|
+
type: info.data.type,
|
|
225
|
+
database: info.data.database,
|
|
226
|
+
latency_ms: latencyMs,
|
|
227
|
+
},
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
async function checkEnv(projectId: string): Promise<Lane> {
|
|
232
|
+
const res = await apiRequest<any>('GET', `/projects/${projectId}/env/runtime`);
|
|
233
|
+
if (!res.ok) {
|
|
234
|
+
return {
|
|
235
|
+
name: 'env',
|
|
236
|
+
status: 'fail',
|
|
237
|
+
summary: `Could not fetch runtime env (${res.status}).`,
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
if (res.data.no_deployment) {
|
|
241
|
+
return { name: 'env', status: 'skip', summary: 'No deployment yet — env vars are injected at pod start.' };
|
|
242
|
+
}
|
|
243
|
+
const counts = res.data.counts || {};
|
|
244
|
+
const customer = counts.customer || 0;
|
|
245
|
+
// Anything that isn't customer-set is platform-injected.
|
|
246
|
+
const platform = Object.entries(counts)
|
|
247
|
+
.filter(([k]) => k !== 'customer')
|
|
248
|
+
.reduce((sum, [, n]) => sum + (n as number), 0);
|
|
249
|
+
return {
|
|
250
|
+
name: 'env',
|
|
251
|
+
status: 'ok',
|
|
252
|
+
summary: `${customer} customer-set + ${platform} platform-injected env vars.`,
|
|
253
|
+
detail: { customer, platform, by_source: counts },
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
async function checkRecentErrors(projectId: string): Promise<Lane> {
|
|
258
|
+
const res = await apiRequest<{ logs?: string[] }>('GET', `/projects/${projectId}/logs?tail=50`);
|
|
259
|
+
if (!res.ok) {
|
|
260
|
+
return { name: 'errors', status: 'skip', summary: 'No logs available (project may be paused).' };
|
|
261
|
+
}
|
|
262
|
+
const lines = res.data.logs || [];
|
|
263
|
+
const matches = lines.filter((line) => ERROR_LINE_PATTERN.test(line));
|
|
264
|
+
if (matches.length === 0) {
|
|
265
|
+
return { name: 'errors', status: 'ok', summary: 'No error/fatal/panic in last 50 log lines.' };
|
|
266
|
+
}
|
|
267
|
+
// Heuristic: many error matches in 50 lines is a real fire. A handful of
|
|
268
|
+
// routine "level=error" lines is normal noise — flag warn, not fail.
|
|
269
|
+
const laneStatus: LaneStatus = matches.length >= 10 ? 'fail' : 'warn';
|
|
270
|
+
return {
|
|
271
|
+
name: 'errors',
|
|
272
|
+
status: laneStatus,
|
|
273
|
+
summary: `${matches.length} error/fatal/panic line(s) in last 50.`,
|
|
274
|
+
detail: { matches: matches.slice(0, 5) },
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
function aggregateVerdict(lanes: Lane[]): { verdict: 'healthy' | 'degraded' | 'broken'; summary: string } {
|
|
279
|
+
const hasFail = lanes.some((l) => l.status === 'fail');
|
|
280
|
+
const hasWarn = lanes.some((l) => l.status === 'warn');
|
|
281
|
+
|
|
282
|
+
if (hasFail) {
|
|
283
|
+
const failingLanes = lanes.filter((l) => l.status === 'fail').map((l) => l.name);
|
|
284
|
+
const allFailures = lanes
|
|
285
|
+
.filter((l) => l.status === 'fail')
|
|
286
|
+
.map((l) => `${l.name}: ${l.summary}`)
|
|
287
|
+
.join(' ');
|
|
288
|
+
return {
|
|
289
|
+
verdict: 'broken',
|
|
290
|
+
summary: `Project is broken. Failing checks: ${failingLanes.join(', ')}. ${allFailures}`,
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
if (hasWarn) {
|
|
294
|
+
const warnLanes = lanes.filter((l) => l.status === 'warn');
|
|
295
|
+
const detail = warnLanes.map((l) => `${l.name}: ${l.summary}`).join(' ');
|
|
296
|
+
return {
|
|
297
|
+
verdict: 'degraded',
|
|
298
|
+
summary: `Project is degraded but not down. ${detail}`,
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
const okCount = lanes.filter((l) => l.status === 'ok').length;
|
|
302
|
+
const skipped = lanes.filter((l) => l.status === 'skip').map((l) => l.name);
|
|
303
|
+
let summary = `Project looks healthy. ${okCount} checks passed.`;
|
|
304
|
+
if (skipped.length) summary += ` Skipped: ${skipped.join(', ')}.`;
|
|
305
|
+
return { verdict: 'healthy', summary };
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
export function registerDiagnoseTools(server: McpServer) {
|
|
309
|
+
server.tool(
|
|
310
|
+
'dailey_diagnose',
|
|
311
|
+
'FIRST tool to reach for when a customer says "something is broken." Runs every health check (deploy, pods, storage, database, env vars, recent log errors) for a project in parallel and returns a structured summary with an overall verdict (healthy/degraded/broken). Output includes a top-level `summary` string an AI agent can render directly to the user. Accepts either a project ID or a slug.',
|
|
312
|
+
{
|
|
313
|
+
project: z.string().describe('Project ID or slug — the tool resolves either.'),
|
|
314
|
+
},
|
|
315
|
+
async ({ project }) => {
|
|
316
|
+
const resolved = await resolveProjectId(project);
|
|
317
|
+
if (!resolved.id) {
|
|
318
|
+
return textResult(
|
|
319
|
+
JSON.stringify(
|
|
320
|
+
{
|
|
321
|
+
verdict: 'broken',
|
|
322
|
+
summary: resolved.hint || `Could not resolve "${project}" to a project.`,
|
|
323
|
+
project_input: project,
|
|
324
|
+
matched_by: resolved.matched_by,
|
|
325
|
+
},
|
|
326
|
+
null,
|
|
327
|
+
2,
|
|
328
|
+
),
|
|
329
|
+
);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
const projectId = resolved.id;
|
|
333
|
+
// Run every lane in parallel — one slow lane shouldn't block the rest.
|
|
334
|
+
const lanes = await Promise.all([
|
|
335
|
+
checkDeploy(projectId).catch((err) => ({
|
|
336
|
+
name: 'deploy',
|
|
337
|
+
status: 'fail' as LaneStatus,
|
|
338
|
+
summary: `lane crashed: ${err.message}`,
|
|
339
|
+
})),
|
|
340
|
+
checkPods(projectId).catch((err) => ({
|
|
341
|
+
name: 'pods',
|
|
342
|
+
status: 'fail' as LaneStatus,
|
|
343
|
+
summary: `lane crashed: ${err.message}`,
|
|
344
|
+
})),
|
|
345
|
+
checkStorage(projectId).catch((err) => ({
|
|
346
|
+
name: 'storage',
|
|
347
|
+
status: 'fail' as LaneStatus,
|
|
348
|
+
summary: `lane crashed: ${err.message}`,
|
|
349
|
+
})),
|
|
350
|
+
checkDatabase(projectId).catch((err) => ({
|
|
351
|
+
name: 'database',
|
|
352
|
+
status: 'fail' as LaneStatus,
|
|
353
|
+
summary: `lane crashed: ${err.message}`,
|
|
354
|
+
})),
|
|
355
|
+
checkEnv(projectId).catch((err) => ({
|
|
356
|
+
name: 'env',
|
|
357
|
+
status: 'fail' as LaneStatus,
|
|
358
|
+
summary: `lane crashed: ${err.message}`,
|
|
359
|
+
})),
|
|
360
|
+
checkRecentErrors(projectId).catch((err) => ({
|
|
361
|
+
name: 'errors',
|
|
362
|
+
status: 'fail' as LaneStatus,
|
|
363
|
+
summary: `lane crashed: ${err.message}`,
|
|
364
|
+
})),
|
|
365
|
+
]);
|
|
366
|
+
|
|
367
|
+
const { verdict, summary } = aggregateVerdict(lanes);
|
|
368
|
+
|
|
369
|
+
const payload = {
|
|
370
|
+
project_id: projectId,
|
|
371
|
+
project_input: project,
|
|
372
|
+
matched_by: resolved.matched_by,
|
|
373
|
+
verdict,
|
|
374
|
+
summary,
|
|
375
|
+
checks: lanes.reduce<Record<string, Lane>>((acc, lane) => {
|
|
376
|
+
acc[lane.name] = lane;
|
|
377
|
+
return acc;
|
|
378
|
+
}, {}),
|
|
379
|
+
};
|
|
380
|
+
|
|
381
|
+
return textResult(JSON.stringify(payload, null, 2));
|
|
382
|
+
},
|
|
383
|
+
);
|
|
384
|
+
}
|
package/src/tools/env.ts
CHANGED
|
@@ -7,6 +7,45 @@ interface EnvVar {
|
|
|
7
7
|
updated_at?: string;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
interface RuntimeEnvVar {
|
|
11
|
+
key: string;
|
|
12
|
+
source: string;
|
|
13
|
+
source_name: string | null;
|
|
14
|
+
length: number;
|
|
15
|
+
preview: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface RuntimeEnvListing {
|
|
19
|
+
project_id: string;
|
|
20
|
+
project_slug: string;
|
|
21
|
+
namespace: string;
|
|
22
|
+
no_deployment: boolean;
|
|
23
|
+
env_vars: RuntimeEnvVar[];
|
|
24
|
+
counts: Record<string, number>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface ValidationWarning {
|
|
28
|
+
key: string;
|
|
29
|
+
expected_length: number;
|
|
30
|
+
actual_length: number | null;
|
|
31
|
+
reason: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Append validate-on-set warnings to a tool's text response. Returns an
|
|
35
|
+
* empty string when there are none, so call sites can interpolate
|
|
36
|
+
* unconditionally. Customer-feedback Scott Waters wishlist #5. */
|
|
37
|
+
function formatValidationWarnings(warnings: ValidationWarning[] | undefined): string {
|
|
38
|
+
if (!Array.isArray(warnings) || warnings.length === 0) return '';
|
|
39
|
+
const lines = ['', 'Validation warnings (value still saved, but couldn\'t confirm in pod secret):'];
|
|
40
|
+
for (const w of warnings) {
|
|
41
|
+
const lengths = w.actual_length === null
|
|
42
|
+
? `expected ${w.expected_length} bytes`
|
|
43
|
+
: `expected ${w.expected_length}, got ${w.actual_length}`;
|
|
44
|
+
lines.push(` · ${w.key}: ${w.reason} (${lengths})`);
|
|
45
|
+
}
|
|
46
|
+
return '\n' + lines.join('\n');
|
|
47
|
+
}
|
|
48
|
+
|
|
10
49
|
export function registerEnvTools(server: McpServer) {
|
|
11
50
|
server.tool(
|
|
12
51
|
'dailey_env_vars',
|
|
@@ -45,28 +84,38 @@ export function registerEnvTools(server: McpServer) {
|
|
|
45
84
|
return textResult('Error: key and value are required for set action.');
|
|
46
85
|
}
|
|
47
86
|
// Try PUT first (update), fall back to POST (create)
|
|
48
|
-
const putRes = await apiRequest
|
|
87
|
+
const putRes = await apiRequest<{ updated: boolean; key?: string; validation_warnings?: ValidationWarning[] }>(
|
|
88
|
+
'PUT',
|
|
89
|
+
`/projects/${project_id}/env/${encodeURIComponent(key)}`,
|
|
90
|
+
{ value },
|
|
91
|
+
);
|
|
49
92
|
if (putRes.ok) {
|
|
50
|
-
return textResult(`Environment variable ${key} updated
|
|
93
|
+
return textResult(`Environment variable ${key} updated.${formatValidationWarnings(putRes.data?.validation_warnings)}`);
|
|
51
94
|
}
|
|
52
95
|
// If PUT fails (var doesn't exist yet), try POST
|
|
53
|
-
const postRes = await apiRequest
|
|
96
|
+
const postRes = await apiRequest<{ set: boolean; key?: string; validation_warnings?: ValidationWarning[] }>(
|
|
97
|
+
'POST',
|
|
98
|
+
`/projects/${project_id}/env`,
|
|
99
|
+
{ key, value },
|
|
100
|
+
);
|
|
54
101
|
if (!postRes.ok) return textResult(formatError(postRes));
|
|
55
|
-
return textResult(`Environment variable ${key} set
|
|
102
|
+
return textResult(`Environment variable ${key} set.${formatValidationWarnings(postRes.data?.validation_warnings)}`);
|
|
56
103
|
}
|
|
57
104
|
|
|
58
105
|
if (action === 'set_many') {
|
|
59
106
|
if (!env_vars || Object.keys(env_vars).length === 0) {
|
|
60
107
|
return textResult('Error: env_vars object is required for set_many action.');
|
|
61
108
|
}
|
|
62
|
-
const res = await apiRequest<{ set: boolean; count: number; keys: string[] }>(
|
|
109
|
+
const res = await apiRequest<{ set: boolean; count: number; keys: string[]; validation_warnings?: ValidationWarning[] }>(
|
|
63
110
|
'POST',
|
|
64
111
|
`/projects/${project_id}/env`,
|
|
65
112
|
{ env_vars },
|
|
66
113
|
);
|
|
67
114
|
if (!res.ok) return textResult(formatError(res));
|
|
68
115
|
const d = res.data || {} as any;
|
|
69
|
-
return textResult(
|
|
116
|
+
return textResult(
|
|
117
|
+
`Set ${d.count ?? Object.keys(env_vars).length} environment variables: ${(d.keys || Object.keys(env_vars)).join(', ')}${formatValidationWarnings(d.validation_warnings)}`,
|
|
118
|
+
);
|
|
70
119
|
}
|
|
71
120
|
|
|
72
121
|
if (action === 'delete') {
|
|
@@ -81,4 +130,76 @@ export function registerEnvTools(server: McpServer) {
|
|
|
81
130
|
return textResult('Error: Invalid action. Use list, set, or delete.');
|
|
82
131
|
},
|
|
83
132
|
);
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* dailey_env_runtime_list — what the pod will actually see.
|
|
136
|
+
*
|
|
137
|
+
* Customer-feedback Scott Waters platform-wishlist 2026-04-25. The
|
|
138
|
+
* existing dailey_env_vars list action only shows customer-set vars;
|
|
139
|
+
* this tool walks the project's k8s Deployment spec and returns every
|
|
140
|
+
* key the pod will receive at runtime, including platform-injected
|
|
141
|
+
* ones (S3_*, DATABASE_URL, AUTH_*) tagged by source. Values are
|
|
142
|
+
* redacted server-side; the response includes length + first-4 +
|
|
143
|
+
* last-4 preview so debugging "is FOO actually set?" doesn't leak
|
|
144
|
+
* raw bytes.
|
|
145
|
+
*/
|
|
146
|
+
server.tool(
|
|
147
|
+
'dailey_env_runtime_list',
|
|
148
|
+
"Returns every env var the project's pod will see at runtime, including platform-injected ones (S3_*, DATABASE_URL, etc.) — values redacted but lengths shown. Use this when debugging 'is the env var I expect actually present in the pod?'.",
|
|
149
|
+
{ project_id: z.string().describe('The project ID') },
|
|
150
|
+
async ({ project_id }) => {
|
|
151
|
+
const res = await apiRequest<RuntimeEnvListing>('GET', `/projects/${project_id}/env/runtime`);
|
|
152
|
+
if (!res.ok) return textResult(formatError(res));
|
|
153
|
+
|
|
154
|
+
const data = res.data;
|
|
155
|
+
if (data.no_deployment) {
|
|
156
|
+
return textResult('No deployment found for this project. Run `dailey deploy` (or call dailey_deploy) first — env vars only exist on the deployed pod.');
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const sourceLabel: Record<string, string> = {
|
|
160
|
+
'customer': 'customer',
|
|
161
|
+
'platform-storage': 'storage',
|
|
162
|
+
'platform-db': 'db',
|
|
163
|
+
'platform-auth': 'auth',
|
|
164
|
+
'platform-other': 'platform',
|
|
165
|
+
'inline': 'inline',
|
|
166
|
+
'field-ref': 'downward',
|
|
167
|
+
'config-map': 'configmap',
|
|
168
|
+
'unknown': '?',
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
const lines = [
|
|
172
|
+
`Runtime env: ${data.project_slug}`,
|
|
173
|
+
`Namespace: ${data.namespace}`,
|
|
174
|
+
`Total keys: ${data.env_vars.length}`,
|
|
175
|
+
'',
|
|
176
|
+
];
|
|
177
|
+
|
|
178
|
+
// Group by source for readability — AI agents pattern-match a lot
|
|
179
|
+
// better when "all the platform-storage stuff" is contiguous than
|
|
180
|
+
// when keys are alphabetic across all sources.
|
|
181
|
+
const grouped = new Map<string, RuntimeEnvVar[]>();
|
|
182
|
+
for (const v of data.env_vars) {
|
|
183
|
+
const arr = grouped.get(v.source) || [];
|
|
184
|
+
arr.push(v);
|
|
185
|
+
grouped.set(v.source, arr);
|
|
186
|
+
}
|
|
187
|
+
const sourceOrder = ['customer', 'platform-storage', 'platform-db', 'platform-auth', 'platform-other', 'inline', 'field-ref', 'config-map', 'unknown'];
|
|
188
|
+
for (const source of sourceOrder) {
|
|
189
|
+
const vars = grouped.get(source);
|
|
190
|
+
if (!vars || vars.length === 0) continue;
|
|
191
|
+
lines.push(`[${sourceLabel[source] || source}] (${vars.length})`);
|
|
192
|
+
for (const v of vars) {
|
|
193
|
+
const lengthStr = v.length === -1 ? '-' : String(v.length);
|
|
194
|
+
const sourceName = v.source_name ? ` ← ${v.source_name}` : '';
|
|
195
|
+
lines.push(` ${v.key.padEnd(30)} ${lengthStr.padStart(5)}B ${v.preview}${sourceName}`);
|
|
196
|
+
}
|
|
197
|
+
lines.push('');
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
lines.push('Values redacted server-side. Customer-set keys can be rotated via dailey_env_vars(action: set).');
|
|
201
|
+
|
|
202
|
+
return textResult(lines.join('\n'));
|
|
203
|
+
},
|
|
204
|
+
);
|
|
84
205
|
}
|
package/src/tools/projects.ts
CHANGED
|
@@ -239,9 +239,44 @@ export function registerProjectTools(server: McpServer) {
|
|
|
239
239
|
|
|
240
240
|
server.tool(
|
|
241
241
|
'dailey_delete_project',
|
|
242
|
-
'Delete a project (
|
|
243
|
-
{
|
|
244
|
-
|
|
242
|
+
'Delete a project — IRREVERSIBLE. Tears down Deployment, Service, Ingress, Secrets, DB, R2 prefix, DNS. Requires confirm=true to actually delete; calling without confirm returns the project\'s current state + a summary of what would be destroyed so you can verify before committing. (Pitfall #15)',
|
|
243
|
+
{
|
|
244
|
+
project_id: z.string().describe('The project ID to delete'),
|
|
245
|
+
confirm: z.boolean().optional().describe('MUST be true to actually delete. Default false — returns preview only.'),
|
|
246
|
+
},
|
|
247
|
+
async ({ project_id, confirm }) => {
|
|
248
|
+
if (!confirm) {
|
|
249
|
+
// Preview what would be deleted.
|
|
250
|
+
const info = await apiRequest<any>('GET', `/projects/${project_id}`);
|
|
251
|
+
if (!info.ok) return textResult(formatError(info));
|
|
252
|
+
const p = info.data;
|
|
253
|
+
const lines = [
|
|
254
|
+
`⚠ DELETE PREVIEW — not executed. Re-call with confirm=true to destroy.`,
|
|
255
|
+
'',
|
|
256
|
+
`Project: ${p.name} (${p.slug})`,
|
|
257
|
+
`ID: ${p.id}`,
|
|
258
|
+
`Status: ${p.status}`,
|
|
259
|
+
`Namespace: ${p.namespace || '-'}`,
|
|
260
|
+
`Database: ${p.database_name ? `${p.database_name} (${p.database_type})` : 'none'}`,
|
|
261
|
+
`URL: ${p.url || 'none'}`,
|
|
262
|
+
`Replicas: ${p.replicas ?? '-'}`,
|
|
263
|
+
'',
|
|
264
|
+
'Will be destroyed:',
|
|
265
|
+
' • k8s Deployment + Service + Ingress in namespace',
|
|
266
|
+
' • All Secrets (db creds, env, storage creds if project-local)',
|
|
267
|
+
' • Postgres/MySQL database + scoped role (if managed DB)',
|
|
268
|
+
' • R2 storage prefix for this project (if storage-enabled)',
|
|
269
|
+
' • DNS record at <slug>.dailey.cloud',
|
|
270
|
+
' • Customer registry image tags (not shared baseline images)',
|
|
271
|
+
'',
|
|
272
|
+
'Will survive:',
|
|
273
|
+
' • Audit logs, billing usage records (history)',
|
|
274
|
+
' • Nightly DB backups — retained per retention policy',
|
|
275
|
+
'',
|
|
276
|
+
`To delete: dailey_delete_project(project_id="${project_id}", confirm=true)`,
|
|
277
|
+
];
|
|
278
|
+
return textResult(lines.join('\n'));
|
|
279
|
+
}
|
|
245
280
|
const res = await apiRequest('DELETE', `/projects/${project_id}`);
|
|
246
281
|
if (!res.ok) return textResult(formatError(res));
|
|
247
282
|
return textResult(`Project ${project_id} deleted successfully.`);
|
package/src/tools/storage.ts
CHANGED
|
@@ -64,7 +64,7 @@ interface PresignedDownloadResponse {
|
|
|
64
64
|
export function registerStorageTools(server: McpServer) {
|
|
65
65
|
server.tool(
|
|
66
66
|
'dailey_storage_info',
|
|
67
|
-
'
|
|
67
|
+
'Returns the project\'s storage binding (bucket, prefix, region) AND the SDK env-var convention for server-side integration. For server-side apps in your Dailey-deployed pod: install an S3 SDK and use the auto-injected S3_* env vars (S3_ENDPOINT, S3_REGION, S3_BUCKET_NAME, S3_ACCESS_KEY_ID, S3_SECRET_ACCESS_KEY, S3_SESSION_TOKEN, S3_KEY_PREFIX). For browser-side flows: use dailey_storage_presign_upload/download to mint URLs.',
|
|
68
68
|
{ project_id: z.string().describe('The project ID') },
|
|
69
69
|
async ({ project_id }) => {
|
|
70
70
|
const res = await apiRequest<StorageInfoResponse>('GET', `/projects/${project_id}/storage`);
|
|
@@ -88,7 +88,30 @@ export function registerStorageTools(server: McpServer) {
|
|
|
88
88
|
`URL TTL: ${data.binding.limits.signed_url_ttl_seconds}s`,
|
|
89
89
|
];
|
|
90
90
|
|
|
91
|
-
|
|
91
|
+
// Render the new integration_paths block when the API surfaces it.
|
|
92
|
+
// Older customer-api responses still set next_step; fall back to that
|
|
93
|
+
// verbatim so this tool keeps working during the rolling deploy.
|
|
94
|
+
const ip = (data as any).integration_paths;
|
|
95
|
+
if (ip) {
|
|
96
|
+
lines.push('');
|
|
97
|
+
lines.push('Integration paths:');
|
|
98
|
+
if (ip.server_side) {
|
|
99
|
+
lines.push(` Server-side (deployed app): ${ip.server_side.summary}`);
|
|
100
|
+
if (Array.isArray(ip.server_side.env_vars)) {
|
|
101
|
+
lines.push(` Auto-injected env vars: ${ip.server_side.env_vars.join(', ')}`);
|
|
102
|
+
}
|
|
103
|
+
if (ip.server_side.example) {
|
|
104
|
+
lines.push(` Example: ${ip.server_side.example}`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (ip.browser_side) {
|
|
108
|
+
lines.push(` Browser-side (user's machine): ${ip.browser_side.summary}`);
|
|
109
|
+
}
|
|
110
|
+
const docsUrl = (data as any).docs_url;
|
|
111
|
+
if (docsUrl) {
|
|
112
|
+
lines.push(` Docs: ${docsUrl}`);
|
|
113
|
+
}
|
|
114
|
+
} else if (data.next_step) {
|
|
92
115
|
lines.push('');
|
|
93
116
|
lines.push(`Next Step: ${data.next_step}`);
|
|
94
117
|
}
|
|
@@ -148,7 +171,7 @@ export function registerStorageTools(server: McpServer) {
|
|
|
148
171
|
|
|
149
172
|
server.tool(
|
|
150
173
|
'dailey_storage_presign_upload',
|
|
151
|
-
'
|
|
174
|
+
'For BROWSER-side flows. Server-side apps deployed on Dailey should instead use the S3 SDK with the auto-injected S3_* env vars (see dailey_storage_info). Creates a presigned upload URL for an object in a project bucket.',
|
|
152
175
|
{
|
|
153
176
|
project_id: z.string().describe('The project ID'),
|
|
154
177
|
key: z.string().describe('The object key to upload'),
|
|
@@ -184,7 +207,7 @@ export function registerStorageTools(server: McpServer) {
|
|
|
184
207
|
|
|
185
208
|
server.tool(
|
|
186
209
|
'dailey_storage_presign_download',
|
|
187
|
-
'
|
|
210
|
+
'For BROWSER-side flows. Server-side apps deployed on Dailey should instead use the S3 SDK with the auto-injected S3_* env vars (see dailey_storage_info). Creates a presigned download URL for an object in a project bucket.',
|
|
188
211
|
{
|
|
189
212
|
project_id: z.string().describe('The project ID'),
|
|
190
213
|
key: z.string().describe('The object key to download'),
|