@roxyon/mcp 0.1.2 → 0.3.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/bin/roxyon-mcp-http.js +1 -0
- package/dist/chunk-U6ILIHUR.js +818 -0
- package/dist/chunk-U6ILIHUR.js.map +1 -0
- package/dist/http-entry.js +261 -0
- package/dist/http-entry.js.map +1 -0
- package/dist/index.js +4 -579
- package/dist/index.js.map +1 -1
- package/package.json +11 -7
- package/resources/recipe-web-deploy.md +51 -0
|
@@ -0,0 +1,818 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/server.ts
|
|
4
|
+
import { createRequire } from "module";
|
|
5
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
6
|
+
|
|
7
|
+
// src/prompts.ts
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
function registerPrompts(server) {
|
|
10
|
+
server.registerPrompt(
|
|
11
|
+
"scaffold-lumen-app",
|
|
12
|
+
{
|
|
13
|
+
title: "Scaffold a LumenJS + Roxyon app",
|
|
14
|
+
description: "Guidance for creating a new LumenJS SPA wired to the Roxyon BaaS and ready to deploy.",
|
|
15
|
+
argsSchema: {
|
|
16
|
+
idea: z.string().describe("What the app should do."),
|
|
17
|
+
dir: z.string().optional().describe("Where to create it.")
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
({ idea, dir }) => ({
|
|
21
|
+
messages: [
|
|
22
|
+
{
|
|
23
|
+
role: "user",
|
|
24
|
+
content: {
|
|
25
|
+
type: "text",
|
|
26
|
+
text: `Build a LumenJS single-page app: ${idea}
|
|
27
|
+
|
|
28
|
+
Steps:
|
|
29
|
+
1. Read the "roxyon://docs/lumenjs" resource \u2014 follow V1 rules exactly (one bind per region, no nested bind, build option lists in JS not :for, check every BaaS write for an error field).
|
|
30
|
+
2. Read "roxyon://docs/baas" for the data/auth API.
|
|
31
|
+
3. Scaffold with the LumenJS CLI: \`lm create <name>\`${dir ? ` in ${dir}` : ""}. Put views under src/views/, wire the BaaS in src/index.js via config.json.
|
|
32
|
+
4. When it runs locally (\`lm serve\`), call roxyon_init then roxyon_deploy (dry run first, then confirm:true).`
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
]
|
|
36
|
+
})
|
|
37
|
+
);
|
|
38
|
+
server.registerPrompt(
|
|
39
|
+
"build-and-ship-site",
|
|
40
|
+
{
|
|
41
|
+
title: "Build a site and host it on Roxyon",
|
|
42
|
+
description: "Generate a static site (or no-build LumenJS SPA) in the conversation and publish it to a Roxyon host \u2014 for the hosted connector, no local files.",
|
|
43
|
+
argsSchema: {
|
|
44
|
+
brief: z.string().describe("What the site should be."),
|
|
45
|
+
host: z.string().describe("Where to host it, e.g. promo.mycompany.com")
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
({ brief, host }) => ({
|
|
49
|
+
messages: [
|
|
50
|
+
{
|
|
51
|
+
role: "user",
|
|
52
|
+
content: {
|
|
53
|
+
type: "text",
|
|
54
|
+
text: `Build and publish a website to ${host}.
|
|
55
|
+
|
|
56
|
+
Brief: ${brief}
|
|
57
|
+
|
|
58
|
+
1. Read "roxyon://docs/recipe" and follow it. (Read "roxyon://docs/lumenjs" too only if the site needs reactivity.)
|
|
59
|
+
2. If ${host} is not already on the account, roxyon_add_domain { host: "${host}", confirm: true } (add spa:true only for a real single-page app).
|
|
60
|
+
3. Generate the site \u2014 self-contained static files, relative paths, real .html per page or <page>/index.html, \u226460 files / 2 MB.
|
|
61
|
+
4. roxyon_deploy_content { host: "${host}", files: [...], clean: true, confirm: true } (dry-run first).
|
|
62
|
+
5. roxyon_list_files { host: "${host}" } to verify, then give me the URL. Note that HTTPS may take a couple of minutes on a brand-new host.`
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
]
|
|
66
|
+
})
|
|
67
|
+
);
|
|
68
|
+
server.registerPrompt(
|
|
69
|
+
"deploy-to-roxyon",
|
|
70
|
+
{
|
|
71
|
+
title: "Deploy this project to Roxyon",
|
|
72
|
+
description: "Walk through deploying the current project to Roxyon infrastructure.",
|
|
73
|
+
argsSchema: { dir: z.string().describe("Absolute path to the project.") }
|
|
74
|
+
},
|
|
75
|
+
({ dir }) => ({
|
|
76
|
+
messages: [
|
|
77
|
+
{
|
|
78
|
+
role: "user",
|
|
79
|
+
content: {
|
|
80
|
+
type: "text",
|
|
81
|
+
text: `Deploy the project at ${dir} to Roxyon.
|
|
82
|
+
|
|
83
|
+
1. If there is no roxyon.json, call roxyon_init (it detects the runtime; ask me which host if there are several).
|
|
84
|
+
2. Call roxyon_deploy with just the dir first to see the plan.
|
|
85
|
+
3. If the plan looks right, call roxyon_deploy again with confirm:true.
|
|
86
|
+
4. For an app runtime, report the final status and, if it failed, the last error from roxyon_app_status.`
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
]
|
|
90
|
+
})
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// src/resources.ts
|
|
95
|
+
import { readFile } from "fs/promises";
|
|
96
|
+
import { dirname, join } from "path";
|
|
97
|
+
import { fileURLToPath } from "url";
|
|
98
|
+
var RESOURCE_DIR = join(dirname(fileURLToPath(import.meta.url)), "..", "resources");
|
|
99
|
+
var DOCS = [
|
|
100
|
+
{
|
|
101
|
+
uri: "roxyon://docs/lumenjs",
|
|
102
|
+
name: "lumenjs-reference",
|
|
103
|
+
file: "lumenjs.md",
|
|
104
|
+
title: "LumenJS \u2014 complete reference",
|
|
105
|
+
description: "Full LumenJS V1 reference for building SPAs with vanilla JS/HTML/CSS (no build step), contrasted with Vue/React. Read before writing .view files."
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
uri: "roxyon://docs/baas",
|
|
109
|
+
name: "baas-reference",
|
|
110
|
+
file: "baas.md",
|
|
111
|
+
title: "Roxyon BaaS reference",
|
|
112
|
+
description: "The Roxyon Backend-as-a-Service REST API: endpoints, auth flow, query rules, and the resolve-on-failure write behaviour."
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
uri: "roxyon://docs/deploy",
|
|
116
|
+
name: "deploy-reference",
|
|
117
|
+
file: "deploy.md",
|
|
118
|
+
title: "Deploying to Roxyon",
|
|
119
|
+
description: "How roxyon_init / roxyon_deploy work, the roxyon.json schema, static vs app deploys, env vars, and git push-to-deploy."
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
uri: "roxyon://docs/recipe",
|
|
123
|
+
name: "web-deploy-recipe",
|
|
124
|
+
file: "recipe-web-deploy.md",
|
|
125
|
+
title: "Recipe \u2014 build a site and host it",
|
|
126
|
+
description: 'The end-to-end flow for "build a landing page and put it on sub.mydomain.com" over the hosted connector: roxyon_add_domain \u2192 roxyon_deploy_content \u2192 roxyon_list_files.'
|
|
127
|
+
}
|
|
128
|
+
];
|
|
129
|
+
function registerResources(server) {
|
|
130
|
+
for (const doc of DOCS) {
|
|
131
|
+
server.registerResource(
|
|
132
|
+
doc.name,
|
|
133
|
+
doc.uri,
|
|
134
|
+
{ title: doc.title, description: doc.description, mimeType: "text/markdown" },
|
|
135
|
+
async () => {
|
|
136
|
+
const body = await readFile(join(RESOURCE_DIR, doc.file), "utf8");
|
|
137
|
+
return { contents: [{ uri: doc.uri, mimeType: "text/markdown", text: body }] };
|
|
138
|
+
}
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// src/tools.ts
|
|
144
|
+
import { formatEnv } from "@roxyon/api-client";
|
|
145
|
+
import {
|
|
146
|
+
buildIgnore,
|
|
147
|
+
buildProjectConfig,
|
|
148
|
+
deployProject,
|
|
149
|
+
detectRuntime,
|
|
150
|
+
listFiles,
|
|
151
|
+
loadProjectConfig,
|
|
152
|
+
packFiles,
|
|
153
|
+
saveProjectConfig
|
|
154
|
+
} from "@roxyon/deploy-core";
|
|
155
|
+
import { z as z2 } from "zod";
|
|
156
|
+
|
|
157
|
+
// src/context.ts
|
|
158
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
159
|
+
var storage = new AsyncLocalStorage();
|
|
160
|
+
function runWithContext(ctx, fn) {
|
|
161
|
+
return storage.run(ctx, fn);
|
|
162
|
+
}
|
|
163
|
+
function currentContext() {
|
|
164
|
+
return storage.getStore() ?? {};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// src/session.ts
|
|
168
|
+
import { Roxyon, isAuthError } from "@roxyon/api-client";
|
|
169
|
+
import { endpointsFromEnv, loadCredentials, tokenFromEnv } from "@roxyon/deploy-core";
|
|
170
|
+
var NotAuthenticatedError = class extends Error {
|
|
171
|
+
constructor() {
|
|
172
|
+
super(
|
|
173
|
+
"Not signed in to Roxyon. Run `roxyon login` in a terminal, or set ROXYON_TOKEN in this MCP server's environment."
|
|
174
|
+
);
|
|
175
|
+
this.name = "NotAuthenticatedError";
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
async function getSession() {
|
|
179
|
+
const { apiUrl, consoleUrl } = endpointsFromEnv();
|
|
180
|
+
const requestToken = currentContext().token;
|
|
181
|
+
if (requestToken) {
|
|
182
|
+
return {
|
|
183
|
+
roxyon: new Roxyon({ sessionToken: requestToken, baseUrl: apiUrl, consoleUrl }),
|
|
184
|
+
source: "oauth"
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
const envToken = tokenFromEnv();
|
|
188
|
+
if (envToken) {
|
|
189
|
+
return {
|
|
190
|
+
roxyon: new Roxyon({ sessionToken: envToken, baseUrl: apiUrl, consoleUrl }),
|
|
191
|
+
source: "env-token"
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
const creds = await loadCredentials();
|
|
195
|
+
if (!creds?.sessionToken) throw new NotAuthenticatedError();
|
|
196
|
+
return {
|
|
197
|
+
roxyon: new Roxyon({ sessionToken: creds.sessionToken, baseUrl: apiUrl, consoleUrl }),
|
|
198
|
+
preferredSubscription: creds.subscription,
|
|
199
|
+
source: "stored-login"
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
function isSessionGone(err) {
|
|
203
|
+
return err instanceof NotAuthenticatedError || isAuthError(err);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// src/result.ts
|
|
207
|
+
function text(body, structured) {
|
|
208
|
+
return {
|
|
209
|
+
content: [{ type: "text", text: body }],
|
|
210
|
+
...structured ? { structuredContent: structured } : {}
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
function errorResult(message, structured) {
|
|
214
|
+
return {
|
|
215
|
+
content: [{ type: "text", text: message }],
|
|
216
|
+
...structured ? { structuredContent: structured } : {},
|
|
217
|
+
isError: true
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
async function guard(fn) {
|
|
221
|
+
try {
|
|
222
|
+
return await fn();
|
|
223
|
+
} catch (err) {
|
|
224
|
+
if (isSessionGone(err)) {
|
|
225
|
+
return errorResult(
|
|
226
|
+
err.message || "Roxyon session expired \u2014 run `roxyon login` again, or refresh ROXYON_TOKEN."
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
return errorResult(err instanceof Error ? err.message : String(err));
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// src/tools.ts
|
|
234
|
+
var MAX_FILES = 60;
|
|
235
|
+
var MAX_FILE_BYTES = 1024 * 1024;
|
|
236
|
+
var MAX_TOTAL_BYTES = 2 * 1024 * 1024;
|
|
237
|
+
function remoteFilesystemBlock(tool) {
|
|
238
|
+
if (!currentContext().remote) return null;
|
|
239
|
+
return errorResult(
|
|
240
|
+
[
|
|
241
|
+
`${tool} needs access to your local project files, which the hosted Roxyon MCP`,
|
|
242
|
+
"server does not have. Either:",
|
|
243
|
+
" \u2022 run the `roxyon` CLI locally (`npm i -g @roxyon/cli`, then `roxyon deploy`), or",
|
|
244
|
+
" \u2022 use `roxyon_link_github` to connect a git repo for push-to-deploy, then",
|
|
245
|
+
" `roxyon_app_status` / `roxyon_logs` to watch it here."
|
|
246
|
+
].join("\n")
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
async function resolveApp(args) {
|
|
250
|
+
if (args.application) return { applicationId: args.application };
|
|
251
|
+
if (args.dir) {
|
|
252
|
+
const cfg = await loadProjectConfig(args.dir);
|
|
253
|
+
if (cfg?.application) return { applicationId: cfg.application, host: cfg.host };
|
|
254
|
+
throw new Error(
|
|
255
|
+
`No application linked in ${args.dir}/roxyon.json. Deploy it once (roxyon_deploy) or pass "application".`
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
throw new Error('Pass either "application" (an id) or "dir" (a project directory).');
|
|
259
|
+
}
|
|
260
|
+
function accountContext(session) {
|
|
261
|
+
return session.roxyon.account.context();
|
|
262
|
+
}
|
|
263
|
+
function registerTools(server) {
|
|
264
|
+
server.registerTool(
|
|
265
|
+
"roxyon_whoami",
|
|
266
|
+
{
|
|
267
|
+
title: "Roxyon: who am I",
|
|
268
|
+
description: "Show the signed-in Roxyon user and their subscriptions (which one is active).",
|
|
269
|
+
inputSchema: {}
|
|
270
|
+
},
|
|
271
|
+
() => guard(async () => {
|
|
272
|
+
const session = await getSession();
|
|
273
|
+
const ctx = await accountContext(session);
|
|
274
|
+
const lines = [
|
|
275
|
+
`User: ${ctx.user.email || ctx.user.id} (${ctx.user.id})`,
|
|
276
|
+
`Auth: ${session.source}${ctx.scopes.length ? ` (scopes: ${ctx.scopes.join(", ")})` : ""}`,
|
|
277
|
+
"",
|
|
278
|
+
"Subscriptions:",
|
|
279
|
+
...ctx.subscriptions.map((s) => ` ${s.name || s.id} \u2014 ${s.status || "?"}`),
|
|
280
|
+
"",
|
|
281
|
+
`Hosts: ${ctx.domains.map((d) => d.name).join(", ") || "(none)"}`
|
|
282
|
+
];
|
|
283
|
+
return text(lines.join("\n"), {
|
|
284
|
+
user: ctx.user,
|
|
285
|
+
scopes: ctx.scopes,
|
|
286
|
+
subscriptions: ctx.subscriptions,
|
|
287
|
+
hosts: ctx.domains.map((d) => d.name)
|
|
288
|
+
});
|
|
289
|
+
})
|
|
290
|
+
);
|
|
291
|
+
server.registerTool(
|
|
292
|
+
"roxyon_list_domains",
|
|
293
|
+
{
|
|
294
|
+
title: "Roxyon: list hosts",
|
|
295
|
+
description: "List the domains (hosts) on the active subscription \u2014 the possible deploy targets.",
|
|
296
|
+
inputSchema: {}
|
|
297
|
+
},
|
|
298
|
+
() => guard(async () => {
|
|
299
|
+
const session = await getSession();
|
|
300
|
+
const { domains } = await accountContext(session);
|
|
301
|
+
return text(
|
|
302
|
+
domains.length ? domains.map(
|
|
303
|
+
(d) => `- ${d.name}${d.status && d.status !== "active" ? ` (${d.status})` : ""}`
|
|
304
|
+
).join("\n") : "(no hosts on this account)",
|
|
305
|
+
{ hosts: domains }
|
|
306
|
+
);
|
|
307
|
+
})
|
|
308
|
+
);
|
|
309
|
+
server.registerTool(
|
|
310
|
+
"roxyon_list_apps",
|
|
311
|
+
{
|
|
312
|
+
title: "Roxyon: list applications",
|
|
313
|
+
description: "List the applications on the active subscription with their status and revision.",
|
|
314
|
+
inputSchema: {}
|
|
315
|
+
},
|
|
316
|
+
() => guard(async () => {
|
|
317
|
+
const session = await getSession();
|
|
318
|
+
const apps = await session.roxyon.account.apps();
|
|
319
|
+
const body = apps.length ? apps.map(
|
|
320
|
+
(a) => `- ${a.name} [${a.id}] \u2014 ${a.status || "?"} (rev ${a.appliedRevision}/${a.configRevision})${a.repo ? ` \xB7 git:${a.repo.branch}` : ""}`
|
|
321
|
+
).join("\n") : "(no applications)";
|
|
322
|
+
return text(body, { applications: apps });
|
|
323
|
+
})
|
|
324
|
+
);
|
|
325
|
+
server.registerTool(
|
|
326
|
+
"roxyon_init",
|
|
327
|
+
{
|
|
328
|
+
title: "Roxyon: initialise a project",
|
|
329
|
+
description: "Detect a project's type and write roxyon.json. Run this once per project before roxyon_deploy. Does not create anything on the platform.",
|
|
330
|
+
inputSchema: {
|
|
331
|
+
dir: z2.string().describe("Absolute path to the project directory."),
|
|
332
|
+
runtime: z2.enum(["lumen", "node", "python", "php"]).optional(),
|
|
333
|
+
host: z2.string().optional().describe("Deploy host (a domain on the subscription)."),
|
|
334
|
+
folder: z2.string().optional().describe('Sub-path under the host; "" = site root.'),
|
|
335
|
+
overwrite: z2.boolean().optional().describe("Replace an existing roxyon.json.")
|
|
336
|
+
}
|
|
337
|
+
},
|
|
338
|
+
(args) => guard(async () => {
|
|
339
|
+
const blocked = remoteFilesystemBlock("roxyon_init");
|
|
340
|
+
if (blocked) return blocked;
|
|
341
|
+
const session = await getSession();
|
|
342
|
+
const existing = await loadProjectConfig(args.dir);
|
|
343
|
+
if (existing && !args.overwrite) {
|
|
344
|
+
return errorResult(
|
|
345
|
+
`roxyon.json already exists in ${args.dir}. Pass overwrite:true to replace it.`,
|
|
346
|
+
{ config: existing }
|
|
347
|
+
);
|
|
348
|
+
}
|
|
349
|
+
const { domains } = await accountContext(session);
|
|
350
|
+
if (domains.length === 0) {
|
|
351
|
+
return errorResult(
|
|
352
|
+
"This account has no hosts. Add a domain in the Roxyon console first."
|
|
353
|
+
);
|
|
354
|
+
}
|
|
355
|
+
const detected = await detectRuntime(args.dir);
|
|
356
|
+
const runtime = args.runtime ?? detected.runtime;
|
|
357
|
+
const host = args.host ?? domains[0].name;
|
|
358
|
+
if (!domains.some((d) => d.name === host)) {
|
|
359
|
+
return errorResult(
|
|
360
|
+
`Host "${host}" is not on this account (have: ${domains.map((d) => d.name).join(", ")}).`
|
|
361
|
+
);
|
|
362
|
+
}
|
|
363
|
+
const config = buildProjectConfig({
|
|
364
|
+
cwd: args.dir,
|
|
365
|
+
runtime,
|
|
366
|
+
host,
|
|
367
|
+
folder: args.folder,
|
|
368
|
+
start: detected.start
|
|
369
|
+
});
|
|
370
|
+
const path = await saveProjectConfig(config, args.dir);
|
|
371
|
+
return text(
|
|
372
|
+
`Wrote ${path}
|
|
373
|
+
Detected: ${detected.runtime} (${detected.reason})
|
|
374
|
+
|
|
375
|
+
${JSON.stringify(config, null, 2)}`,
|
|
376
|
+
{ path, detected: detected.runtime, config }
|
|
377
|
+
);
|
|
378
|
+
})
|
|
379
|
+
);
|
|
380
|
+
server.registerTool(
|
|
381
|
+
"roxyon_deploy",
|
|
382
|
+
{
|
|
383
|
+
title: "Roxyon: deploy a project",
|
|
384
|
+
description: 'Build (if configured) and deploy the project in "dir" to Roxyon. Without confirm:true this returns a dry-run plan (what would build, where it would go, how many files). With confirm:true it runs the build, uploads, and \u2014 for app runtimes \u2014 waits for it to go live. Requires roxyon.json (run roxyon_init first).',
|
|
385
|
+
inputSchema: {
|
|
386
|
+
dir: z2.string().describe("Absolute path to the project directory (must contain roxyon.json)."),
|
|
387
|
+
confirm: z2.boolean().optional().describe("Actually deploy. Omit for a dry-run plan."),
|
|
388
|
+
build: z2.boolean().optional().describe("Run the configured build command (default true)."),
|
|
389
|
+
follow: z2.boolean().optional().describe("For app runtimes, wait until running/failed (default true).")
|
|
390
|
+
}
|
|
391
|
+
},
|
|
392
|
+
(args) => guard(async () => {
|
|
393
|
+
const blocked = remoteFilesystemBlock("roxyon_deploy");
|
|
394
|
+
if (blocked) return blocked;
|
|
395
|
+
const session = await getSession();
|
|
396
|
+
const config = await loadProjectConfig(args.dir);
|
|
397
|
+
if (!config) {
|
|
398
|
+
return errorResult(`No roxyon.json in ${args.dir}. Run roxyon_init first.`);
|
|
399
|
+
}
|
|
400
|
+
if (!args.confirm) {
|
|
401
|
+
const ig = await buildIgnore(args.dir);
|
|
402
|
+
const packRoot = config.kind === "static" && config.outDir ? `${args.dir}/${config.outDir}` : args.dir;
|
|
403
|
+
let files = [];
|
|
404
|
+
try {
|
|
405
|
+
files = await listFiles(packRoot, ig);
|
|
406
|
+
} catch {
|
|
407
|
+
}
|
|
408
|
+
const plan = [
|
|
409
|
+
"DRY RUN \u2014 pass confirm:true to deploy.",
|
|
410
|
+
"",
|
|
411
|
+
`Project: ${config.name} (${config.runtime}, ${config.kind})`,
|
|
412
|
+
`Target: ${config.host}${config.folder ? `/${config.folder}` : ""}`,
|
|
413
|
+
config.build ? `Build: ${config.build}` : "Build: (none)",
|
|
414
|
+
config.kind === "app" ? `App: ${config.application ?? "(created on first deploy)"}` : "Serve: static files from the host document root",
|
|
415
|
+
files.length ? `Would pack ${files.length} file(s) from ${config.kind === "static" && config.outDir ? config.outDir : "."}` : `Would pack the build output (${config.outDir ?? "dist"}) after building`
|
|
416
|
+
].join("\n");
|
|
417
|
+
return text(plan, { dryRun: true, config });
|
|
418
|
+
}
|
|
419
|
+
const logLines = [];
|
|
420
|
+
const outcome = await deployProject({
|
|
421
|
+
cwd: args.dir,
|
|
422
|
+
roxyon: session.roxyon,
|
|
423
|
+
preferredSubscription: session.preferredSubscription,
|
|
424
|
+
build: args.build,
|
|
425
|
+
follow: args.follow ?? true,
|
|
426
|
+
timeoutMs: 5 * 60 * 1e3,
|
|
427
|
+
reporter: {
|
|
428
|
+
step: (m) => logLines.push(`\xBB ${m}`),
|
|
429
|
+
log: (l) => logLines.push(` ${l}`)
|
|
430
|
+
}
|
|
431
|
+
});
|
|
432
|
+
const tail = logLines.slice(-60).join("\n");
|
|
433
|
+
if (outcome.kind === "static" && outcome.ok) {
|
|
434
|
+
return text(`${tail}
|
|
435
|
+
|
|
436
|
+
\u2713 Live: ${outcome.url} (${outcome.files} files)`, {
|
|
437
|
+
ok: true,
|
|
438
|
+
kind: "static",
|
|
439
|
+
url: outcome.url
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
if (outcome.kind === "app" && outcome.ok) {
|
|
443
|
+
return text(
|
|
444
|
+
`${tail}
|
|
445
|
+
|
|
446
|
+
\u2713 ${outcome.status === "running" ? `Live: ${outcome.url ?? outcome.application}` : `Build queued (revision ${outcome.revision})`}`,
|
|
447
|
+
{
|
|
448
|
+
ok: true,
|
|
449
|
+
kind: "app",
|
|
450
|
+
application: outcome.application,
|
|
451
|
+
status: outcome.status,
|
|
452
|
+
url: outcome.url
|
|
453
|
+
}
|
|
454
|
+
);
|
|
455
|
+
}
|
|
456
|
+
return errorResult(
|
|
457
|
+
`${tail}
|
|
458
|
+
|
|
459
|
+
\u2717 Deploy failed: ${"error" in outcome ? outcome.error : "unknown"}`,
|
|
460
|
+
{ ok: false, application: "application" in outcome ? outcome.application : void 0 }
|
|
461
|
+
);
|
|
462
|
+
})
|
|
463
|
+
);
|
|
464
|
+
server.registerTool(
|
|
465
|
+
"roxyon_app_status",
|
|
466
|
+
{
|
|
467
|
+
title: "Roxyon: application status",
|
|
468
|
+
description: "Current status, revisions and last error for an application (by id or project dir).",
|
|
469
|
+
inputSchema: {
|
|
470
|
+
application: z2.string().optional(),
|
|
471
|
+
dir: z2.string().optional().describe("A project directory whose roxyon.json links an application.")
|
|
472
|
+
}
|
|
473
|
+
},
|
|
474
|
+
(args) => guard(async () => {
|
|
475
|
+
const session = await getSession();
|
|
476
|
+
const { applicationId } = await resolveApp(args);
|
|
477
|
+
const app = await session.roxyon.account.getApp(applicationId);
|
|
478
|
+
if (!app) return errorResult(`Application ${applicationId} not found.`);
|
|
479
|
+
const settled = app.configRevision <= app.appliedRevision;
|
|
480
|
+
const body = [
|
|
481
|
+
`${app.name} [${app.id}]`,
|
|
482
|
+
`Status: ${app.status || "?"}${settled ? "" : " (applying)"}`,
|
|
483
|
+
`Revision: ${app.appliedRevision} / ${app.configRevision}`,
|
|
484
|
+
`Runtime: ${app.runtime}`.trim(),
|
|
485
|
+
app.lastError ? `
|
|
486
|
+
Last error:
|
|
487
|
+
${app.lastError}` : ""
|
|
488
|
+
].filter(Boolean).join("\n");
|
|
489
|
+
return text(body, {
|
|
490
|
+
id: app.id,
|
|
491
|
+
status: app.status,
|
|
492
|
+
settled,
|
|
493
|
+
configRevision: app.configRevision,
|
|
494
|
+
appliedRevision: app.appliedRevision,
|
|
495
|
+
lastError: app.lastError || void 0
|
|
496
|
+
});
|
|
497
|
+
})
|
|
498
|
+
);
|
|
499
|
+
server.registerTool(
|
|
500
|
+
"roxyon_logs",
|
|
501
|
+
{
|
|
502
|
+
title: "Roxyon: application logs",
|
|
503
|
+
description: "Recent journal lines for an application (by id or project dir).",
|
|
504
|
+
inputSchema: {
|
|
505
|
+
application: z2.string().optional(),
|
|
506
|
+
dir: z2.string().optional(),
|
|
507
|
+
lines: z2.number().int().min(1).max(1e3).optional().describe("How many lines (default 100).")
|
|
508
|
+
}
|
|
509
|
+
},
|
|
510
|
+
(args) => guard(async () => {
|
|
511
|
+
const session = await getSession();
|
|
512
|
+
const { applicationId } = await resolveApp(args);
|
|
513
|
+
const lines = await session.roxyon.applications.logs(applicationId, args.lines ?? 100);
|
|
514
|
+
return text(lines.join("\n") || "(no log lines)", { lines });
|
|
515
|
+
})
|
|
516
|
+
);
|
|
517
|
+
server.registerTool(
|
|
518
|
+
"roxyon_restart",
|
|
519
|
+
{
|
|
520
|
+
title: "Roxyon: restart an application",
|
|
521
|
+
description: "Bounce the application process (no rebuild). Needs confirm:true.",
|
|
522
|
+
inputSchema: {
|
|
523
|
+
application: z2.string().optional(),
|
|
524
|
+
dir: z2.string().optional(),
|
|
525
|
+
confirm: z2.boolean().optional()
|
|
526
|
+
}
|
|
527
|
+
},
|
|
528
|
+
(args) => guard(async () => {
|
|
529
|
+
const session = await getSession();
|
|
530
|
+
const { applicationId } = await resolveApp(args);
|
|
531
|
+
if (!args.confirm)
|
|
532
|
+
return text(`Would restart ${applicationId}. Pass confirm:true.`, { dryRun: true });
|
|
533
|
+
await session.roxyon.applications.restart(applicationId);
|
|
534
|
+
return text(`Restart queued for ${applicationId}.`, { ok: true });
|
|
535
|
+
})
|
|
536
|
+
);
|
|
537
|
+
server.registerTool(
|
|
538
|
+
"roxyon_env_get",
|
|
539
|
+
{
|
|
540
|
+
title: "Roxyon: read environment variables",
|
|
541
|
+
description: "An application's environment variables as KEY=value lines.",
|
|
542
|
+
inputSchema: { application: z2.string().optional(), dir: z2.string().optional() }
|
|
543
|
+
},
|
|
544
|
+
(args) => guard(async () => {
|
|
545
|
+
const session = await getSession();
|
|
546
|
+
const { applicationId } = await resolveApp(args);
|
|
547
|
+
const env = await session.roxyon.applications.getEnv(applicationId);
|
|
548
|
+
return text(formatEnv(env) || "(none set)", { env });
|
|
549
|
+
})
|
|
550
|
+
);
|
|
551
|
+
server.registerTool(
|
|
552
|
+
"roxyon_env_set",
|
|
553
|
+
{
|
|
554
|
+
title: "Roxyon: set environment variables",
|
|
555
|
+
description: "Merge variables into an application's environment and bump its revision. Run roxyon_deploy afterwards to apply. Needs confirm:true. PORT and HOST are platform-managed and ignored.",
|
|
556
|
+
inputSchema: {
|
|
557
|
+
application: z2.string().optional(),
|
|
558
|
+
dir: z2.string().optional(),
|
|
559
|
+
vars: z2.record(z2.string()).describe('{ KEY: "value", ... } to set.'),
|
|
560
|
+
remove: z2.array(z2.string()).optional().describe("Keys to delete."),
|
|
561
|
+
confirm: z2.boolean().optional()
|
|
562
|
+
}
|
|
563
|
+
},
|
|
564
|
+
(args) => guard(async () => {
|
|
565
|
+
const session = await getSession();
|
|
566
|
+
const { applicationId } = await resolveApp(args);
|
|
567
|
+
const set = {};
|
|
568
|
+
for (const [k, v] of Object.entries(args.vars)) {
|
|
569
|
+
if (k === "PORT" || k === "HOST") continue;
|
|
570
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(k)) return errorResult(`Invalid env key "${k}".`);
|
|
571
|
+
set[k] = v;
|
|
572
|
+
}
|
|
573
|
+
const planned = [...Object.keys(set), ...(args.remove ?? []).map((k) => `-${k}`)];
|
|
574
|
+
if (!args.confirm) {
|
|
575
|
+
return text(`Would update: ${planned.join(", ") || "(nothing)"}. Pass confirm:true.`, {
|
|
576
|
+
dryRun: true,
|
|
577
|
+
changed: planned
|
|
578
|
+
});
|
|
579
|
+
}
|
|
580
|
+
const r = await session.roxyon.applications.setEnv(applicationId, {
|
|
581
|
+
set,
|
|
582
|
+
remove: args.remove ?? []
|
|
583
|
+
});
|
|
584
|
+
return text(`Updated ${r.changed.join(", ") || "(nothing)"}. Run roxyon_deploy to apply.`, {
|
|
585
|
+
ok: true,
|
|
586
|
+
changed: r.changed
|
|
587
|
+
});
|
|
588
|
+
})
|
|
589
|
+
);
|
|
590
|
+
server.registerTool(
|
|
591
|
+
"roxyon_link_github",
|
|
592
|
+
{
|
|
593
|
+
title: "Roxyon: connect a git remote",
|
|
594
|
+
description: "Connect a git repository to an application for push-to-deploy. Returns the deploy key and webhook URL to add to the repo. Needs confirm:true.",
|
|
595
|
+
inputSchema: {
|
|
596
|
+
application: z2.string().optional(),
|
|
597
|
+
dir: z2.string().optional(),
|
|
598
|
+
repoUrl: z2.string().describe("SSH git URL, e.g. git@github.com:you/app.git"),
|
|
599
|
+
branch: z2.string().optional().describe("Branch to deploy (default main)."),
|
|
600
|
+
confirm: z2.boolean().optional()
|
|
601
|
+
}
|
|
602
|
+
},
|
|
603
|
+
(args) => guard(async () => {
|
|
604
|
+
const session = await getSession();
|
|
605
|
+
const { applicationId } = await resolveApp(args);
|
|
606
|
+
if (!args.confirm) {
|
|
607
|
+
return text(
|
|
608
|
+
`Would connect ${args.repoUrl} (${args.branch ?? "main"}) to ${applicationId}. Pass confirm:true.`,
|
|
609
|
+
{ dryRun: true }
|
|
610
|
+
);
|
|
611
|
+
}
|
|
612
|
+
const res = await session.roxyon.applications.repoConnect(
|
|
613
|
+
applicationId,
|
|
614
|
+
args.repoUrl,
|
|
615
|
+
args.branch ?? "main"
|
|
616
|
+
);
|
|
617
|
+
const body = [
|
|
618
|
+
`Connected ${args.repoUrl} (${args.branch ?? "main"}).`,
|
|
619
|
+
res.deployKey ? `
|
|
620
|
+
Deploy key (add to the repo, read-only):
|
|
621
|
+
${res.deployKey}` : "",
|
|
622
|
+
res.webhookUrl ? `
|
|
623
|
+
Webhook URL: ${res.webhookUrl}` : "",
|
|
624
|
+
res.secret ? `Webhook secret: ${res.secret}` : "",
|
|
625
|
+
res.hint ? `
|
|
626
|
+
${res.hint}` : ""
|
|
627
|
+
].filter(Boolean).join("\n");
|
|
628
|
+
return text(body, {
|
|
629
|
+
ok: true,
|
|
630
|
+
deployKey: res.deployKey,
|
|
631
|
+
webhookUrl: res.webhookUrl,
|
|
632
|
+
secret: res.secret
|
|
633
|
+
});
|
|
634
|
+
})
|
|
635
|
+
);
|
|
636
|
+
server.registerTool(
|
|
637
|
+
"roxyon_add_domain",
|
|
638
|
+
{
|
|
639
|
+
title: "Roxyon: add a subdomain / host",
|
|
640
|
+
description: "Provision a host \u2014 DNS + web server + automatic HTTPS. The host must be a subdomain of a domain the account already hosts (or a *.roxyon.com subdomain). Returns while it is still coming up; TLS follows a minute or two later. Needs confirm:true.",
|
|
641
|
+
inputSchema: {
|
|
642
|
+
host: z2.string().describe("The full hostname, e.g. promo.mycompany.com"),
|
|
643
|
+
subscription: z2.string().optional().describe("Which subscription to attach it to (omit if the account has one)."),
|
|
644
|
+
spa: z2.boolean().optional().describe("Single-page app: unmatched paths serve /index.html."),
|
|
645
|
+
confirm: z2.boolean().optional()
|
|
646
|
+
}
|
|
647
|
+
},
|
|
648
|
+
(args) => guard(async () => {
|
|
649
|
+
const session = await getSession();
|
|
650
|
+
if (!args.confirm) {
|
|
651
|
+
return text(
|
|
652
|
+
`Would provision ${args.host}${args.spa ? " (SPA routing)" : ""}. Pass confirm:true.`,
|
|
653
|
+
{ dryRun: true }
|
|
654
|
+
);
|
|
655
|
+
}
|
|
656
|
+
const res = await session.roxyon.domains.create({
|
|
657
|
+
host: args.host,
|
|
658
|
+
subscription: args.subscription ?? session.preferredSubscription,
|
|
659
|
+
siteType: args.spa ? "spa" : void 0
|
|
660
|
+
});
|
|
661
|
+
const live = res.status === "active";
|
|
662
|
+
return text(
|
|
663
|
+
[
|
|
664
|
+
`${res.host} \u2014 ${res.type}, ${res.status}.`,
|
|
665
|
+
live ? "The host is up. HTTPS may take another minute to issue." : "DNS + web server are being set up (~1\u20132 min), then HTTPS. Check roxyon_list_domains, or just deploy now \u2014 files are kept and served once it is live."
|
|
666
|
+
].join("\n"),
|
|
667
|
+
{ ok: true, host: res.host, type: res.type, status: res.status }
|
|
668
|
+
);
|
|
669
|
+
})
|
|
670
|
+
);
|
|
671
|
+
server.registerTool(
|
|
672
|
+
"roxyon_deploy_content",
|
|
673
|
+
{
|
|
674
|
+
title: "Roxyon: deploy generated files",
|
|
675
|
+
description: [
|
|
676
|
+
"Publish a set of files you generated (HTML/CSS/JS/assets) to a host on the account.",
|
|
677
|
+
"The host must already exist (roxyon_add_domain, or an existing site). Overlay by",
|
|
678
|
+
"default \u2014 pass clean:true to replace the whole document root. Needs confirm:true.",
|
|
679
|
+
`Limits: ${MAX_FILES} files, ${MAX_FILE_BYTES / 1024 | 0} KB per file,`,
|
|
680
|
+
`${(MAX_TOTAL_BYTES / 1024 / 1024).toFixed(1)} MB total (base64-encode binaries).`
|
|
681
|
+
].join(" "),
|
|
682
|
+
inputSchema: {
|
|
683
|
+
host: z2.string().describe("Target host, e.g. promo.mycompany.com"),
|
|
684
|
+
folder: z2.string().optional().describe('Sub-path under the host; "" = site root.'),
|
|
685
|
+
files: z2.array(
|
|
686
|
+
z2.object({
|
|
687
|
+
path: z2.string().describe("Relative path, e.g. index.html, about/index.html"),
|
|
688
|
+
content: z2.string(),
|
|
689
|
+
encoding: z2.enum(["utf8", "base64"]).optional()
|
|
690
|
+
})
|
|
691
|
+
).min(1),
|
|
692
|
+
clean: z2.boolean().optional().describe("Replace the whole docroot (keeps .well-known)."),
|
|
693
|
+
spa: z2.boolean().optional().describe("Also flip the host to SPA routing."),
|
|
694
|
+
confirm: z2.boolean().optional()
|
|
695
|
+
}
|
|
696
|
+
},
|
|
697
|
+
(args) => guard(async () => {
|
|
698
|
+
const session = await getSession();
|
|
699
|
+
if (args.files.length > MAX_FILES) {
|
|
700
|
+
return errorResult(`Too many files (${args.files.length}); the limit is ${MAX_FILES}.`);
|
|
701
|
+
}
|
|
702
|
+
let total = 0;
|
|
703
|
+
for (const f of args.files) {
|
|
704
|
+
const n = Buffer.byteLength(f.content, f.encoding === "base64" ? "base64" : "utf8");
|
|
705
|
+
if (n > MAX_FILE_BYTES) {
|
|
706
|
+
return errorResult(
|
|
707
|
+
`"${f.path}" is ${n / 1024 | 0} KB; the per-file limit is ${MAX_FILE_BYTES / 1024 | 0} KB.`
|
|
708
|
+
);
|
|
709
|
+
}
|
|
710
|
+
total += n;
|
|
711
|
+
}
|
|
712
|
+
if (total > MAX_TOTAL_BYTES) {
|
|
713
|
+
return errorResult(
|
|
714
|
+
`Total content is ${(total / 1024 / 1024).toFixed(1)} MB; the limit is ${(MAX_TOTAL_BYTES / 1024 / 1024).toFixed(1)} MB. Deploy in parts or use the CLI.`
|
|
715
|
+
);
|
|
716
|
+
}
|
|
717
|
+
const folder = args.folder ?? "";
|
|
718
|
+
if (!args.confirm) {
|
|
719
|
+
return text(
|
|
720
|
+
[
|
|
721
|
+
"DRY RUN \u2014 pass confirm:true to deploy.",
|
|
722
|
+
"",
|
|
723
|
+
`Host: ${args.host}${folder ? `/${folder}` : ""}`,
|
|
724
|
+
`Files: ${args.files.length} (${total / 1024 | 0} KB)`,
|
|
725
|
+
`Mode: ${args.clean ? "clean (replaces the document root)" : "overlay"}${args.spa ? " + SPA routing" : ""}`,
|
|
726
|
+
...args.files.slice(0, 20).map((f) => ` ${f.path}`),
|
|
727
|
+
args.files.length > 20 ? ` \u2026 ${args.files.length - 20} more` : ""
|
|
728
|
+
].filter(Boolean).join("\n"),
|
|
729
|
+
{ dryRun: true }
|
|
730
|
+
);
|
|
731
|
+
}
|
|
732
|
+
const { buffer, files } = await packFiles(args.files, { maxBytes: MAX_TOTAL_BYTES });
|
|
733
|
+
const r = await session.roxyon.sites.deploy(args.host, folder, buffer, {
|
|
734
|
+
clean: args.clean,
|
|
735
|
+
spa: args.spa
|
|
736
|
+
});
|
|
737
|
+
const size = r.bytes ? ` (${r.bytes / 1024 | 0} KB)` : "";
|
|
738
|
+
const spaNote = args.spa ? "\nSPA routing enabled \u2014 deep links resolve to index.html." : "";
|
|
739
|
+
return text(
|
|
740
|
+
`\u2713 Deployed ${files.length} file(s) to https://${args.host}${folder ? `/${folder}` : ""}${size}.${spaNote}`,
|
|
741
|
+
{ ok: true, host: args.host, files: files.length }
|
|
742
|
+
);
|
|
743
|
+
})
|
|
744
|
+
);
|
|
745
|
+
server.registerTool(
|
|
746
|
+
"roxyon_list_files",
|
|
747
|
+
{
|
|
748
|
+
title: "Roxyon: list a site\u2019s files",
|
|
749
|
+
description: "The files currently deployed to a host's document root.",
|
|
750
|
+
inputSchema: {
|
|
751
|
+
host: z2.string(),
|
|
752
|
+
folder: z2.string().optional(),
|
|
753
|
+
path: z2.string().optional().describe("List under this sub-path only.")
|
|
754
|
+
}
|
|
755
|
+
},
|
|
756
|
+
(args) => guard(async () => {
|
|
757
|
+
const session = await getSession();
|
|
758
|
+
const files = await session.roxyon.sites.listFiles(
|
|
759
|
+
args.host,
|
|
760
|
+
args.folder ?? "",
|
|
761
|
+
args.path ?? ""
|
|
762
|
+
);
|
|
763
|
+
const body = files.length ? files.map(
|
|
764
|
+
(f) => `${f.type === "dir" ? "d" : "-"} ${String(f.size).padStart(8)} ${f.path}`
|
|
765
|
+
).join("\n") : "(empty)";
|
|
766
|
+
return text(body, { files });
|
|
767
|
+
})
|
|
768
|
+
);
|
|
769
|
+
server.registerTool(
|
|
770
|
+
"roxyon_read_file",
|
|
771
|
+
{
|
|
772
|
+
title: "Roxyon: read a site file",
|
|
773
|
+
description: "Read one file from a host's document root (to review or edit it).",
|
|
774
|
+
inputSchema: {
|
|
775
|
+
host: z2.string(),
|
|
776
|
+
folder: z2.string().optional(),
|
|
777
|
+
path: z2.string().describe("Relative path, e.g. index.html")
|
|
778
|
+
}
|
|
779
|
+
},
|
|
780
|
+
(args) => guard(async () => {
|
|
781
|
+
const session = await getSession();
|
|
782
|
+
const f = await session.roxyon.sites.readFile(args.host, args.folder ?? "", args.path);
|
|
783
|
+
if (f.encoding === "base64") {
|
|
784
|
+
return text(
|
|
785
|
+
`${f.path} \u2014 ${f.size} bytes, binary (base64):
|
|
786
|
+
|
|
787
|
+
${f.content.slice(0, 4096)}`,
|
|
788
|
+
{ path: f.path, size: f.size, encoding: "base64" }
|
|
789
|
+
);
|
|
790
|
+
}
|
|
791
|
+
return text(f.content, { path: f.path, size: f.size, encoding: "utf8" });
|
|
792
|
+
})
|
|
793
|
+
);
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
// src/server.ts
|
|
797
|
+
var SERVER_NAME = "roxyon";
|
|
798
|
+
var SERVER_VERSION = createRequire(import.meta.url)("../package.json").version;
|
|
799
|
+
function createServer() {
|
|
800
|
+
const server = new McpServer(
|
|
801
|
+
{ name: SERVER_NAME, version: SERVER_VERSION },
|
|
802
|
+
{
|
|
803
|
+
instructions: "Roxyon lets you build LumenJS SPAs, use the Roxyon BaaS, and deploy apps and web projects to Roxyon infrastructure. Read the roxyon://docs/* resources before writing LumenJS or calling the BaaS. To deploy: roxyon_init once per project, then roxyon_deploy (dry run, then confirm:true). Side-effecting tools require confirm:true."
|
|
804
|
+
}
|
|
805
|
+
);
|
|
806
|
+
registerResources(server);
|
|
807
|
+
registerPrompts(server);
|
|
808
|
+
registerTools(server);
|
|
809
|
+
return server;
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
export {
|
|
813
|
+
runWithContext,
|
|
814
|
+
SERVER_NAME,
|
|
815
|
+
SERVER_VERSION,
|
|
816
|
+
createServer
|
|
817
|
+
};
|
|
818
|
+
//# sourceMappingURL=chunk-U6ILIHUR.js.map
|