@daileyos/mcp-server 1.4.0 → 1.5.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/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/tools/bundle.d.ts +13 -0
- package/dist/tools/bundle.d.ts.map +1 -0
- package/dist/tools/bundle.js +123 -0
- package/dist/tools/bundle.js.map +1 -0
- package/dist/tools/images.d.ts.map +1 -1
- package/dist/tools/images.js +35 -3
- package/dist/tools/images.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +4 -0
- package/src/tools/bundle.ts +129 -0
- package/src/tools/images.ts +35 -3
- package/tests/pack1-mcp-preflight.test.mjs +177 -0
package/dist/index.js
CHANGED
|
@@ -24,6 +24,7 @@ import { registerLinkTools } from './tools/links.js';
|
|
|
24
24
|
import { registerCredentialRevealTools } from './tools/credentials-reveal.js';
|
|
25
25
|
import { registerAnalyzeTools } from './tools/analyze.js';
|
|
26
26
|
import { registerCliTools } from './tools/cli.js';
|
|
27
|
+
import { registerBundleTools } from './tools/bundle.js';
|
|
27
28
|
function preflight() {
|
|
28
29
|
const isInteractive = Boolean(process.stdin.isTTY);
|
|
29
30
|
if (!hasCredentials()) {
|
|
@@ -107,6 +108,8 @@ registerStorageTools(server);
|
|
|
107
108
|
registerBackupTools(server);
|
|
108
109
|
// CLI assist
|
|
109
110
|
registerCliTools(server);
|
|
111
|
+
// Atomic deploy bundle
|
|
112
|
+
registerBundleTools(server);
|
|
110
113
|
const transport = new StdioServerTransport();
|
|
111
114
|
await server.connect(transport);
|
|
112
115
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AA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,CAAC;AAE5B,aAAa;AACb,gBAAgB,CAAC,MAAM,CAAC,CAAC;AAEzB,uBAAuB;AACvB,mBAAmB,CAAC,MAAM,CAAC,CAAC;AAE5B,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;AAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
/**
|
|
3
|
+
* dailey_deploy_bundle — atomic create + configure + deploy in one call.
|
|
4
|
+
*
|
|
5
|
+
* Replaces what used to be 4–30 separate MCP calls (create_project +
|
|
6
|
+
* set_env_var × N + service_links × M + deploy + ...). Each of those
|
|
7
|
+
* required its own Claude Code permission prompt, which was Scott's
|
|
8
|
+
* friction #8. One call, one prompt, whole-bundle rollback on failure.
|
|
9
|
+
*
|
|
10
|
+
* EOS #53.
|
|
11
|
+
*/
|
|
12
|
+
export declare function registerBundleTools(server: McpServer): void;
|
|
13
|
+
//# sourceMappingURL=bundle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["../../src/tools/bundle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAIpE;;;;;;;;;GASG;AAEH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,SAAS,QAiHpD"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { apiRequest, formatError, textResult } from '../api.js';
|
|
3
|
+
/**
|
|
4
|
+
* dailey_deploy_bundle — atomic create + configure + deploy in one call.
|
|
5
|
+
*
|
|
6
|
+
* Replaces what used to be 4–30 separate MCP calls (create_project +
|
|
7
|
+
* set_env_var × N + service_links × M + deploy + ...). Each of those
|
|
8
|
+
* required its own Claude Code permission prompt, which was Scott's
|
|
9
|
+
* friction #8. One call, one prompt, whole-bundle rollback on failure.
|
|
10
|
+
*
|
|
11
|
+
* EOS #53.
|
|
12
|
+
*/
|
|
13
|
+
export function registerBundleTools(server) {
|
|
14
|
+
server.tool('dailey_deploy_bundle', [
|
|
15
|
+
'Create a project, inject env vars, link to other projects, bind a domain, and trigger the deploy — all in one atomic call.',
|
|
16
|
+
'If any step fails, the project is rolled back (deleted) so you do not end up with a partial "failed" project.',
|
|
17
|
+
'Prefer this over dailey_create_project + dailey_env_vars + dailey_service_links + dailey_deploy for any fresh deploy — it burns one permission prompt instead of many, and guarantees all-or-nothing.',
|
|
18
|
+
].join(' '), {
|
|
19
|
+
name: z.string().describe('Project name (also used as the requested slug).'),
|
|
20
|
+
repo_url: z.string().describe('GitHub repo URL (https://github.com/owner/repo) or Docker image (e.g., nginx:alpine).'),
|
|
21
|
+
branch: z.string().optional().describe('Git branch to deploy. Defaults to main. Ignored for Docker images.'),
|
|
22
|
+
env_vars: z
|
|
23
|
+
.record(z.string())
|
|
24
|
+
.optional()
|
|
25
|
+
.describe('Environment variables as a flat object, e.g. { DATABASE_URL: "postgresql://...", REDIS_URL: "..." }.'),
|
|
26
|
+
database: z
|
|
27
|
+
.union([z.enum(['mysql', 'postgres']), z.boolean()])
|
|
28
|
+
.optional()
|
|
29
|
+
.describe('Provision a managed DB: "mysql" | "postgres" | true (= mysql) | false. For Prisma/pg apps, use "postgres".'),
|
|
30
|
+
needs_auth: z.boolean().optional().describe('Provision Dailey Auth (SSO) for this project.'),
|
|
31
|
+
needs_storage: z.boolean().optional().describe('Provision object storage (R2) for this project.'),
|
|
32
|
+
links: z
|
|
33
|
+
.array(z.object({
|
|
34
|
+
target_project_id: z.string().describe('ID of the project to link to (e.g., a Postgres project).'),
|
|
35
|
+
env_key: z.string().optional().describe('Env key to inject on the source project. Defaults to an uppercased version of the target name.'),
|
|
36
|
+
}))
|
|
37
|
+
.optional()
|
|
38
|
+
.describe('Service links to inject into the new project. For DB targets, the injected env var is a real connection string (postgresql://, mysql://, etc.).'),
|
|
39
|
+
domain: z.string().optional().describe('Optional custom domain to bind (e.g., my-app.example.com). Must pass DNS-check after deploy.'),
|
|
40
|
+
deploy: z.boolean().optional().describe('Trigger a deploy after configuration. Defaults to true.'),
|
|
41
|
+
}, async (input) => {
|
|
42
|
+
// Translate to server shape: the bundle endpoint takes needs_database
|
|
43
|
+
// + database_type separately, same shape as POST /projects.
|
|
44
|
+
let needs_database = false;
|
|
45
|
+
let database_type;
|
|
46
|
+
if (input.database === true) {
|
|
47
|
+
needs_database = true;
|
|
48
|
+
database_type = 'mysql';
|
|
49
|
+
}
|
|
50
|
+
else if (input.database === 'mysql' || input.database === 'postgres') {
|
|
51
|
+
needs_database = true;
|
|
52
|
+
database_type = input.database;
|
|
53
|
+
}
|
|
54
|
+
const res = await apiRequest('POST', '/projects/bundle', {
|
|
55
|
+
name: input.name,
|
|
56
|
+
repo_url: input.repo_url,
|
|
57
|
+
branch: input.branch,
|
|
58
|
+
env_vars: input.env_vars,
|
|
59
|
+
needs_database,
|
|
60
|
+
database_type,
|
|
61
|
+
needs_auth: input.needs_auth,
|
|
62
|
+
needs_storage: input.needs_storage,
|
|
63
|
+
links: input.links,
|
|
64
|
+
domain: input.domain,
|
|
65
|
+
deploy: input.deploy,
|
|
66
|
+
});
|
|
67
|
+
if (!res.ok) {
|
|
68
|
+
// Bundle endpoint returns structured failure with a rolled_back flag
|
|
69
|
+
// and a steps array showing which stage died.
|
|
70
|
+
const body = res.data;
|
|
71
|
+
const lines = [];
|
|
72
|
+
lines.push(`Bundle failed: ${body?.error || formatError(res)}`);
|
|
73
|
+
if (body?.rolled_back) {
|
|
74
|
+
lines.push('Rolled back cleanly — no partial project left behind.');
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
lines.push('⚠ NOT rolled back — a partial project may exist. Inspect dailey_list_projects.');
|
|
78
|
+
}
|
|
79
|
+
if (Array.isArray(body?.steps)) {
|
|
80
|
+
lines.push('');
|
|
81
|
+
lines.push('Steps:');
|
|
82
|
+
for (const s of body.steps) {
|
|
83
|
+
const mark = s.status === 'ok' ? '✓' : '✗';
|
|
84
|
+
lines.push(` ${mark} ${s.step} (${s.ms}ms)${s.status === 'failed' && s.detail ? ` — ${JSON.stringify(s.detail)}` : ''}`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return textResult(lines.join('\n'));
|
|
88
|
+
}
|
|
89
|
+
const data = res.data;
|
|
90
|
+
const project = data.project || {};
|
|
91
|
+
const lines = [];
|
|
92
|
+
lines.push(`✓ Bundled deploy for ${project.name || input.name}`);
|
|
93
|
+
lines.push('');
|
|
94
|
+
lines.push(`Project ID: ${project.id}`);
|
|
95
|
+
lines.push(`Slug: ${project.slug}`);
|
|
96
|
+
lines.push(`URL: ${project.url || `https://${project.slug}.dailey.cloud`}`);
|
|
97
|
+
if (project.database)
|
|
98
|
+
lines.push(`Database: ${project.database.database} (${project.database.type || database_type || 'mysql'})`);
|
|
99
|
+
if (Array.isArray(data.links) && data.links.length > 0) {
|
|
100
|
+
lines.push('');
|
|
101
|
+
lines.push('Service links:');
|
|
102
|
+
for (const l of data.links) {
|
|
103
|
+
lines.push(` ${l.env_key} → ${l.target_slug} (${l.kind})`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (data.domain)
|
|
107
|
+
lines.push(`Domain: ${data.domain.hostname || input.domain}`);
|
|
108
|
+
if (data.build_id) {
|
|
109
|
+
lines.push('');
|
|
110
|
+
lines.push(`Build ID: ${data.build_id}`);
|
|
111
|
+
lines.push(`Track progress: dailey_deploy_status with project_id=${project.id}`);
|
|
112
|
+
}
|
|
113
|
+
if (Array.isArray(data.steps)) {
|
|
114
|
+
const ok = data.steps.filter((s) => s.status === 'ok').length;
|
|
115
|
+
const total = data.steps.length;
|
|
116
|
+
const totalMs = data.steps.reduce((sum, s) => sum + (s.ms || 0), 0);
|
|
117
|
+
lines.push('');
|
|
118
|
+
lines.push(`(${ok}/${total} steps succeeded in ${totalMs}ms)`);
|
|
119
|
+
}
|
|
120
|
+
return textResult(lines.join('\n'));
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=bundle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundle.js","sourceRoot":"","sources":["../../src/tools/bundle.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEhE;;;;;;;;;GASG;AAEH,MAAM,UAAU,mBAAmB,CAAC,MAAiB;IACnD,MAAM,CAAC,IAAI,CACT,sBAAsB,EACtB;QACE,4HAA4H;QAC5H,+GAA+G;QAC/G,uMAAuM;KACxM,CAAC,IAAI,CAAC,GAAG,CAAC,EACX;QACE,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,iDAAiD,CAAC;QAC5E,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,uFAAuF,CAAC;QACtH,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,oEAAoE,CAAC;QAC5G,QAAQ,EAAE,CAAC;aACR,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;aAClB,QAAQ,EAAE;aACV,QAAQ,CAAC,sGAAsG,CAAC;QACnH,QAAQ,EAAE,CAAC;aACR,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;aACnD,QAAQ,EAAE;aACV,QAAQ,CAAC,4GAA4G,CAAC;QACzH,UAAU,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,+CAA+C,CAAC;QAC5F,aAAa,EAAE,CAAC,CAAC,OAAO,EAAE,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["../../src/tools/images.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAIpE,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"images.d.ts","sourceRoot":"","sources":["../../src/tools/images.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAIpE,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,SAAS,QAwNnD"}
|
package/dist/tools/images.js
CHANGED
|
@@ -5,15 +5,45 @@ export function registerImageTools(server) {
|
|
|
5
5
|
server.tool('dailey_run_image', 'Deploy a Docker image to Dailey OS. Creates a project and deploys the image in one step. Examples: wordpress:6-apache, ghost:5-alpine, nginx:alpine, grafana/grafana:latest', {
|
|
6
6
|
image: z.string().describe('Docker image to deploy (e.g., wordpress:6-apache, nginx:alpine)'),
|
|
7
7
|
name: z.string().optional().describe('Project name (auto-generated if not provided)'),
|
|
8
|
-
database: z
|
|
8
|
+
database: z
|
|
9
|
+
.union([z.enum(['mysql', 'postgres']), z.boolean()])
|
|
10
|
+
.optional()
|
|
11
|
+
.describe('Provision a managed database: "mysql" | "postgres" | true (= mysql, for back-compat) | false. Default: no database.'),
|
|
9
12
|
}, async ({ image, name, database }) => {
|
|
10
13
|
const projectName = name || image.split('/').pop()?.split(':')[0] || 'app';
|
|
14
|
+
// Normalize the database flag.
|
|
15
|
+
// false / undefined → no DB
|
|
16
|
+
// true → mysql (back-compat with pre-0.9 callers)
|
|
17
|
+
// "mysql" | "postgres" → that engine
|
|
18
|
+
let needsDatabase = false;
|
|
19
|
+
let databaseType;
|
|
20
|
+
if (database === true) {
|
|
21
|
+
needsDatabase = true;
|
|
22
|
+
databaseType = 'mysql';
|
|
23
|
+
}
|
|
24
|
+
else if (database === 'mysql' || database === 'postgres') {
|
|
25
|
+
needsDatabase = true;
|
|
26
|
+
databaseType = database;
|
|
27
|
+
}
|
|
28
|
+
// Gentle nudge if the user asked for a DB alongside an image that
|
|
29
|
+
// IS the database — that's usually a mistake.
|
|
30
|
+
let noteIfRedundant = '';
|
|
31
|
+
const imgLower = image.toLowerCase();
|
|
32
|
+
if (needsDatabase && databaseType === 'postgres' && /(^|\/)postgres:/.test(imgLower)) {
|
|
33
|
+
noteIfRedundant = '\nNote: you asked for a managed Postgres alongside a postgres image. ' +
|
|
34
|
+
'The image IS a database — you probably want database: false and to connect to this project directly.\n';
|
|
35
|
+
}
|
|
36
|
+
if (needsDatabase && databaseType === 'mysql' && /(^|\/)mysql:|mariadb:/.test(imgLower)) {
|
|
37
|
+
noteIfRedundant = '\nNote: you asked for a managed MySQL alongside a MySQL/MariaDB image. ' +
|
|
38
|
+
'The image IS a database — you probably want database: false and to connect to this project directly.\n';
|
|
39
|
+
}
|
|
11
40
|
// Create project
|
|
12
41
|
const createRes = await apiRequest('POST', '/projects', {
|
|
13
42
|
name: projectName,
|
|
14
43
|
repo_url: image,
|
|
15
44
|
branch: 'main',
|
|
16
|
-
needs_database:
|
|
45
|
+
needs_database: needsDatabase,
|
|
46
|
+
database_type: databaseType,
|
|
17
47
|
});
|
|
18
48
|
if (!createRes.ok)
|
|
19
49
|
return textResult(formatError(createRes));
|
|
@@ -28,8 +58,10 @@ export function registerImageTools(server) {
|
|
|
28
58
|
result += `Note: ${project.slug_note}\n`;
|
|
29
59
|
}
|
|
30
60
|
if (project.database) {
|
|
31
|
-
result += `Database: ${project.database.database}\n`;
|
|
61
|
+
result += `Database: ${project.database.database} (${project.database.type || 'mysql'})\n`;
|
|
32
62
|
}
|
|
63
|
+
if (noteIfRedundant)
|
|
64
|
+
result += noteIfRedundant;
|
|
33
65
|
if (deployRes.ok && deployRes.data?.credentials) {
|
|
34
66
|
result += `\nCredentials:\n`;
|
|
35
67
|
for (const [key, val] of Object.entries(deployRes.data.credentials)) {
|
package/dist/tools/images.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"images.js","sourceRoot":"","sources":["../../src/tools/images.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEhE,MAAM,UAAU,kBAAkB,CAAC,MAAiB;IAClD,wBAAwB;IACxB,MAAM,CAAC,IAAI,CACT,kBAAkB,EAClB,6KAA6K,EAC7K;QACE,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,iEAAiE,CAAC;QAC7F,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,+CAA+C,CAAC;QACrF,QAAQ,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"images.js","sourceRoot":"","sources":["../../src/tools/images.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEhE,MAAM,UAAU,kBAAkB,CAAC,MAAiB;IAClD,wBAAwB;IACxB,MAAM,CAAC,IAAI,CACT,kBAAkB,EAClB,6KAA6K,EAC7K;QACE,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,iEAAiE,CAAC;QAC7F,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,+CAA+C,CAAC;QACrF,QAAQ,EAAE,CAAC;aACR,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;aACnD,QAAQ,EAAE;aACV,QAAQ,CAAC,qHAAqH,CAAC;KACnI,EACD,KAAK,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,E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,7 @@ import { registerLinkTools } from './tools/links.js';
|
|
|
26
26
|
import { registerCredentialRevealTools } from './tools/credentials-reveal.js';
|
|
27
27
|
import { registerAnalyzeTools } from './tools/analyze.js';
|
|
28
28
|
import { registerCliTools } from './tools/cli.js';
|
|
29
|
+
import { registerBundleTools } from './tools/bundle.js';
|
|
29
30
|
|
|
30
31
|
function preflight(): void {
|
|
31
32
|
const isInteractive = Boolean(process.stdin.isTTY);
|
|
@@ -126,5 +127,8 @@ registerBackupTools(server);
|
|
|
126
127
|
// CLI assist
|
|
127
128
|
registerCliTools(server);
|
|
128
129
|
|
|
130
|
+
// Atomic deploy bundle
|
|
131
|
+
registerBundleTools(server);
|
|
132
|
+
|
|
129
133
|
const transport = new StdioServerTransport();
|
|
130
134
|
await server.connect(transport);
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { apiRequest, formatError, textResult } from '../api.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* dailey_deploy_bundle — atomic create + configure + deploy in one call.
|
|
7
|
+
*
|
|
8
|
+
* Replaces what used to be 4–30 separate MCP calls (create_project +
|
|
9
|
+
* set_env_var × N + service_links × M + deploy + ...). Each of those
|
|
10
|
+
* required its own Claude Code permission prompt, which was Scott's
|
|
11
|
+
* friction #8. One call, one prompt, whole-bundle rollback on failure.
|
|
12
|
+
*
|
|
13
|
+
* EOS #53.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
export function registerBundleTools(server: McpServer) {
|
|
17
|
+
server.tool(
|
|
18
|
+
'dailey_deploy_bundle',
|
|
19
|
+
[
|
|
20
|
+
'Create a project, inject env vars, link to other projects, bind a domain, and trigger the deploy — all in one atomic call.',
|
|
21
|
+
'If any step fails, the project is rolled back (deleted) so you do not end up with a partial "failed" project.',
|
|
22
|
+
'Prefer this over dailey_create_project + dailey_env_vars + dailey_service_links + dailey_deploy for any fresh deploy — it burns one permission prompt instead of many, and guarantees all-or-nothing.',
|
|
23
|
+
].join(' '),
|
|
24
|
+
{
|
|
25
|
+
name: z.string().describe('Project name (also used as the requested slug).'),
|
|
26
|
+
repo_url: z.string().describe('GitHub repo URL (https://github.com/owner/repo) or Docker image (e.g., nginx:alpine).'),
|
|
27
|
+
branch: z.string().optional().describe('Git branch to deploy. Defaults to main. Ignored for Docker images.'),
|
|
28
|
+
env_vars: z
|
|
29
|
+
.record(z.string())
|
|
30
|
+
.optional()
|
|
31
|
+
.describe('Environment variables as a flat object, e.g. { DATABASE_URL: "postgresql://...", REDIS_URL: "..." }.'),
|
|
32
|
+
database: z
|
|
33
|
+
.union([z.enum(['mysql', 'postgres']), z.boolean()])
|
|
34
|
+
.optional()
|
|
35
|
+
.describe('Provision a managed DB: "mysql" | "postgres" | true (= mysql) | false. For Prisma/pg apps, use "postgres".'),
|
|
36
|
+
needs_auth: z.boolean().optional().describe('Provision Dailey Auth (SSO) for this project.'),
|
|
37
|
+
needs_storage: z.boolean().optional().describe('Provision object storage (R2) for this project.'),
|
|
38
|
+
links: z
|
|
39
|
+
.array(
|
|
40
|
+
z.object({
|
|
41
|
+
target_project_id: z.string().describe('ID of the project to link to (e.g., a Postgres project).'),
|
|
42
|
+
env_key: z.string().optional().describe('Env key to inject on the source project. Defaults to an uppercased version of the target name.'),
|
|
43
|
+
}),
|
|
44
|
+
)
|
|
45
|
+
.optional()
|
|
46
|
+
.describe('Service links to inject into the new project. For DB targets, the injected env var is a real connection string (postgresql://, mysql://, etc.).'),
|
|
47
|
+
domain: z.string().optional().describe('Optional custom domain to bind (e.g., my-app.example.com). Must pass DNS-check after deploy.'),
|
|
48
|
+
deploy: z.boolean().optional().describe('Trigger a deploy after configuration. Defaults to true.'),
|
|
49
|
+
},
|
|
50
|
+
async (input) => {
|
|
51
|
+
// Translate to server shape: the bundle endpoint takes needs_database
|
|
52
|
+
// + database_type separately, same shape as POST /projects.
|
|
53
|
+
let needs_database = false;
|
|
54
|
+
let database_type: 'mysql' | 'postgres' | undefined;
|
|
55
|
+
if (input.database === true) { needs_database = true; database_type = 'mysql'; }
|
|
56
|
+
else if (input.database === 'mysql' || input.database === 'postgres') {
|
|
57
|
+
needs_database = true;
|
|
58
|
+
database_type = input.database;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const res = await apiRequest<any>('POST', '/projects/bundle', {
|
|
62
|
+
name: input.name,
|
|
63
|
+
repo_url: input.repo_url,
|
|
64
|
+
branch: input.branch,
|
|
65
|
+
env_vars: input.env_vars,
|
|
66
|
+
needs_database,
|
|
67
|
+
database_type,
|
|
68
|
+
needs_auth: input.needs_auth,
|
|
69
|
+
needs_storage: input.needs_storage,
|
|
70
|
+
links: input.links,
|
|
71
|
+
domain: input.domain,
|
|
72
|
+
deploy: input.deploy,
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
if (!res.ok) {
|
|
76
|
+
// Bundle endpoint returns structured failure with a rolled_back flag
|
|
77
|
+
// and a steps array showing which stage died.
|
|
78
|
+
const body: any = res.data;
|
|
79
|
+
const lines: string[] = [];
|
|
80
|
+
lines.push(`Bundle failed: ${body?.error || formatError(res)}`);
|
|
81
|
+
if (body?.rolled_back) {
|
|
82
|
+
lines.push('Rolled back cleanly — no partial project left behind.');
|
|
83
|
+
} else {
|
|
84
|
+
lines.push('⚠ NOT rolled back — a partial project may exist. Inspect dailey_list_projects.');
|
|
85
|
+
}
|
|
86
|
+
if (Array.isArray(body?.steps)) {
|
|
87
|
+
lines.push('');
|
|
88
|
+
lines.push('Steps:');
|
|
89
|
+
for (const s of body.steps) {
|
|
90
|
+
const mark = s.status === 'ok' ? '✓' : '✗';
|
|
91
|
+
lines.push(` ${mark} ${s.step} (${s.ms}ms)${s.status === 'failed' && s.detail ? ` — ${JSON.stringify(s.detail)}` : ''}`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return textResult(lines.join('\n'));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const data: any = res.data;
|
|
98
|
+
const project = data.project || {};
|
|
99
|
+
const lines: string[] = [];
|
|
100
|
+
lines.push(`✓ Bundled deploy for ${project.name || input.name}`);
|
|
101
|
+
lines.push('');
|
|
102
|
+
lines.push(`Project ID: ${project.id}`);
|
|
103
|
+
lines.push(`Slug: ${project.slug}`);
|
|
104
|
+
lines.push(`URL: ${project.url || `https://${project.slug}.dailey.cloud`}`);
|
|
105
|
+
if (project.database) lines.push(`Database: ${project.database.database} (${project.database.type || database_type || 'mysql'})`);
|
|
106
|
+
if (Array.isArray(data.links) && data.links.length > 0) {
|
|
107
|
+
lines.push('');
|
|
108
|
+
lines.push('Service links:');
|
|
109
|
+
for (const l of data.links) {
|
|
110
|
+
lines.push(` ${l.env_key} → ${l.target_slug} (${l.kind})`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (data.domain) lines.push(`Domain: ${data.domain.hostname || input.domain}`);
|
|
114
|
+
if (data.build_id) {
|
|
115
|
+
lines.push('');
|
|
116
|
+
lines.push(`Build ID: ${data.build_id}`);
|
|
117
|
+
lines.push(`Track progress: dailey_deploy_status with project_id=${project.id}`);
|
|
118
|
+
}
|
|
119
|
+
if (Array.isArray(data.steps)) {
|
|
120
|
+
const ok = data.steps.filter((s: any) => s.status === 'ok').length;
|
|
121
|
+
const total = data.steps.length;
|
|
122
|
+
const totalMs = data.steps.reduce((sum: number, s: any) => sum + (s.ms || 0), 0);
|
|
123
|
+
lines.push('');
|
|
124
|
+
lines.push(`(${ok}/${total} steps succeeded in ${totalMs}ms)`);
|
|
125
|
+
}
|
|
126
|
+
return textResult(lines.join('\n'));
|
|
127
|
+
},
|
|
128
|
+
);
|
|
129
|
+
}
|
package/src/tools/images.ts
CHANGED
|
@@ -10,17 +10,48 @@ export function registerImageTools(server: McpServer) {
|
|
|
10
10
|
{
|
|
11
11
|
image: z.string().describe('Docker image to deploy (e.g., wordpress:6-apache, nginx:alpine)'),
|
|
12
12
|
name: z.string().optional().describe('Project name (auto-generated if not provided)'),
|
|
13
|
-
database: z
|
|
13
|
+
database: z
|
|
14
|
+
.union([z.enum(['mysql', 'postgres']), z.boolean()])
|
|
15
|
+
.optional()
|
|
16
|
+
.describe('Provision a managed database: "mysql" | "postgres" | true (= mysql, for back-compat) | false. Default: no database.'),
|
|
14
17
|
},
|
|
15
18
|
async ({ image, name, database }) => {
|
|
16
19
|
const projectName = name || image.split('/').pop()?.split(':')[0] || 'app';
|
|
17
20
|
|
|
21
|
+
// Normalize the database flag.
|
|
22
|
+
// false / undefined → no DB
|
|
23
|
+
// true → mysql (back-compat with pre-0.9 callers)
|
|
24
|
+
// "mysql" | "postgres" → that engine
|
|
25
|
+
let needsDatabase = false;
|
|
26
|
+
let databaseType: 'mysql' | 'postgres' | undefined;
|
|
27
|
+
if (database === true) {
|
|
28
|
+
needsDatabase = true;
|
|
29
|
+
databaseType = 'mysql';
|
|
30
|
+
} else if (database === 'mysql' || database === 'postgres') {
|
|
31
|
+
needsDatabase = true;
|
|
32
|
+
databaseType = database;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Gentle nudge if the user asked for a DB alongside an image that
|
|
36
|
+
// IS the database — that's usually a mistake.
|
|
37
|
+
let noteIfRedundant = '';
|
|
38
|
+
const imgLower = image.toLowerCase();
|
|
39
|
+
if (needsDatabase && databaseType === 'postgres' && /(^|\/)postgres:/.test(imgLower)) {
|
|
40
|
+
noteIfRedundant = '\nNote: you asked for a managed Postgres alongside a postgres image. ' +
|
|
41
|
+
'The image IS a database — you probably want database: false and to connect to this project directly.\n';
|
|
42
|
+
}
|
|
43
|
+
if (needsDatabase && databaseType === 'mysql' && /(^|\/)mysql:|mariadb:/.test(imgLower)) {
|
|
44
|
+
noteIfRedundant = '\nNote: you asked for a managed MySQL alongside a MySQL/MariaDB image. ' +
|
|
45
|
+
'The image IS a database — you probably want database: false and to connect to this project directly.\n';
|
|
46
|
+
}
|
|
47
|
+
|
|
18
48
|
// Create project
|
|
19
49
|
const createRes = await apiRequest<any>('POST', '/projects', {
|
|
20
50
|
name: projectName,
|
|
21
51
|
repo_url: image,
|
|
22
52
|
branch: 'main',
|
|
23
|
-
needs_database:
|
|
53
|
+
needs_database: needsDatabase,
|
|
54
|
+
database_type: databaseType,
|
|
24
55
|
});
|
|
25
56
|
|
|
26
57
|
if (!createRes.ok) return textResult(formatError(createRes));
|
|
@@ -40,8 +71,9 @@ export function registerImageTools(server: McpServer) {
|
|
|
40
71
|
}
|
|
41
72
|
|
|
42
73
|
if (project.database) {
|
|
43
|
-
result += `Database: ${project.database.database}\n`;
|
|
74
|
+
result += `Database: ${project.database.database} (${project.database.type || 'mysql'})\n`;
|
|
44
75
|
}
|
|
76
|
+
if (noteIfRedundant) result += noteIfRedundant;
|
|
45
77
|
|
|
46
78
|
if (deployRes.ok && deployRes.data?.credentials) {
|
|
47
79
|
result += `\nCredentials:\n`;
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EOS #47 — dailey-mcp preflight / stdio-TTY banner + JSON-RPC error.
|
|
3
|
+
*
|
|
4
|
+
* Three paths:
|
|
5
|
+
*
|
|
6
|
+
* 1. non-TTY + no creds → JSON-RPC 2.0 notification on stdout + stderr
|
|
7
|
+
* + exit code 1
|
|
8
|
+
* 2. TTY + no creds → stderr banner with "This is an MCP stdio server"
|
|
9
|
+
* + exit code 1
|
|
10
|
+
* 3. TTY + creds → short "MCP stdio server running" banner + stays
|
|
11
|
+
* running (kill after grace period)
|
|
12
|
+
*
|
|
13
|
+
* TTY is spawned via `unbuffer` (expect tools) when available — Node child-
|
|
14
|
+
* process piped stdio is NON-TTY by default. If unbuffer is missing,
|
|
15
|
+
* path (2) is documented rather than skipped silently.
|
|
16
|
+
*
|
|
17
|
+
* Run:
|
|
18
|
+
* node tests/pack1-mcp-preflight.test.mjs
|
|
19
|
+
* or
|
|
20
|
+
* node --test tests/pack1-mcp-preflight.test.mjs
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import { test, describe } from 'node:test';
|
|
24
|
+
import assert from 'node:assert/strict';
|
|
25
|
+
import { spawn, spawnSync } from 'node:child_process';
|
|
26
|
+
import { join, dirname } from 'node:path';
|
|
27
|
+
import { fileURLToPath } from 'node:url';
|
|
28
|
+
import { existsSync } from 'node:fs';
|
|
29
|
+
|
|
30
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
31
|
+
const BINARY = join(__dirname, '..', 'dist', 'index.js');
|
|
32
|
+
|
|
33
|
+
function unbufferAvailable() {
|
|
34
|
+
const r = spawnSync('sh', ['-c', 'command -v unbuffer']);
|
|
35
|
+
return r.status === 0 && String(r.stdout).trim().length > 0;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Spawn the MCP server with a controlled environment. Returns a promise that
|
|
40
|
+
* resolves with { code, stdout, stderr } once the process exits OR the
|
|
41
|
+
* waitMs timeout fires (in which case we kill it and set code=null).
|
|
42
|
+
*/
|
|
43
|
+
function runMcp({ env = {}, tty = false, waitMs = 4000, closeStdin = true }) {
|
|
44
|
+
return new Promise((resolve) => {
|
|
45
|
+
const cleanEnv = {
|
|
46
|
+
// Drop the parent's credentials unless explicitly restored below.
|
|
47
|
+
PATH: process.env.PATH,
|
|
48
|
+
HOME: process.env.HOME,
|
|
49
|
+
NODE_PATH: process.env.NODE_PATH,
|
|
50
|
+
...env,
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
let child;
|
|
54
|
+
if (tty) {
|
|
55
|
+
if (!unbufferAvailable()) {
|
|
56
|
+
resolve({ code: -1, stdout: '', stderr: 'unbuffer-not-available', skipped: true });
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
// unbuffer allocates a pty on stdout (but NOT stdin). For `stdin.isTTY`,
|
|
60
|
+
// we use `script` if available — or we fall back to a node wrapper that
|
|
61
|
+
// forces process.stdin.isTTY = true before requiring the real binary.
|
|
62
|
+
// Simplest cross-platform: use a small wrapper file that stamps the TTY
|
|
63
|
+
// flag and then dynamically imports the real entry.
|
|
64
|
+
child = spawn(
|
|
65
|
+
'node',
|
|
66
|
+
['-e', `process.stdin.isTTY = true; process.stdout.isTTY = true; await import(${JSON.stringify(BINARY)});`],
|
|
67
|
+
{ env: cleanEnv, stdio: ['pipe', 'pipe', 'pipe'] },
|
|
68
|
+
);
|
|
69
|
+
} else {
|
|
70
|
+
child = spawn('node', [BINARY], { env: cleanEnv, stdio: ['pipe', 'pipe', 'pipe'] });
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
let stdout = '';
|
|
74
|
+
let stderr = '';
|
|
75
|
+
child.stdout.on('data', (c) => { stdout += c.toString(); });
|
|
76
|
+
child.stderr.on('data', (c) => { stderr += c.toString(); });
|
|
77
|
+
|
|
78
|
+
const timer = setTimeout(() => {
|
|
79
|
+
try { child.kill('SIGTERM'); } catch {}
|
|
80
|
+
}, waitMs);
|
|
81
|
+
|
|
82
|
+
child.on('exit', (code) => {
|
|
83
|
+
clearTimeout(timer);
|
|
84
|
+
resolve({ code, stdout, stderr, killed: false });
|
|
85
|
+
});
|
|
86
|
+
child.on('error', (err) => {
|
|
87
|
+
clearTimeout(timer);
|
|
88
|
+
resolve({ code: -1, stdout, stderr: stderr + '\n' + err.message, error: true });
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
if (closeStdin) {
|
|
92
|
+
// Close stdin so the server doesn't block waiting for input.
|
|
93
|
+
try { child.stdin.end(); } catch {}
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
describe('EOS #47 — MCP preflight', { concurrency: false }, () => {
|
|
99
|
+
test('binary exists at dist/index.js (has been built)', () => {
|
|
100
|
+
assert.ok(existsSync(BINARY), `binary not found at ${BINARY} — run \`npm run build\` first`);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test('non-TTY + no creds → JSON-RPC notifications/message on stdout + stderr + exit 1', async () => {
|
|
104
|
+
const r = await runMcp({
|
|
105
|
+
env: { /* no DAILEY_* */ },
|
|
106
|
+
tty: false,
|
|
107
|
+
waitMs: 4000,
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
assert.equal(r.code, 1, `expected exit code 1, got ${r.code} (stderr: ${r.stderr.slice(0, 200)})`);
|
|
111
|
+
|
|
112
|
+
// Stdout must contain a valid JSON-RPC 2.0 notification
|
|
113
|
+
const line = r.stdout.split('\n').map((l) => l.trim()).find((l) => l.length > 0);
|
|
114
|
+
assert.ok(line, `expected at least one stdout line, got empty (stderr: ${r.stderr.slice(0, 200)})`);
|
|
115
|
+
let parsed;
|
|
116
|
+
try { parsed = JSON.parse(line); } catch (err) {
|
|
117
|
+
assert.fail(`stdout line is not JSON: ${line.slice(0, 200)}`);
|
|
118
|
+
}
|
|
119
|
+
assert.equal(parsed.jsonrpc, '2.0', `expected jsonrpc=2.0, got ${parsed.jsonrpc}`);
|
|
120
|
+
assert.equal(parsed.method, 'notifications/message', `expected method=notifications/message, got ${parsed.method}`);
|
|
121
|
+
assert.equal(parsed.params?.level, 'error');
|
|
122
|
+
assert.match(parsed.params?.data || '', /credentials/i);
|
|
123
|
+
|
|
124
|
+
// Stderr must also carry the message (so shell users see something)
|
|
125
|
+
assert.match(r.stderr, /dailey-mcp/i, 'stderr should mention dailey-mcp');
|
|
126
|
+
assert.match(r.stderr, /credentials/i, 'stderr should mention missing credentials');
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test('TTY + no creds → stderr banner with "This is an MCP stdio server" + exit 1', async () => {
|
|
130
|
+
const r = await runMcp({
|
|
131
|
+
env: { /* no DAILEY_* */ },
|
|
132
|
+
tty: true,
|
|
133
|
+
waitMs: 4000,
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
if (r.skipped) {
|
|
137
|
+
assert.fail(
|
|
138
|
+
'TTY case could not be executed in this environment (no `unbuffer`). ' +
|
|
139
|
+
'Manual verification: run `node dist/index.js` from an interactive terminal ' +
|
|
140
|
+
'with no DAILEY_* env set; expect the long banner + exit 1.'
|
|
141
|
+
);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
assert.equal(r.code, 1, `expected exit code 1, got ${r.code}`);
|
|
146
|
+
assert.match(r.stderr, /This is an MCP stdio server/, 'stderr must contain the TTY banner');
|
|
147
|
+
assert.match(r.stderr, /Missing credentials/i, 'stderr must mention Missing credentials');
|
|
148
|
+
// Long banner should NOT produce JSON on stdout in TTY mode
|
|
149
|
+
assert.equal(r.stdout.trim(), '', 'TTY-no-creds path should NOT emit JSON-RPC on stdout');
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
test('TTY + creds → short "MCP stdio server running" banner, process keeps running', async () => {
|
|
153
|
+
// We don't actually need real creds to hit the success-branch banner —
|
|
154
|
+
// `hasCredentials()` checks env vars only.
|
|
155
|
+
const r = await runMcp({
|
|
156
|
+
env: { DAILEY_API_TOKEN: 'fake-token-for-preflight-test-only' },
|
|
157
|
+
tty: true,
|
|
158
|
+
waitMs: 2500,
|
|
159
|
+
closeStdin: false,
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
if (r.skipped) {
|
|
163
|
+
assert.fail(
|
|
164
|
+
'TTY case could not be executed in this environment (no `unbuffer`). ' +
|
|
165
|
+
'Manual verification: run `DAILEY_API_TOKEN=x node dist/index.js` from an ' +
|
|
166
|
+
'interactive terminal; expect the short "MCP stdio server running" banner ' +
|
|
167
|
+
'and the process stays alive until Ctrl+C.'
|
|
168
|
+
);
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Killed by our SIGTERM — exit code should NOT be 1 (that's the preflight-fail code).
|
|
173
|
+
// node w/ SIGTERM typically exits with code null or 143.
|
|
174
|
+
assert.notEqual(r.code, 1, `server should not exit 1 when creds are present, got ${r.code} (stderr: ${r.stderr.slice(0, 200)})`);
|
|
175
|
+
assert.match(r.stderr, /MCP stdio server running/, `stderr should contain short banner. Got: ${r.stderr.slice(0, 300)}`);
|
|
176
|
+
});
|
|
177
|
+
});
|