@daileyos/mcp-server 1.20.2 → 1.20.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -1
- package/dist/tools/usage.d.ts.map +1 -1
- package/dist/tools/usage.js +61 -0
- package/dist/tools/usage.js.map +1 -1
- package/dist/tools/wordpress-live-edit.d.ts +3 -0
- package/dist/tools/wordpress-live-edit.d.ts.map +1 -0
- package/dist/tools/wordpress-live-edit.js +195 -0
- package/dist/tools/wordpress-live-edit.js.map +1 -0
- package/dist/tools/wordpress-migrate.d.ts.map +1 -1
- package/dist/tools/wordpress-migrate.js +15 -1
- package/dist/tools/wordpress-migrate.js.map +1 -1
- package/dist/tools/wordpress-targeting.d.ts +3 -0
- package/dist/tools/wordpress-targeting.d.ts.map +1 -0
- package/dist/tools/wordpress-targeting.js +110 -0
- package/dist/tools/wordpress-targeting.js.map +1 -0
- package/package.json +1 -1
- package/src/index.ts +8 -0
- package/src/tools/usage.ts +108 -0
- package/src/tools/wordpress-live-edit.ts +250 -0
- package/src/tools/wordpress-migrate.ts +17 -1
- package/src/tools/wordpress-targeting.ts +173 -0
- package/test/wordpress-live-edit.test.ts +159 -0
- package/test/wordpress-targeting.test.ts +127 -0
package/src/tools/usage.ts
CHANGED
|
@@ -2,6 +2,49 @@ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { apiRequest, formatError, textResult, jsonResult } from '../api.js';
|
|
4
4
|
|
|
5
|
+
interface AccountUsageResponse {
|
|
6
|
+
month: string;
|
|
7
|
+
plan: string;
|
|
8
|
+
currency: string;
|
|
9
|
+
ai: {
|
|
10
|
+
input_tokens: number;
|
|
11
|
+
output_tokens: number;
|
|
12
|
+
requests: number;
|
|
13
|
+
tiers: Array<{
|
|
14
|
+
tier: string;
|
|
15
|
+
used_tokens: number;
|
|
16
|
+
requests: number;
|
|
17
|
+
allowance_tokens: number;
|
|
18
|
+
remaining_tokens: number;
|
|
19
|
+
billable_tokens: number;
|
|
20
|
+
est_overage_cents: number;
|
|
21
|
+
}>;
|
|
22
|
+
est_overage_cents: number;
|
|
23
|
+
};
|
|
24
|
+
compute: {
|
|
25
|
+
gpu_minutes: number;
|
|
26
|
+
jobs: number;
|
|
27
|
+
rate_cents_per_minute: number;
|
|
28
|
+
est_overage_cents: number;
|
|
29
|
+
};
|
|
30
|
+
email: {
|
|
31
|
+
enabled: boolean;
|
|
32
|
+
messages_sent: number;
|
|
33
|
+
included: number;
|
|
34
|
+
remaining: number;
|
|
35
|
+
est_overage_cents: number;
|
|
36
|
+
};
|
|
37
|
+
est_total_overage_cents: number;
|
|
38
|
+
credits: {
|
|
39
|
+
prepaid_enabled: boolean;
|
|
40
|
+
balance_cents: number;
|
|
41
|
+
auto_recharge_enabled: boolean;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const dollars = (cents: number | undefined) => `$${(((cents ?? 0)) / 100).toFixed(2)}`;
|
|
46
|
+
const n = (x: number | undefined) => (x ?? 0).toLocaleString();
|
|
47
|
+
|
|
5
48
|
export function registerUsageTools(server: McpServer) {
|
|
6
49
|
server.tool(
|
|
7
50
|
'dailey_usage',
|
|
@@ -17,4 +60,69 @@ export function registerUsageTools(server: McpServer) {
|
|
|
17
60
|
return jsonResult(res.data);
|
|
18
61
|
},
|
|
19
62
|
);
|
|
63
|
+
|
|
64
|
+
server.tool(
|
|
65
|
+
'dailey_usage_summary',
|
|
66
|
+
'Show this month\'s metered usage across the whole account: Dailey AI (tokens used, per-tier allowance remaining), Dailey Compute (GPU minutes), and Dailey Email (messages sent vs included) — each with the estimated overage cost — plus the prepaid credit balance that covers overage. Use this to answer "how much have I used?" and "how many credits do I have left?". Top up with dailey_credits_topup.',
|
|
67
|
+
{
|
|
68
|
+
month: z.string().optional().describe('Month as YYYY-MM (e.g., 2026-07). Defaults to the current month.'),
|
|
69
|
+
},
|
|
70
|
+
async ({ month }) => {
|
|
71
|
+
const q = month ? `?month=${encodeURIComponent(month)}` : '';
|
|
72
|
+
const res = await apiRequest<AccountUsageResponse>('GET', `/account/usage${q}`);
|
|
73
|
+
if (!res.ok) return textResult(formatError(res));
|
|
74
|
+
const d = res.data;
|
|
75
|
+
const lines: string[] = [`Dailey usage — ${d.month} (${d.plan} plan)`, ''];
|
|
76
|
+
|
|
77
|
+
// Dailey AI
|
|
78
|
+
lines.push('Dailey AI');
|
|
79
|
+
if (d.ai.tiers.length === 0) {
|
|
80
|
+
lines.push(' No AI usage this month.');
|
|
81
|
+
} else {
|
|
82
|
+
lines.push(` ${n(d.ai.input_tokens + d.ai.output_tokens)} tokens across ${d.ai.tiers.length} tier(s), ${n(d.ai.requests)} requests`);
|
|
83
|
+
for (const t of d.ai.tiers) {
|
|
84
|
+
const base = t.allowance_tokens > 0
|
|
85
|
+
? `${n(t.used_tokens)} used / ${n(t.allowance_tokens)} allowance (${n(t.remaining_tokens)} left)`
|
|
86
|
+
: `${n(t.used_tokens)} used (metered)`;
|
|
87
|
+
const over = t.est_overage_cents > 0 ? ` ~${dollars(t.est_overage_cents)} overage` : '';
|
|
88
|
+
lines.push(` • ${t.tier}: ${base}${over}`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
lines.push(` Est. AI overage: ${dollars(d.ai.est_overage_cents)}`);
|
|
92
|
+
lines.push('');
|
|
93
|
+
|
|
94
|
+
// Dailey Compute
|
|
95
|
+
lines.push('Dailey Compute (GPU)');
|
|
96
|
+
if (d.compute.gpu_minutes === 0) {
|
|
97
|
+
lines.push(' No GPU usage this month.');
|
|
98
|
+
} else {
|
|
99
|
+
lines.push(` ${n(d.compute.gpu_minutes)} GPU-min across ${n(d.compute.jobs)} job(s) @ ${dollars(d.compute.rate_cents_per_minute)}/min → ~${dollars(d.compute.est_overage_cents)}`);
|
|
100
|
+
}
|
|
101
|
+
lines.push('');
|
|
102
|
+
|
|
103
|
+
// Dailey Email
|
|
104
|
+
lines.push('Dailey Email');
|
|
105
|
+
if (!d.email.enabled) {
|
|
106
|
+
lines.push(' Not enabled (add the Email add-on to send).');
|
|
107
|
+
} else {
|
|
108
|
+
lines.push(` ${n(d.email.messages_sent)} / ${n(d.email.included)} sent (${n(d.email.remaining)} left)`);
|
|
109
|
+
lines.push(` Est. email overage: ${dollars(d.email.est_overage_cents)}`);
|
|
110
|
+
}
|
|
111
|
+
lines.push('');
|
|
112
|
+
|
|
113
|
+
// Totals + credits
|
|
114
|
+
lines.push(`Estimated overage this month: ${dollars(d.est_total_overage_cents)}`);
|
|
115
|
+
if (d.credits.prepaid_enabled) {
|
|
116
|
+
lines.push(`Prepaid credits: ${dollars(d.credits.balance_cents)} balance${d.credits.auto_recharge_enabled ? ' (auto-recharge on)' : ''}`);
|
|
117
|
+
lines.push(' Covers metered overage plus real-time Images/Voice usage.');
|
|
118
|
+
if (d.credits.balance_cents < d.est_total_overage_cents) {
|
|
119
|
+
lines.push(' ⚠ Balance is below the estimated overage — top up with dailey_credits_topup.');
|
|
120
|
+
}
|
|
121
|
+
} else {
|
|
122
|
+
lines.push('Prepaid credits: not enabled (overage is invoiced monthly). Enable prepaid with dailey_credits.');
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return textResult(lines.join('\n'));
|
|
126
|
+
},
|
|
127
|
+
);
|
|
20
128
|
}
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import {
|
|
4
|
+
apiRequest,
|
|
5
|
+
formatError,
|
|
6
|
+
textResult,
|
|
7
|
+
getActiveAccount,
|
|
8
|
+
setActiveAccount,
|
|
9
|
+
} from '../api.js';
|
|
10
|
+
|
|
11
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
12
|
+
// WordPress "live-edit" tools — thin MCP wrappers over the tenant-scoped
|
|
13
|
+
// customer-api live-edit routes (paired PR customer-api#18). Everything here
|
|
14
|
+
// lives under POST /projects/:id/wp/{files,media,cli}/…
|
|
15
|
+
//
|
|
16
|
+
// SAFETY MODEL (two-phase confirm). The mutating server routes are two-phase:
|
|
17
|
+
// 1. Request WITHOUT confirm_token → the server returns a PREVIEW:
|
|
18
|
+
// { preview:true, confirm_token, identity:{project_id,slug,domain,env,
|
|
19
|
+
// db_name,namespace}, change }
|
|
20
|
+
// It does NOT mutate. The `identity` echo tells you exactly which
|
|
21
|
+
// domain / database / environment you are about to touch.
|
|
22
|
+
// 2. Request WITH that confirm_token → the server executes (snapshot-first).
|
|
23
|
+
//
|
|
24
|
+
// These tools NEVER fabricate or auto-pass a confirm_token. The token must come
|
|
25
|
+
// back from a real server preview; the tool only relays it on the second call.
|
|
26
|
+
// The model is instructed (in each description) to show the preview to the user
|
|
27
|
+
// and confirm the target before re-calling with the token.
|
|
28
|
+
//
|
|
29
|
+
// NOTE: these consume customer-api#18's routes and 404 until that PR is deployed
|
|
30
|
+
// (both merge in the same change window).
|
|
31
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
32
|
+
|
|
33
|
+
// The targeting identity the server echoes on a preview so the model/user can
|
|
34
|
+
// confirm the exact site before a mutation proceeds.
|
|
35
|
+
interface Identity {
|
|
36
|
+
project_id?: string;
|
|
37
|
+
slug?: string;
|
|
38
|
+
domain?: string;
|
|
39
|
+
env?: string;
|
|
40
|
+
db_name?: string;
|
|
41
|
+
namespace?: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// A two-phase preview envelope (no mutation happened yet).
|
|
45
|
+
interface PreviewEnvelope {
|
|
46
|
+
preview: true;
|
|
47
|
+
confirm_token: string;
|
|
48
|
+
identity?: Identity;
|
|
49
|
+
change?: unknown;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function isPreview(data: unknown): data is PreviewEnvelope {
|
|
53
|
+
return typeof data === 'object' && data !== null && (data as { preview?: unknown }).preview === true;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// If the caller passed an explicit `account`, adopt it as the acting-as target
|
|
57
|
+
// for this session (same mechanism as dailey_use_account — sends X-Dailey-Account
|
|
58
|
+
// on every subsequent request). Returns the EFFECTIVE account so every tool
|
|
59
|
+
// result can surface it and targeting is never ambiguous.
|
|
60
|
+
function scopeAccount(account?: string): string | null {
|
|
61
|
+
if (account && account.trim()) {
|
|
62
|
+
setActiveAccount(account.trim());
|
|
63
|
+
}
|
|
64
|
+
return getActiveAccount() ?? null;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Render a two-phase preview prominently: the identity echo (domain/db/env) plus
|
|
68
|
+
// the pending change and the confirm_token to relay back verbatim.
|
|
69
|
+
function renderPreview(activeAccount: string | null, env: PreviewEnvelope, toolHint: string): string {
|
|
70
|
+
const id = env.identity ?? {};
|
|
71
|
+
const lines: string[] = [
|
|
72
|
+
'PREVIEW ONLY — nothing has changed yet. Confirm the target below, then re-call to execute.',
|
|
73
|
+
'',
|
|
74
|
+
`Active account: ${activeAccount ?? 'self'}`,
|
|
75
|
+
`Domain: ${id.domain ?? '(unknown)'}`,
|
|
76
|
+
`Database: ${id.db_name ?? '(unknown)'}`,
|
|
77
|
+
`Environment: ${id.env ?? '(unknown)'}`,
|
|
78
|
+
`Project: ${id.project_id ?? '(unknown)'}${id.slug ? ` (${id.slug})` : ''}`,
|
|
79
|
+
`Namespace: ${id.namespace ?? '(unknown)'}`,
|
|
80
|
+
'',
|
|
81
|
+
'Pending change:',
|
|
82
|
+
JSON.stringify(env.change ?? {}, null, 2),
|
|
83
|
+
'',
|
|
84
|
+
`confirm_token: ${env.confirm_token}`,
|
|
85
|
+
'',
|
|
86
|
+
toolHint,
|
|
87
|
+
'Do NOT invent a confirm_token — only relay the exact one above, and only after the user confirms this is the right site.',
|
|
88
|
+
];
|
|
89
|
+
return lines.join('\n');
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Merge the effective account (and any identity echo the server included) onto a
|
|
93
|
+
// non-preview result so every result surfaces which account/site was acted on.
|
|
94
|
+
function renderResult(activeAccount: string | null, data: unknown): string {
|
|
95
|
+
const base: Record<string, unknown> = { active_account: activeAccount ?? 'self' };
|
|
96
|
+
if (typeof data === 'object' && data !== null) {
|
|
97
|
+
Object.assign(base, data as Record<string, unknown>);
|
|
98
|
+
} else {
|
|
99
|
+
base.result = data;
|
|
100
|
+
}
|
|
101
|
+
return JSON.stringify(base, null, 2);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function registerWordPressLiveEditTools(server: McpServer) {
|
|
105
|
+
// ── Tool 1 — files: list / read / write / delete ─────────────────────────
|
|
106
|
+
server.tool(
|
|
107
|
+
'dailey_wp_files',
|
|
108
|
+
[
|
|
109
|
+
'Browse and edit the files of a live WordPress site (wp-content: themes, plugins, uploads).',
|
|
110
|
+
'action="list" (path optional) and action="read" (path required) run immediately and are read-only.',
|
|
111
|
+
'action="write" (path + content, optional encoding "utf8"|"base64") and action="delete" (path) are MUTATING and two-phase:',
|
|
112
|
+
' 1) Call WITHOUT confirm_token first — the server returns a PREVIEW that echoes the target domain, db_name, env, and the exact change (it does NOT modify anything).',
|
|
113
|
+
' 2) SHOW that preview to the user, confirm it is the right site, then call AGAIN with the SAME args plus the confirm_token returned by the preview to execute (the server takes a snapshot first).',
|
|
114
|
+
'Never fabricate a confirm_token — only relay the one a real preview returned. Every result surfaces the active_account and, on mutations, the identity echo (domain/db/env).',
|
|
115
|
+
'Consumes customer-api#18 routes; 404s until that ships (same change window).',
|
|
116
|
+
].join('\n'),
|
|
117
|
+
{
|
|
118
|
+
project: z.string().describe('The WordPress project — its id (or slug/ref the server can resolve)'),
|
|
119
|
+
action: z.enum(['list', 'read', 'write', 'delete']).describe('list (read-only), read (read-only), write (mutating, two-phase), delete (mutating, two-phase)'),
|
|
120
|
+
path: z.string().optional().describe('Path within wp-content. Optional for list (defaults to root); required for read/write/delete.'),
|
|
121
|
+
content: z.string().optional().describe('File content for action="write" (interpret per `encoding`).'),
|
|
122
|
+
encoding: z.enum(['utf8', 'base64']).optional().describe('Encoding of `content` for write; defaults to utf8.'),
|
|
123
|
+
confirm_token: z.string().optional().describe('Two-phase confirm token for write/delete. Omit on the first call to get the preview; on the second call pass the exact token the preview returned. Never fabricate one.'),
|
|
124
|
+
account: z.string().optional().describe('Acting-as target: slug or id of a managed account (must be in your fleet from dailey_accounts). Scopes this and subsequent calls, like dailey_use_account.'),
|
|
125
|
+
},
|
|
126
|
+
async ({ project, action, path, content, encoding, confirm_token, account }) => {
|
|
127
|
+
const activeAccount = scopeAccount(account);
|
|
128
|
+
const base = `/projects/${encodeURIComponent(project)}/wp/files`;
|
|
129
|
+
|
|
130
|
+
if (action === 'list') {
|
|
131
|
+
const res = await apiRequest('POST', `${base}/list`, path ? { path } : {});
|
|
132
|
+
if (!res.ok) return textResult(formatError(res));
|
|
133
|
+
return textResult(renderResult(activeAccount, res.data));
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (action === 'read') {
|
|
137
|
+
if (!path) return textResult('action="read" requires `path`.');
|
|
138
|
+
const res = await apiRequest('POST', `${base}/read`, { path });
|
|
139
|
+
if (!res.ok) return textResult(formatError(res));
|
|
140
|
+
return textResult(renderResult(activeAccount, res.data));
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (action === 'write') {
|
|
144
|
+
if (!path) return textResult('action="write" requires `path`.');
|
|
145
|
+
if (content == null) return textResult('action="write" requires `content`.');
|
|
146
|
+
const body: Record<string, unknown> = { path, content };
|
|
147
|
+
if (encoding) body.encoding = encoding;
|
|
148
|
+
if (confirm_token) body.confirm_token = confirm_token;
|
|
149
|
+
const res = await apiRequest('POST', `${base}/write`, body);
|
|
150
|
+
if (!res.ok) return textResult(formatError(res));
|
|
151
|
+
if (isPreview(res.data)) {
|
|
152
|
+
return textResult(renderPreview(activeAccount, res.data, 'To write this file, re-call dailey_wp_files with the same project/path/content and this confirm_token.'));
|
|
153
|
+
}
|
|
154
|
+
return textResult(renderResult(activeAccount, res.data));
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// action === 'delete'
|
|
158
|
+
if (!path) return textResult('action="delete" requires `path`.');
|
|
159
|
+
const body: Record<string, unknown> = { path };
|
|
160
|
+
if (confirm_token) body.confirm_token = confirm_token;
|
|
161
|
+
const res = await apiRequest('POST', `${base}/delete`, body);
|
|
162
|
+
if (!res.ok) return textResult(formatError(res));
|
|
163
|
+
if (isPreview(res.data)) {
|
|
164
|
+
return textResult(renderPreview(activeAccount, res.data, 'To delete this file, re-call dailey_wp_files with the same project/path and this confirm_token.'));
|
|
165
|
+
}
|
|
166
|
+
return textResult(renderResult(activeAccount, res.data));
|
|
167
|
+
},
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
// ── Tool 2 — media: list / upload ────────────────────────────────────────
|
|
171
|
+
server.tool(
|
|
172
|
+
'dailey_wp_media',
|
|
173
|
+
[
|
|
174
|
+
'List or upload media in a live WordPress site\'s uploads directory.',
|
|
175
|
+
'action="list" (path optional) runs immediately and is read-only.',
|
|
176
|
+
'action="upload" (filename + content_base64, optional import to register it in the WP media library) is MUTATING and two-phase:',
|
|
177
|
+
' 1) Call WITHOUT confirm_token first — the server returns a PREVIEW echoing the target domain, db_name, env and the pending change (nothing is written yet).',
|
|
178
|
+
' 2) SHOW the preview, confirm the site, then call AGAIN with the same args plus the returned confirm_token to execute (snapshot-first).',
|
|
179
|
+
'Never fabricate a confirm_token — only relay one a real preview returned. Every result surfaces the active_account and, on mutations, the identity echo.',
|
|
180
|
+
'Consumes customer-api#18 routes; 404s until that ships (same change window).',
|
|
181
|
+
].join('\n'),
|
|
182
|
+
{
|
|
183
|
+
project: z.string().describe('The WordPress project — its id (or slug/ref the server can resolve)'),
|
|
184
|
+
action: z.enum(['list', 'upload']).describe('list (read-only) or upload (mutating, two-phase)'),
|
|
185
|
+
path: z.string().optional().describe('Subpath within uploads for action="list" (defaults to root).'),
|
|
186
|
+
filename: z.string().optional().describe('Destination filename for action="upload".'),
|
|
187
|
+
content_base64: z.string().optional().describe('Base64-encoded file bytes for action="upload".'),
|
|
188
|
+
import: z.boolean().optional().describe('If true, register the uploaded file in the WordPress media library (not just drop it on disk).'),
|
|
189
|
+
confirm_token: z.string().optional().describe('Two-phase confirm token for upload. Omit on the first call to get the preview; pass the exact token the preview returned on the second call. Never fabricate one.'),
|
|
190
|
+
account: z.string().optional().describe('Acting-as target: slug or id of a managed account (must be in your fleet). Scopes this and subsequent calls, like dailey_use_account.'),
|
|
191
|
+
},
|
|
192
|
+
async ({ project, action, path, filename, content_base64, import: importFlag, confirm_token, account }) => {
|
|
193
|
+
const activeAccount = scopeAccount(account);
|
|
194
|
+
const base = `/projects/${encodeURIComponent(project)}/wp/media`;
|
|
195
|
+
|
|
196
|
+
if (action === 'list') {
|
|
197
|
+
const res = await apiRequest('POST', `${base}/list`, path ? { path } : {});
|
|
198
|
+
if (!res.ok) return textResult(formatError(res));
|
|
199
|
+
return textResult(renderResult(activeAccount, res.data));
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// action === 'upload'
|
|
203
|
+
if (!filename) return textResult('action="upload" requires `filename`.');
|
|
204
|
+
if (content_base64 == null) return textResult('action="upload" requires `content_base64`.');
|
|
205
|
+
const body: Record<string, unknown> = { filename, content_base64 };
|
|
206
|
+
if (importFlag != null) body.import = importFlag;
|
|
207
|
+
if (confirm_token) body.confirm_token = confirm_token;
|
|
208
|
+
const res = await apiRequest('POST', `${base}/upload`, body);
|
|
209
|
+
if (!res.ok) return textResult(formatError(res));
|
|
210
|
+
if (isPreview(res.data)) {
|
|
211
|
+
return textResult(renderPreview(activeAccount, res.data, 'To upload this media, re-call dailey_wp_media with the same project/filename/content_base64 and this confirm_token.'));
|
|
212
|
+
}
|
|
213
|
+
return textResult(renderResult(activeAccount, res.data));
|
|
214
|
+
},
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
// ── Tool 3 — wp-cli passthrough ──────────────────────────────────────────
|
|
218
|
+
server.tool(
|
|
219
|
+
'dailey_wp_cli',
|
|
220
|
+
[
|
|
221
|
+
'Run a wp-cli command against a live WordPress site. `args` is the argv array passed straight through (e.g. ["option","get","siteurl"] or ["post","list","--format=json"]).',
|
|
222
|
+
'Read-only commands (e.g. `option get`, `post list`, `plugin list`) run immediately and return stdout/stderr/exit_code.',
|
|
223
|
+
'Write commands require allow_write:true AND the two-phase confirm:',
|
|
224
|
+
' 1) Call with allow_write:true but WITHOUT confirm_token — the server returns a PREVIEW echoing the target domain/db/env and the pending change (it does NOT run the write).',
|
|
225
|
+
' 2) SHOW the preview, confirm the site, then call AGAIN with the same args + allow_write:true + the returned confirm_token to execute (snapshot-first).',
|
|
226
|
+
'The server enforces an allow-list and REFUSES anything outside it — no `config`, `core`, `eval`, `search-replace`, or `db import/export`. Never fabricate a confirm_token. Results surface the active_account (and identity echo on writes).',
|
|
227
|
+
'Consumes customer-api#18 routes; 404s until that ships (same change window).',
|
|
228
|
+
].join('\n'),
|
|
229
|
+
{
|
|
230
|
+
project: z.string().describe('The WordPress project — its id (or slug/ref the server can resolve)'),
|
|
231
|
+
args: z.array(z.string()).describe('wp-cli argv, passed straight through. The server enforces the allow-list.'),
|
|
232
|
+
allow_write: z.boolean().optional().describe('Required (true) for any write command; the server also gates writes by its allow-list. Read-only commands do not need this.'),
|
|
233
|
+
confirm_token: z.string().optional().describe('Two-phase confirm token for writes. Omit on the first call to get the preview; pass the exact token the preview returned on the second call. Never fabricate one.'),
|
|
234
|
+
account: z.string().optional().describe('Acting-as target: slug or id of a managed account (must be in your fleet). Scopes this and subsequent calls, like dailey_use_account.'),
|
|
235
|
+
},
|
|
236
|
+
async ({ project, args, allow_write, confirm_token, account }) => {
|
|
237
|
+
const activeAccount = scopeAccount(account);
|
|
238
|
+
const body: Record<string, unknown> = { args };
|
|
239
|
+
if (allow_write != null) body.allow_write = allow_write;
|
|
240
|
+
if (confirm_token) body.confirm_token = confirm_token;
|
|
241
|
+
|
|
242
|
+
const res = await apiRequest('POST', `/projects/${encodeURIComponent(project)}/wp/cli`, body);
|
|
243
|
+
if (!res.ok) return textResult(formatError(res));
|
|
244
|
+
if (isPreview(res.data)) {
|
|
245
|
+
return textResult(renderPreview(activeAccount, res.data, 'To run this write command, re-call dailey_wp_cli with the same args + allow_write:true and this confirm_token.'));
|
|
246
|
+
}
|
|
247
|
+
return textResult(renderResult(activeAccount, res.data));
|
|
248
|
+
},
|
|
249
|
+
);
|
|
250
|
+
}
|
|
@@ -13,6 +13,8 @@ interface StartResponse {
|
|
|
13
13
|
}
|
|
14
14
|
interface RunResponse { ok: boolean; migration_id: string; new_url: string }
|
|
15
15
|
interface StatusResponse { status: string; step?: string; error?: string; log_tail?: string; finished_at?: string }
|
|
16
|
+
interface ScanFinding { level: string; code: string; message: string }
|
|
17
|
+
interface ScanResponse { ok: boolean; verdict: 'clean' | 'warn' | 'blocked'; findings: ScanFinding[] }
|
|
16
18
|
|
|
17
19
|
export function registerWordPressMigrateTools(server: McpServer) {
|
|
18
20
|
server.tool(
|
|
@@ -25,9 +27,10 @@ export function registerWordPressMigrateTools(server: McpServer) {
|
|
|
25
27
|
content_file: z.string().optional().describe('Local path to the wp-content archive (.tar.gz/.tgz/.zip) — required for migrate'),
|
|
26
28
|
old_url: z.string().optional().describe('The site\'s current URL, e.g. https://oldsite.com — required for migrate'),
|
|
27
29
|
table_prefix: z.string().optional().describe('Table prefix if not wp_'),
|
|
30
|
+
allow_unsafe: z.boolean().optional().describe('Proceed even if the pre-migrate scan reports a blocked verdict (non-malware only)'),
|
|
28
31
|
migration_id: z.string().optional().describe('Migration ID — required for status'),
|
|
29
32
|
},
|
|
30
|
-
async ({ project_id, action, db_file, content_file, old_url, table_prefix, migration_id }) => {
|
|
33
|
+
async ({ project_id, action, db_file, content_file, old_url, table_prefix, allow_unsafe, migration_id }) => {
|
|
31
34
|
if (action === 'status') {
|
|
32
35
|
if (!migration_id) return textResult('migration_id is required for action=status');
|
|
33
36
|
const res = await apiRequest<StatusResponse>('GET', `/projects/${project_id}/migrate/wordpress/${migration_id}`);
|
|
@@ -59,6 +62,19 @@ export function registerWordPressMigrateTools(server: McpServer) {
|
|
|
59
62
|
return textResult(`Upload failed: ${message}\nMigration ${mid} is still pending — fix the file and call migrate again (a new migration will be started).`);
|
|
60
63
|
}
|
|
61
64
|
|
|
65
|
+
// Pre-migrate scan is REQUIRED server-side before /run (returns 409
|
|
66
|
+
// scan_required otherwise). Without this, migrate fails at launch and
|
|
67
|
+
// leaves a pending migration lock on the project.
|
|
68
|
+
const scan = await apiRequest<ScanResponse>('POST', `/projects/${project_id}/migrate/wordpress/${mid}/scan`, {
|
|
69
|
+
allow_unsafe: Boolean(allow_unsafe),
|
|
70
|
+
});
|
|
71
|
+
if (scan.status === 409) {
|
|
72
|
+
const findings = (scan.data as ScanResponse | undefined)?.findings ?? [];
|
|
73
|
+
const list = findings.length ? findings.map((f) => ` [${f.level}] ${f.code}: ${f.message}`).join('\n') : ' (no findings detail returned)';
|
|
74
|
+
return textResult(`Refusing to run: server-side scan gate is BLOCKED.\n${list}\nMigration ${mid} is still pending — pass allow_unsafe=true to override (logged) and call migrate again.`);
|
|
75
|
+
}
|
|
76
|
+
if (!scan.ok) return textResult(formatError(scan));
|
|
77
|
+
|
|
62
78
|
const run = await apiRequest<RunResponse>('POST', `/projects/${project_id}/migrate/wordpress/${mid}/run`, {
|
|
63
79
|
old_url, ...(table_prefix ? { table_prefix } : {}),
|
|
64
80
|
});
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import {
|
|
4
|
+
apiRequest,
|
|
5
|
+
formatError,
|
|
6
|
+
textResult,
|
|
7
|
+
jsonResult,
|
|
8
|
+
getActiveAccount,
|
|
9
|
+
setActiveAccount,
|
|
10
|
+
} from '../api.js';
|
|
11
|
+
|
|
12
|
+
// The hardened WordPress catalog template is resolved by the deploy-service from
|
|
13
|
+
// this image name — it wires the MySQL DB + persistent wp-content volume +
|
|
14
|
+
// generated admin creds. Do NOT change without the paired catalog entry.
|
|
15
|
+
const WORDPRESS_CATALOG_IMAGE = 'wordpress:6-apache';
|
|
16
|
+
|
|
17
|
+
interface CreatedProject {
|
|
18
|
+
id: string;
|
|
19
|
+
name: string;
|
|
20
|
+
slug?: string;
|
|
21
|
+
status?: string;
|
|
22
|
+
repo_url?: string;
|
|
23
|
+
url?: string;
|
|
24
|
+
build_id?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// A WordPress project as returned by the targeting spine
|
|
28
|
+
// (customer-api feat/wp-targeting-spine).
|
|
29
|
+
interface WpProject {
|
|
30
|
+
project_id: string;
|
|
31
|
+
slug: string;
|
|
32
|
+
domain: string;
|
|
33
|
+
env: string;
|
|
34
|
+
db_name: string;
|
|
35
|
+
namespace: string;
|
|
36
|
+
active_account: string | null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
interface WpListResponse {
|
|
40
|
+
projects: WpProject[];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// If the caller passed an explicit `account`, adopt it as the acting-as target
|
|
44
|
+
// for this session (same mechanism as dailey_use_account — sends X-Dailey-Account
|
|
45
|
+
// on every subsequent request). Returns the EFFECTIVE account so every tool
|
|
46
|
+
// result can surface it and targeting is never ambiguous.
|
|
47
|
+
function scopeAccount(account?: string): string | null {
|
|
48
|
+
if (account && account.trim()) {
|
|
49
|
+
setActiveAccount(account.trim());
|
|
50
|
+
}
|
|
51
|
+
return getActiveAccount() ?? null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function registerWordPressTargetingTools(server: McpServer) {
|
|
55
|
+
// ── Tool 1 — Scenario 1: create a fresh hardened WordPress site ──────────
|
|
56
|
+
server.tool(
|
|
57
|
+
'dailey_create_wordpress',
|
|
58
|
+
'Create a brand-new hardened WordPress site in the effective account (respects the account set by dailey_use_account, or the optional `account` arg here). POSTs the standard project-create endpoint with the WordPress catalog image so the deploy-service provisions the MySQL database, a persistent wp-content volume, and generated admin credentials. Prefer this over dailey_wordpress_import when you just need a fresh site (import is for migrating an existing bundle). Returns the project_id, slug, the wp-admin URL, and the effective account. The generated admin password is retrievable via dailey_reveal_credential (key WORDPRESS_ADMIN_PASSWORD).',
|
|
59
|
+
{
|
|
60
|
+
name: z.string().describe('Project name for the new WordPress site'),
|
|
61
|
+
account: z
|
|
62
|
+
.string()
|
|
63
|
+
.optional()
|
|
64
|
+
.describe('Acting-as target: slug or id of a managed account to create the site in (must be in your fleet from dailey_accounts). Scopes this and subsequent calls, like dailey_use_account.'),
|
|
65
|
+
},
|
|
66
|
+
async ({ name, account }) => {
|
|
67
|
+
const activeAccount = scopeAccount(account);
|
|
68
|
+
|
|
69
|
+
// Reuse the exact dailey_create_project call shape (POST /projects) but
|
|
70
|
+
// with the hardened WordPress catalog inputs. The deploy-service resolves
|
|
71
|
+
// the catalog template by image name and wires DB + storage + admin creds.
|
|
72
|
+
const res = await apiRequest<CreatedProject>('POST', '/projects', {
|
|
73
|
+
name,
|
|
74
|
+
repo_url: WORDPRESS_CATALOG_IMAGE,
|
|
75
|
+
needs_database: true,
|
|
76
|
+
needs_storage: true,
|
|
77
|
+
});
|
|
78
|
+
if (!res.ok) return textResult(formatError(res));
|
|
79
|
+
|
|
80
|
+
const p = res.data;
|
|
81
|
+
const slug = p.slug || '';
|
|
82
|
+
const adminUrl = slug ? `https://${slug}.dailey.cloud/wp-admin` : '(slug pending — check dailey_project_info)';
|
|
83
|
+
|
|
84
|
+
return textResult(
|
|
85
|
+
[
|
|
86
|
+
`WordPress site created!`,
|
|
87
|
+
``,
|
|
88
|
+
`Project ID: ${p.id}`,
|
|
89
|
+
`Name: ${p.name}`,
|
|
90
|
+
`Slug: ${slug || '(pending)'}`,
|
|
91
|
+
`Status: ${p.status || 'pending'}`,
|
|
92
|
+
`Admin URL: ${adminUrl}`,
|
|
93
|
+
`Account: ${activeAccount ?? 'self'}`,
|
|
94
|
+
...(p.build_id ? [`Build: ${p.build_id} (auto-queued — watch with dailey_deploy_status)`] : []),
|
|
95
|
+
``,
|
|
96
|
+
`The generated admin password is retrievable via:`,
|
|
97
|
+
` dailey_reveal_credential(project_id="${p.id}", key="WORDPRESS_ADMIN_PASSWORD")`,
|
|
98
|
+
`Every reveal is audited and returns a masked preview by default.`,
|
|
99
|
+
].join('\n'),
|
|
100
|
+
);
|
|
101
|
+
},
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
// ── Tool 2 — list WordPress projects (targeting spine) ───────────────────
|
|
105
|
+
server.tool(
|
|
106
|
+
'dailey_wp_list',
|
|
107
|
+
'List the WordPress projects in the effective account. Call this instead of guessing a WP site from the generic dailey_list_projects — it returns only WordPress projects with their targeting identity (project_id, slug, domain, env, db_name, namespace) and prominently the active_account you are operating in. NOTE: requires the paired customer-api feat/wp-targeting-spine deploy; until that ships this returns 404 (expected — both merge together).',
|
|
108
|
+
{
|
|
109
|
+
account: z
|
|
110
|
+
.string()
|
|
111
|
+
.optional()
|
|
112
|
+
.describe('Acting-as target: slug or id of a managed account to list within (must be in your fleet from dailey_accounts). Scopes this and subsequent calls, like dailey_use_account.'),
|
|
113
|
+
},
|
|
114
|
+
async ({ account }) => {
|
|
115
|
+
const activeAccount = scopeAccount(account);
|
|
116
|
+
|
|
117
|
+
const res = await apiRequest<WpListResponse>('GET', '/projects/wp/list');
|
|
118
|
+
if (!res.ok) return jsonResult({ active_account: activeAccount, error: formatError(res) });
|
|
119
|
+
|
|
120
|
+
const projects = res.data.projects ?? [];
|
|
121
|
+
return jsonResult({
|
|
122
|
+
active_account: activeAccount,
|
|
123
|
+
count: projects.length,
|
|
124
|
+
projects,
|
|
125
|
+
});
|
|
126
|
+
},
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
// ── Tool 3 — resolve/confirm a WordPress target (targeting spine) ────────
|
|
130
|
+
server.tool(
|
|
131
|
+
'dailey_wp_target',
|
|
132
|
+
'Resolve a WordPress project reference (id OR slug) to its exact targeting identity and echo it back: project_id, slug, domain, env, db_name, namespace, and active_account. CALL THIS BEFORE ANY DESTRUCTIVE WordPress action (import, restore, clone, delete, db writes) to confirm you are about to act on the RIGHT domain/database/account — this is the fix for editing the wrong site. If no WordPress project matches the ref in the active account, returns a clear not-found pointing you at dailey_wp_list. NOTE: requires the paired customer-api feat/wp-targeting-spine deploy; until that ships this returns 404 (expected — both merge together).',
|
|
133
|
+
{
|
|
134
|
+
project: z.string().describe('The WordPress project to resolve — its id OR slug'),
|
|
135
|
+
account: z
|
|
136
|
+
.string()
|
|
137
|
+
.optional()
|
|
138
|
+
.describe('Acting-as target: slug or id of a managed account to resolve within (must be in your fleet from dailey_accounts). Scopes this and subsequent calls, like dailey_use_account.'),
|
|
139
|
+
},
|
|
140
|
+
async ({ project, account }) => {
|
|
141
|
+
const activeAccount = scopeAccount(account);
|
|
142
|
+
|
|
143
|
+
const res = await apiRequest<WpProject & { error?: string }>(
|
|
144
|
+
'GET',
|
|
145
|
+
`/projects/wp/resolve?ref=${encodeURIComponent(project)}`,
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
if (res.status === 404) {
|
|
149
|
+
return jsonResult({
|
|
150
|
+
active_account: activeAccount,
|
|
151
|
+
resolved: false,
|
|
152
|
+
message: `No WordPress project matching '${project}' in account '${activeAccount ?? 'self'}' — call dailey_wp_list to see the options.`,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
if (!res.ok) return jsonResult({ active_account: activeAccount, resolved: false, error: formatError(res) });
|
|
156
|
+
|
|
157
|
+
const t = res.data;
|
|
158
|
+
return jsonResult({
|
|
159
|
+
active_account: t.active_account ?? activeAccount,
|
|
160
|
+
resolved: true,
|
|
161
|
+
target: {
|
|
162
|
+
project_id: t.project_id,
|
|
163
|
+
slug: t.slug,
|
|
164
|
+
domain: t.domain,
|
|
165
|
+
env: t.env,
|
|
166
|
+
db_name: t.db_name,
|
|
167
|
+
namespace: t.namespace,
|
|
168
|
+
},
|
|
169
|
+
confirm: `About to act on ${t.domain} (db=${t.db_name}, env=${t.env}) in account '${t.active_account ?? activeAccount ?? 'self'}'. Verify this is the intended site before any destructive action.`,
|
|
170
|
+
});
|
|
171
|
+
},
|
|
172
|
+
);
|
|
173
|
+
}
|