@daileyos/mcp-server 1.18.0 → 1.20.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 +2 -0
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +21 -0
- package/dist/api.js.map +1 -1
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -1
- package/dist/tools/accounts.d.ts +3 -0
- package/dist/tools/accounts.d.ts.map +1 -0
- package/dist/tools/accounts.js +81 -0
- package/dist/tools/accounts.js.map +1 -0
- package/dist/tools/addons.d.ts +3 -0
- package/dist/tools/addons.d.ts.map +1 -0
- package/dist/tools/addons.js +69 -0
- package/dist/tools/addons.js.map +1 -0
- package/dist/tools/auth.d.ts.map +1 -1
- package/dist/tools/auth.js +22 -1
- package/dist/tools/auth.js.map +1 -1
- package/dist/tools/credits.d.ts +3 -0
- package/dist/tools/credits.d.ts.map +1 -0
- package/dist/tools/credits.js +57 -0
- package/dist/tools/credits.js.map +1 -0
- package/dist/tools/email.d.ts +3 -0
- package/dist/tools/email.d.ts.map +1 -0
- package/dist/tools/email.js +61 -0
- package/dist/tools/email.js.map +1 -0
- package/dist/tools/wordpress-snapshot.d.ts +3 -0
- package/dist/tools/wordpress-snapshot.d.ts.map +1 -0
- package/dist/tools/wordpress-snapshot.js +121 -0
- package/dist/tools/wordpress-snapshot.js.map +1 -0
- package/package.json +1 -1
- package/src/api.ts +23 -0
- package/src/index.ts +11 -0
- package/src/tools/accounts.ts +111 -0
- package/src/tools/addons.ts +124 -0
- package/src/tools/auth.ts +27 -1
- package/src/tools/credits.ts +97 -0
- package/src/tools/email.ts +101 -0
- package/src/tools/wordpress-snapshot.ts +221 -0
- package/tests/wp-snapshot.test.mjs +261 -0
- package/dist/tools/buddy.d.ts +0 -3
- package/dist/tools/buddy.d.ts.map +0 -1
- package/dist/tools/buddy.js +0 -765
- package/dist/tools/buddy.js.map +0 -1
- package/dist/tools/payments.d.ts +0 -3
- package/dist/tools/payments.d.ts.map +0 -1
- package/dist/tools/payments.js +0 -96
- package/dist/tools/payments.js.map +0 -1
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { apiRequest, textResult, formatError } from '../api.js';
|
|
3
|
+
function fmtBytes(bytes) {
|
|
4
|
+
if (bytes == null)
|
|
5
|
+
return '-';
|
|
6
|
+
if (bytes < 1024)
|
|
7
|
+
return `${bytes}B`;
|
|
8
|
+
if (bytes < 1024 * 1024)
|
|
9
|
+
return `${(bytes / 1024).toFixed(1)}KB`;
|
|
10
|
+
if (bytes < 1024 * 1024 * 1024)
|
|
11
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)}MB`;
|
|
12
|
+
return `${(bytes / (1024 * 1024 * 1024)).toFixed(2)}GB`;
|
|
13
|
+
}
|
|
14
|
+
export function registerWordPressSnapshotTools(server) {
|
|
15
|
+
server.tool('dailey_wp_snapshots', 'List WordPress snapshots for a project', {
|
|
16
|
+
project_id: z.string().describe('The project ID'),
|
|
17
|
+
}, async ({ project_id }) => {
|
|
18
|
+
const res = await apiRequest('GET', `/projects/${project_id}/wp/snapshots`);
|
|
19
|
+
if (!res.ok)
|
|
20
|
+
return textResult(formatError(res));
|
|
21
|
+
const snapshots = res.data.snapshots;
|
|
22
|
+
if (!snapshots || snapshots.length === 0) {
|
|
23
|
+
return textResult('No snapshots found for this project.');
|
|
24
|
+
}
|
|
25
|
+
const lines = [
|
|
26
|
+
`Snapshots for project ${project_id}`,
|
|
27
|
+
`${'ID'.padEnd(38)} ${'Created'.padEnd(26)} ${'Kind'.padEnd(12)} ${'Status'.padEnd(12)} ${'DB'.padEnd(10)} Uploads`,
|
|
28
|
+
'─'.repeat(115),
|
|
29
|
+
];
|
|
30
|
+
for (const s of snapshots) {
|
|
31
|
+
lines.push(`${(s.id || '').padEnd(38)} ${(s.created_at || '-').padEnd(26)} ${(s.kind || '-').padEnd(12)} ${(s.status || '-').padEnd(12)} ${fmtBytes(s.db_bytes).padEnd(10)} ${fmtBytes(s.uploads_bytes)}`);
|
|
32
|
+
}
|
|
33
|
+
return textResult(lines.join('\n'));
|
|
34
|
+
});
|
|
35
|
+
server.tool('dailey_wp_snapshot', 'Create a snapshot (DB + uploads) of a WordPress project', {
|
|
36
|
+
project_id: z.string().describe('The project ID'),
|
|
37
|
+
}, async ({ project_id }) => {
|
|
38
|
+
const res = await apiRequest('POST', `/projects/${project_id}/wp/snapshot`);
|
|
39
|
+
if (!res.ok)
|
|
40
|
+
return textResult(formatError(res));
|
|
41
|
+
const { operation_id } = res.data;
|
|
42
|
+
return textResult(`Snapshot started. operation_id=${operation_id}. Poll with dailey_wp_operation_status (project_id, operation_id).`);
|
|
43
|
+
});
|
|
44
|
+
server.tool('dailey_wp_restore', 'Restore a WordPress project from a snapshot (DESTRUCTIVE — two-phase). Call WITHOUT confirm_token to get the plan; re-call WITH the returned confirm_token to execute.', {
|
|
45
|
+
project_id: z.string().describe('The project ID'),
|
|
46
|
+
snapshot_id: z.string().describe('The snapshot ID to restore'),
|
|
47
|
+
confirm_token: z.string().optional().describe('Token from the plan response. Omit to preview the plan; provide to execute. Bound to this project+snapshot, ~10min TTL.'),
|
|
48
|
+
}, async ({ project_id, snapshot_id, confirm_token }) => {
|
|
49
|
+
if (!confirm_token) {
|
|
50
|
+
// Phase 1: preview
|
|
51
|
+
const res = await apiRequest('POST', `/projects/${project_id}/wp/restore/preview`, { snapshot_id });
|
|
52
|
+
if (!res.ok)
|
|
53
|
+
return textResult(formatError(res));
|
|
54
|
+
const { plan, confirm_token: token } = res.data;
|
|
55
|
+
const lines = [];
|
|
56
|
+
if (plan.sourceLabel || plan.targetLabel) {
|
|
57
|
+
lines.push(`Restore plan: ${plan.sourceLabel ?? snapshot_id} → ${plan.targetLabel ?? 'this project'}`);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
lines.push(`Restore plan for snapshot ${snapshot_id}:`);
|
|
61
|
+
}
|
|
62
|
+
if (plan.backupFirst) {
|
|
63
|
+
lines.push('• Backs up the target first as a rollback point.');
|
|
64
|
+
}
|
|
65
|
+
if (plan.steps && plan.steps.length > 0) {
|
|
66
|
+
lines.push('');
|
|
67
|
+
lines.push('Steps:');
|
|
68
|
+
plan.steps.forEach((step, i) => {
|
|
69
|
+
lines.push(` ${i + 1}. ${step}`);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
lines.push('');
|
|
73
|
+
lines.push(`confirm_token: ${token}`);
|
|
74
|
+
lines.push('');
|
|
75
|
+
lines.push('This is destructive. To proceed, re-call dailey_wp_restore with the same project_id + snapshot_id and this confirm_token.');
|
|
76
|
+
return textResult(lines.join('\n'));
|
|
77
|
+
}
|
|
78
|
+
// Phase 2: execute
|
|
79
|
+
const res = await apiRequest('POST', `/projects/${project_id}/wp/restore`, { snapshot_id, confirm_token, confirmation: 'RESTORE' });
|
|
80
|
+
if (!res.ok) {
|
|
81
|
+
if (res.status === 409) {
|
|
82
|
+
return textResult('A restore is already in progress for this project.');
|
|
83
|
+
}
|
|
84
|
+
// 400 (expired/invalid token) — surface the message
|
|
85
|
+
return textResult(formatError(res));
|
|
86
|
+
}
|
|
87
|
+
const { operation_id } = res.data;
|
|
88
|
+
return textResult(`Restore started. operation_id=${operation_id}. Poll with dailey_wp_operation_status.`);
|
|
89
|
+
});
|
|
90
|
+
server.tool('dailey_wp_operation_status', 'Check the status of a WordPress snapshot/restore operation', {
|
|
91
|
+
project_id: z.string().describe('The project ID'),
|
|
92
|
+
operation_id: z.string().describe('The operation ID'),
|
|
93
|
+
}, async ({ project_id, operation_id }) => {
|
|
94
|
+
const res = await apiRequest('GET', `/projects/${project_id}/wp/operations/${operation_id}`);
|
|
95
|
+
if (!res.ok)
|
|
96
|
+
return textResult(formatError(res));
|
|
97
|
+
const op = res.data.operation;
|
|
98
|
+
const lines = [];
|
|
99
|
+
if (op.type)
|
|
100
|
+
lines.push(`Type: ${op.type}`);
|
|
101
|
+
lines.push(`Status: ${op.status ?? '-'}`);
|
|
102
|
+
if (op.current_step)
|
|
103
|
+
lines.push(`Current step: ${op.current_step}`);
|
|
104
|
+
if (op.verify != null)
|
|
105
|
+
lines.push(`Verify: ${JSON.stringify(op.verify)}`);
|
|
106
|
+
if (op.error)
|
|
107
|
+
lines.push(`Error: ${op.error}`);
|
|
108
|
+
if (op.backup_snapshot_id)
|
|
109
|
+
lines.push(`Backup snapshot ID: ${op.backup_snapshot_id}`);
|
|
110
|
+
if (op.step_log && op.step_log.length > 0) {
|
|
111
|
+
const tail = op.step_log.slice(-10);
|
|
112
|
+
lines.push('');
|
|
113
|
+
lines.push('Step log (last 10):');
|
|
114
|
+
for (const entry of tail) {
|
|
115
|
+
lines.push(` ${entry}`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return textResult(lines.join('\n'));
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=wordpress-snapshot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wordpress-snapshot.js","sourceRoot":"","sources":["../../src/tools/wordpress-snapshot.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,UAAU,EAAc,WAAW,EAAE,MAAM,WAAW,CAAC;AAoD5E,SAAS,QAAQ,CAAC,KAAc;IAC9B,IAAI,KAAK,IAAI,IAAI;QAAE,OAAO,GAAG,CAAC;IAC9B,IAAI,KAAK,GAAG,IAAI;QAAE,OAAO,GAAG,KAAK,GAAG,CAAC;IACrC,IAAI,KAAK,GAAG,IAAI,GAAG,IAAI;QAAE,OAAO,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC;IACjE,IAAI,KAAK,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI;QAAE,OAAO,GAAG,CAAC,KAAK,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,OA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AI,IAAI,EAAE,CAAC;gBACzB,KAAK,CAAC,IAAI,CAAC,KAAK,KAAK,EAAE,CAAC,CAAC;YAC3B,CAAC;QACH,CAAC;QAED,OAAO,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACtC,CAAC,CACF,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
package/src/api.ts
CHANGED
|
@@ -46,6 +46,24 @@ export function resolveToken(): string {
|
|
|
46
46
|
return readCliStoredToken() || '';
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
// Active managed-account context for the "manager / managed-accounts" capability.
|
|
50
|
+
// A manager (a Dailey account) can operate inside other accounts that granted
|
|
51
|
+
// them a consent-based grant by sending header `X-Dailey-Account: <slug|id>`;
|
|
52
|
+
// the server verifies a LIVE grant and scopes the request to that account (no
|
|
53
|
+
// re-login). This is SESSION-SCOPED: it persists for the MCP server process
|
|
54
|
+
// lifetime, which is what we want — an agent calls `dailey_use_account` once and
|
|
55
|
+
// every subsequent tool call operates within that account until it clears or
|
|
56
|
+
// switches. When unset, no header is sent (normal self-scoped behavior).
|
|
57
|
+
let activeAccount: string | undefined;
|
|
58
|
+
|
|
59
|
+
export function setActiveAccount(slugOrId: string | undefined): void {
|
|
60
|
+
activeAccount = slugOrId && slugOrId.trim() ? slugOrId.trim() : undefined;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function getActiveAccount(): string | undefined {
|
|
64
|
+
return activeAccount;
|
|
65
|
+
}
|
|
66
|
+
|
|
49
67
|
// Credential preflight lives in index.ts so it can distinguish TTY vs
|
|
50
68
|
// MCP-stdio invocation and emit a JSON-RPC-shaped error instead of just
|
|
51
69
|
// dying with a stderr line that Claude Code doesn't surface.
|
|
@@ -93,6 +111,11 @@ export async function apiRequest<T = unknown>(
|
|
|
93
111
|
// first successful MCP connection (onboarding progress).
|
|
94
112
|
'X-Dailey-Source': 'mcp',
|
|
95
113
|
};
|
|
114
|
+
// Manager / managed-accounts: when an active account is set, scope every
|
|
115
|
+
// request to it. The server verifies a live consent grant; absent header =
|
|
116
|
+
// normal self-scoped behavior.
|
|
117
|
+
const acct = getActiveAccount();
|
|
118
|
+
if (acct) headers['X-Dailey-Account'] = acct;
|
|
96
119
|
const options: RequestInit = { method, headers };
|
|
97
120
|
if (body && (method === 'POST' || method === 'PUT' || method === 'PATCH')) {
|
|
98
121
|
options.body = JSON.stringify(body);
|
package/src/index.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
|
|
|
5
5
|
|
|
6
6
|
import { hasCredentials } from './api.js';
|
|
7
7
|
import { registerAuthTools } from './tools/auth.js';
|
|
8
|
+
import { registerAccountTools } from './tools/accounts.js';
|
|
8
9
|
import { registerProjectTools } from './tools/projects.js';
|
|
9
10
|
import { registerDeployTools } from './tools/deploy.js';
|
|
10
11
|
import { registerDeployStatusTools } from './tools/deploy-status.js';
|
|
@@ -22,11 +23,15 @@ import { registerBillingTools } from './tools/billing.js';
|
|
|
22
23
|
import { registerPlatformTools } from './tools/platform.js';
|
|
23
24
|
import { registerStorageTools } from './tools/storage.js';
|
|
24
25
|
import { registerAiTools } from './tools/ai.js';
|
|
26
|
+
import { registerEmailTools } from './tools/email.js';
|
|
27
|
+
import { registerCreditTools } from './tools/credits.js';
|
|
28
|
+
import { registerAddonTools } from './tools/addons.js';
|
|
25
29
|
import { registerImageTools } from './tools/images.js';
|
|
26
30
|
import { registerProcessTools } from './tools/processes.js';
|
|
27
31
|
import { registerLifecycleTools } from './tools/lifecycle.js';
|
|
28
32
|
import { registerBackupTools } from './tools/backups.js';
|
|
29
33
|
import { registerWordPressMigrateTools } from './tools/wordpress-migrate.js';
|
|
34
|
+
import { registerWordPressSnapshotTools } from './tools/wordpress-snapshot.js';
|
|
30
35
|
import { registerResourceConfigTools } from './tools/resource-config.js';
|
|
31
36
|
import { registerLinkTools } from './tools/links.js';
|
|
32
37
|
import { registerCredentialRevealTools } from './tools/credentials-reveal.js';
|
|
@@ -111,9 +116,13 @@ const server = new McpServer({
|
|
|
111
116
|
|
|
112
117
|
// Core + identity
|
|
113
118
|
registerAuthTools(server);
|
|
119
|
+
registerAccountTools(server);
|
|
114
120
|
registerPlatformTools(server);
|
|
115
121
|
registerUsageTools(server);
|
|
116
122
|
registerBillingTools(server);
|
|
123
|
+
// À-la-carte billing surfaces — prepaid credits + capacity add-ons.
|
|
124
|
+
registerCreditTools(server);
|
|
125
|
+
registerAddonTools(server);
|
|
117
126
|
|
|
118
127
|
// Projects + deploys
|
|
119
128
|
registerProjectTools(server);
|
|
@@ -140,8 +149,10 @@ registerDbTools(server);
|
|
|
140
149
|
registerMigrateTools(server);
|
|
141
150
|
registerStorageTools(server);
|
|
142
151
|
registerAiTools(server);
|
|
152
|
+
registerEmailTools(server);
|
|
143
153
|
registerBackupTools(server);
|
|
144
154
|
registerWordPressMigrateTools(server);
|
|
155
|
+
registerWordPressSnapshotTools(server);
|
|
145
156
|
|
|
146
157
|
// Runtime operations — exec into a pod, run one-off jobs
|
|
147
158
|
registerExecRunTools(server);
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import {
|
|
4
|
+
apiRequest,
|
|
5
|
+
formatError,
|
|
6
|
+
jsonResult,
|
|
7
|
+
getActiveAccount,
|
|
8
|
+
setActiveAccount,
|
|
9
|
+
} from '../api.js';
|
|
10
|
+
|
|
11
|
+
interface ManagedAccount {
|
|
12
|
+
managed_customer_id: string;
|
|
13
|
+
slug: string;
|
|
14
|
+
name: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const AUTH_REQUIRED_ERROR = {
|
|
18
|
+
error_code: 'DAILEY_AUTH_REQUIRED',
|
|
19
|
+
message: 'Not authenticated',
|
|
20
|
+
remediation: 'Run `dailey auth setup` in your terminal',
|
|
21
|
+
help_url: 'https://docs.dailey.cloud/auth',
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export function registerAccountTools(server: McpServer) {
|
|
25
|
+
server.tool(
|
|
26
|
+
'dailey_accounts',
|
|
27
|
+
'List the managed accounts (the "fleet") this user manages — other Dailey accounts that have granted you a consent-based access grant. Returns each account\'s managed_customer_id, slug, and name, plus which account is currently active for this session. Empty fleet means you manage no other accounts. Use `dailey_use_account` to switch into one of these accounts; after switching, all other dailey tools operate inside that account until you clear or switch.',
|
|
28
|
+
{},
|
|
29
|
+
async () => {
|
|
30
|
+
const res = await apiRequest<ManagedAccount[]>('GET', '/customers/me/managed-accounts');
|
|
31
|
+
if (!res.ok) {
|
|
32
|
+
if (res.status === 401 || res.status === 403) {
|
|
33
|
+
return jsonResult(AUTH_REQUIRED_ERROR);
|
|
34
|
+
}
|
|
35
|
+
return jsonResult({ error: formatError(res) });
|
|
36
|
+
}
|
|
37
|
+
const fleet = Array.isArray(res.data) ? res.data : [];
|
|
38
|
+
return jsonResult({
|
|
39
|
+
active_account: getActiveAccount() ?? null,
|
|
40
|
+
operating_as: getActiveAccount() ? 'managed_account' : 'self',
|
|
41
|
+
count: fleet.length,
|
|
42
|
+
accounts: fleet,
|
|
43
|
+
});
|
|
44
|
+
},
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
server.tool(
|
|
48
|
+
'dailey_use_account',
|
|
49
|
+
'Switch the active managed-account context for this MCP session. Pass `account` (a slug or id from `dailey_accounts`) to operate INSIDE that managed account; after calling this, ALL other dailey tools act inside that managed account until you clear or switch. Pass `clear: true` to stop and operate as yourself again. The target account must be in your fleet (`dailey_accounts`) — an invalid account is rejected. This context is session-scoped: it persists for the life of this MCP server.',
|
|
50
|
+
{
|
|
51
|
+
account: z
|
|
52
|
+
.string()
|
|
53
|
+
.optional()
|
|
54
|
+
.describe('The slug or id of a managed account to operate within (must be in your fleet from dailey_accounts)'),
|
|
55
|
+
clear: z
|
|
56
|
+
.boolean()
|
|
57
|
+
.optional()
|
|
58
|
+
.describe('If true, clear the active managed account and operate as yourself again'),
|
|
59
|
+
},
|
|
60
|
+
async ({ account, clear }) => {
|
|
61
|
+
if (clear) {
|
|
62
|
+
setActiveAccount(undefined);
|
|
63
|
+
return jsonResult({
|
|
64
|
+
ok: true,
|
|
65
|
+
active_account: null,
|
|
66
|
+
operating_as: 'self',
|
|
67
|
+
message: 'Cleared managed-account context — now operating as yourself.',
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (!account || !account.trim()) {
|
|
72
|
+
return jsonResult({
|
|
73
|
+
ok: false,
|
|
74
|
+
message: 'Provide `account` (a slug or id from dailey_accounts) to switch into, or `clear: true` to operate as yourself.',
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const res = await apiRequest<ManagedAccount[]>('GET', '/customers/me/managed-accounts');
|
|
79
|
+
if (!res.ok) {
|
|
80
|
+
if (res.status === 401 || res.status === 403) {
|
|
81
|
+
return jsonResult(AUTH_REQUIRED_ERROR);
|
|
82
|
+
}
|
|
83
|
+
return jsonResult({ ok: false, error: formatError(res) });
|
|
84
|
+
}
|
|
85
|
+
const fleet = Array.isArray(res.data) ? res.data : [];
|
|
86
|
+
const target = account.trim();
|
|
87
|
+
const match = fleet.find(
|
|
88
|
+
(a) => a.slug === target || a.managed_customer_id === target,
|
|
89
|
+
);
|
|
90
|
+
if (!match) {
|
|
91
|
+
return jsonResult({
|
|
92
|
+
ok: false,
|
|
93
|
+
message: `Account "${target}" is not in your managed-accounts fleet. Call dailey_accounts to list the accounts you manage.`,
|
|
94
|
+
available: fleet.map((a) => ({ slug: a.slug, name: a.name })),
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Use the slug as the header value when available (matches the dashboard/CLI
|
|
99
|
+
// convention); the server accepts either slug or id.
|
|
100
|
+
const activeValue = match.slug || match.managed_customer_id;
|
|
101
|
+
setActiveAccount(activeValue);
|
|
102
|
+
return jsonResult({
|
|
103
|
+
ok: true,
|
|
104
|
+
active_account: activeValue,
|
|
105
|
+
operating_as: 'managed_account',
|
|
106
|
+
account: match,
|
|
107
|
+
message: `Now operating within "${match.name}" (${match.slug}). All subsequent dailey tool calls run inside this account until you clear or switch.`,
|
|
108
|
+
});
|
|
109
|
+
},
|
|
110
|
+
);
|
|
111
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { apiRequest, formatError, textResult } from '../api.js';
|
|
4
|
+
|
|
5
|
+
// À-la-carte capacity add-ons (pay-at-purchase Stripe subscriptions):
|
|
6
|
+
// extra_vcpu, extra_ram, extra_db_storage, extra_object_storage,
|
|
7
|
+
// db_replica, app_ha, email_pro (+ managed_ops / extra_core_users_*).
|
|
8
|
+
// GET /billing/addons = active add-ons; GET /billing/addons/catalog = available
|
|
9
|
+
// types + pricing. POST /billing/addons returns { checkout_url } (pay first) or,
|
|
10
|
+
// when no Stripe price is configured, provisions immediately ({ addon, message }).
|
|
11
|
+
interface ActiveAddon {
|
|
12
|
+
id: string;
|
|
13
|
+
addon_type: string;
|
|
14
|
+
quantity: number;
|
|
15
|
+
status: string;
|
|
16
|
+
created_at?: string;
|
|
17
|
+
unit_price?: number;
|
|
18
|
+
unit_label?: string;
|
|
19
|
+
monthly_cost?: number;
|
|
20
|
+
}
|
|
21
|
+
interface AddonsListResponse {
|
|
22
|
+
addons: ActiveAddon[];
|
|
23
|
+
total_monthly: number;
|
|
24
|
+
}
|
|
25
|
+
interface CatalogItem {
|
|
26
|
+
type: string;
|
|
27
|
+
name: string;
|
|
28
|
+
unit_price: number;
|
|
29
|
+
unit_label: string;
|
|
30
|
+
description: string;
|
|
31
|
+
}
|
|
32
|
+
interface CatalogResponse {
|
|
33
|
+
addons: CatalogItem[];
|
|
34
|
+
}
|
|
35
|
+
interface AddonPurchaseResponse {
|
|
36
|
+
checkout_url?: string | null;
|
|
37
|
+
session_id?: string;
|
|
38
|
+
addon?: { id: string; addon_type: string; quantity: number; unit_price: number; monthly_cost: number };
|
|
39
|
+
message?: string;
|
|
40
|
+
note?: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function registerAddonTools(server: McpServer) {
|
|
44
|
+
server.tool(
|
|
45
|
+
'dailey_addons',
|
|
46
|
+
'List à-la-carte capacity add-ons: the account\'s ACTIVE add-ons (with monthly cost) plus the AVAILABLE catalog (extra_vcpu, extra_ram, extra_db_storage, extra_object_storage, db_replica, app_ha, email_pro, ...) and per-unit pricing. Purchase with dailey_addon_purchase; cancel with dailey_addon_cancel.',
|
|
47
|
+
{},
|
|
48
|
+
async () => {
|
|
49
|
+
const [activeRes, catalogRes] = await Promise.all([
|
|
50
|
+
apiRequest<AddonsListResponse>('GET', '/billing/addons'),
|
|
51
|
+
apiRequest<CatalogResponse>('GET', '/billing/addons/catalog'),
|
|
52
|
+
]);
|
|
53
|
+
if (!activeRes.ok) return textResult(formatError(activeRes));
|
|
54
|
+
|
|
55
|
+
const lines: string[] = ['Active add-ons:'];
|
|
56
|
+
const active = activeRes.data.addons || [];
|
|
57
|
+
if (active.length === 0) {
|
|
58
|
+
lines.push(' (none)');
|
|
59
|
+
} else {
|
|
60
|
+
for (const a of active) {
|
|
61
|
+
lines.push(
|
|
62
|
+
` ${a.id} ${a.addon_type} x${a.quantity} $${a.monthly_cost ?? 0}/mo [${a.status}]`,
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
lines.push(` Total: $${activeRes.data.total_monthly ?? 0}/mo`);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (catalogRes.ok) {
|
|
69
|
+
lines.push('');
|
|
70
|
+
lines.push('Available add-ons (catalog):');
|
|
71
|
+
for (const c of catalogRes.data.addons || []) {
|
|
72
|
+
lines.push(` ${c.type} $${c.unit_price}/${c.unit_label} — ${c.description || c.name}`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
lines.push('');
|
|
76
|
+
lines.push('Purchase: dailey_addon_purchase (type[, quantity]) → returns a Stripe Checkout URL to pay.');
|
|
77
|
+
return textResult(lines.join('\n'));
|
|
78
|
+
},
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
server.tool(
|
|
82
|
+
'dailey_addon_purchase',
|
|
83
|
+
'Purchase an à-la-carte capacity add-on (extra_vcpu, extra_ram, extra_db_storage, extra_object_storage, db_replica, app_ha, email_pro, ...). PAY-AT-PURCHASE and billing-owner-only: the normal response is a Stripe Checkout URL the user MUST open to pay the monthly subscription before the capacity is granted — do NOT treat the add-on as active until payment completes. (Some early-stage types with no Stripe price provision immediately.) See dailey_addons for valid types + pricing.',
|
|
84
|
+
{
|
|
85
|
+
addon_type: z.string().describe('Add-on type, e.g. extra_vcpu, extra_ram, extra_db_storage, extra_object_storage, db_replica, app_ha, email_pro'),
|
|
86
|
+
quantity: z.number().int().min(1).optional().describe('Number of units (default 1)'),
|
|
87
|
+
},
|
|
88
|
+
async ({ addon_type, quantity }) => {
|
|
89
|
+
const body: Record<string, unknown> = { addon_type };
|
|
90
|
+
if (typeof quantity === 'number') body.quantity = quantity;
|
|
91
|
+
const res = await apiRequest<AddonPurchaseResponse>('POST', '/billing/addons', body);
|
|
92
|
+
if (!res.ok) return textResult(formatError(res));
|
|
93
|
+
const d = res.data;
|
|
94
|
+
if (d.checkout_url) {
|
|
95
|
+
return textResult(
|
|
96
|
+
[
|
|
97
|
+
`Add-on "${addon_type}" x${quantity ?? 1} — pay-at-purchase.`,
|
|
98
|
+
'',
|
|
99
|
+
'➜ Open this URL to complete the subscription payment:',
|
|
100
|
+
d.checkout_url,
|
|
101
|
+
'',
|
|
102
|
+
'The capacity is granted automatically once the Stripe Checkout is paid. It is NOT active yet.',
|
|
103
|
+
].join('\n'),
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
// No Stripe price configured — provisioned immediately.
|
|
107
|
+
const lines = [d.message || `Add-on "${addon_type}" added.`];
|
|
108
|
+
if (d.addon) lines.push(`id: ${d.addon.id} $${d.addon.monthly_cost}/mo`);
|
|
109
|
+
if (d.note) lines.push(d.note);
|
|
110
|
+
return textResult(lines.join('\n'));
|
|
111
|
+
},
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
server.tool(
|
|
115
|
+
'dailey_addon_cancel',
|
|
116
|
+
'Cancel an active à-la-carte add-on by its add-on id (from dailey_addons). Cancels the Stripe subscription item and removes the capacity from the account quota. Billing-owner-only.',
|
|
117
|
+
{ addon_id: z.string().describe('The add-on id to cancel (from dailey_addons)') },
|
|
118
|
+
async ({ addon_id }) => {
|
|
119
|
+
const res = await apiRequest<{ message: string; addon_id: string }>('DELETE', `/billing/addons/${addon_id}`);
|
|
120
|
+
if (!res.ok) return textResult(formatError(res));
|
|
121
|
+
return textResult(`${res.data.message || 'Add-on cancelled'} (${res.data.addon_id || addon_id}).`);
|
|
122
|
+
},
|
|
123
|
+
);
|
|
124
|
+
}
|
package/src/tools/auth.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import { apiRequest, formatError, textResult, jsonResult } from '../api.js';
|
|
3
|
+
import { apiRequest, formatError, textResult, jsonResult, getActiveAccount } from '../api.js';
|
|
4
|
+
|
|
5
|
+
interface ManagedAccount {
|
|
6
|
+
managed_customer_id: string;
|
|
7
|
+
slug: string;
|
|
8
|
+
name: string;
|
|
9
|
+
}
|
|
4
10
|
|
|
5
11
|
interface AuthEnableResponse {
|
|
6
12
|
ok: boolean;
|
|
@@ -100,12 +106,32 @@ export function registerAuthTools(server: McpServer) {
|
|
|
100
106
|
source = 'session';
|
|
101
107
|
}
|
|
102
108
|
|
|
109
|
+
// Manager / managed-accounts: report whether this user manages any other
|
|
110
|
+
// accounts (the fleet) and which one — if any — is the active context for
|
|
111
|
+
// this session. A non-empty fleet means they can `dailey_use_account` to
|
|
112
|
+
// operate inside one of these accounts. Best-effort: a failure here must
|
|
113
|
+
// not break auth-status, so we swallow errors and report manager: null.
|
|
114
|
+
let fleet: ManagedAccount[] = [];
|
|
115
|
+
try {
|
|
116
|
+
const mres = await apiRequest<ManagedAccount[]>('GET', '/customers/me/managed-accounts');
|
|
117
|
+
if (mres.ok && Array.isArray(mres.data)) fleet = mres.data;
|
|
118
|
+
} catch {
|
|
119
|
+
// ignore — leave fleet empty
|
|
120
|
+
}
|
|
121
|
+
const active = getActiveAccount() ?? null;
|
|
122
|
+
|
|
103
123
|
return jsonResult({
|
|
104
124
|
authenticated: true,
|
|
105
125
|
source,
|
|
106
126
|
account: u.name,
|
|
107
127
|
email: u.email,
|
|
108
128
|
recommended_action: null,
|
|
129
|
+
manager: {
|
|
130
|
+
is_manager: fleet.length > 0,
|
|
131
|
+
managed_accounts: fleet,
|
|
132
|
+
active_account: active,
|
|
133
|
+
operating_as: active ? 'managed_account' : 'self',
|
|
134
|
+
},
|
|
109
135
|
});
|
|
110
136
|
},
|
|
111
137
|
);
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { apiRequest, formatError, textResult } from '../api.js';
|
|
4
|
+
|
|
5
|
+
// Prepaid credits (opt-in $ balance drawn down in real time by metered AI /
|
|
6
|
+
// Compute / Email overage). GET returns balance + settings + recent ledger;
|
|
7
|
+
// top-up runs a one-time Stripe Checkout (kind:credit_topup) whose URL the
|
|
8
|
+
// user must open to pay.
|
|
9
|
+
interface CreditAccountResponse {
|
|
10
|
+
balance_cents?: number;
|
|
11
|
+
prepaid_enabled?: boolean;
|
|
12
|
+
auto_recharge_enabled?: boolean;
|
|
13
|
+
auto_recharge_threshold_cents?: number;
|
|
14
|
+
auto_recharge_amount_cents?: number;
|
|
15
|
+
stripe_payment_method_id?: string | null;
|
|
16
|
+
editable?: boolean;
|
|
17
|
+
ledger?: Array<{
|
|
18
|
+
created_at?: string;
|
|
19
|
+
delta_cents?: number;
|
|
20
|
+
reason?: string;
|
|
21
|
+
ref?: string | null;
|
|
22
|
+
}>;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface TopupResponse {
|
|
26
|
+
checkout_url?: string | null;
|
|
27
|
+
session_id?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const dollars = (cents: number | undefined) =>
|
|
31
|
+
`$${(((cents ?? 0)) / 100).toFixed(2)}`;
|
|
32
|
+
|
|
33
|
+
export function registerCreditTools(server: McpServer) {
|
|
34
|
+
server.tool(
|
|
35
|
+
'dailey_credits',
|
|
36
|
+
'Show the account prepaid credit balance and settings: current balance, whether prepaid is enabled, auto-recharge config, and the recent credit ledger. Prepaid credits are drawn down in real time by metered AI / Compute / Email overage; a $0 balance hard-stops those. Top up with dailey_credits_topup.',
|
|
37
|
+
{},
|
|
38
|
+
async () => {
|
|
39
|
+
const res = await apiRequest<CreditAccountResponse>('GET', '/account/credits');
|
|
40
|
+
if (!res.ok) return textResult(formatError(res));
|
|
41
|
+
const d = res.data;
|
|
42
|
+
const lines = [
|
|
43
|
+
'Prepaid Credits',
|
|
44
|
+
`Balance: ${dollars(d.balance_cents)}`,
|
|
45
|
+
`Prepaid enabled: ${d.prepaid_enabled ? 'yes' : 'no'}`,
|
|
46
|
+
`Auto-recharge: ${d.auto_recharge_enabled ? 'on' : 'off'}`,
|
|
47
|
+
];
|
|
48
|
+
if (d.auto_recharge_enabled) {
|
|
49
|
+
lines.push(` when below: ${dollars(d.auto_recharge_threshold_cents)}`);
|
|
50
|
+
lines.push(` top up by: ${dollars(d.auto_recharge_amount_cents)}`);
|
|
51
|
+
}
|
|
52
|
+
const ledger = d.ledger || [];
|
|
53
|
+
lines.push('');
|
|
54
|
+
lines.push('Recent ledger:');
|
|
55
|
+
if (ledger.length === 0) {
|
|
56
|
+
lines.push(' (none)');
|
|
57
|
+
} else {
|
|
58
|
+
for (const e of ledger.slice(0, 20)) {
|
|
59
|
+
const sign = (e.delta_cents ?? 0) >= 0 ? '+' : '-';
|
|
60
|
+
lines.push(
|
|
61
|
+
` ${e.created_at || '?'} ${sign}${dollars(Math.abs(e.delta_cents ?? 0))} ${e.reason || ''}${e.ref ? ` (${e.ref})` : ''}`,
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
lines.push('');
|
|
66
|
+
lines.push('Top up with dailey_credits_topup (opens a Stripe Checkout).');
|
|
67
|
+
return textResult(lines.join('\n'));
|
|
68
|
+
},
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
server.tool(
|
|
72
|
+
'dailey_credits_topup',
|
|
73
|
+
'Buy a one-time prepaid credit top-up. Returns a Stripe Checkout URL the user MUST open to pay — the balance is only credited after payment completes (do NOT treat credits as added until then). The card is saved for off_session auto-recharge. Amount is $5–$1,000.',
|
|
74
|
+
{
|
|
75
|
+
amount_usd: z.number().min(5).max(1000).describe('Top-up amount in US dollars (5 to 1000).'),
|
|
76
|
+
},
|
|
77
|
+
async ({ amount_usd }) => {
|
|
78
|
+
const amount_cents = Math.round(amount_usd * 100);
|
|
79
|
+
const res = await apiRequest<TopupResponse>('POST', '/account/credits/checkout', { amount_cents });
|
|
80
|
+
if (!res.ok) return textResult(formatError(res));
|
|
81
|
+
const d = res.data;
|
|
82
|
+
if (!d.checkout_url) {
|
|
83
|
+
return textResult('Top-up created but no checkout_url was returned. Retry, or top up from Billing → Credits.');
|
|
84
|
+
}
|
|
85
|
+
return textResult(
|
|
86
|
+
[
|
|
87
|
+
`Prepaid top-up of ${dollars(amount_cents)}.`,
|
|
88
|
+
'',
|
|
89
|
+
'➜ Open this URL to complete payment:',
|
|
90
|
+
d.checkout_url,
|
|
91
|
+
'',
|
|
92
|
+
'Your balance is credited automatically once the Stripe Checkout is paid. It is NOT added yet.',
|
|
93
|
+
].join('\n'),
|
|
94
|
+
);
|
|
95
|
+
},
|
|
96
|
+
);
|
|
97
|
+
}
|