@velixir/mcp 0.2.0 → 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/README.md +18 -1
- package/package.json +1 -1
- package/src/index.js +108 -3
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @velixir/mcp
|
|
2
2
|
|
|
3
|
-
Deploy web apps in **any language** to [velixir](https://velixir.net), the European cloud, straight from your AI agent. `deploy` points at a source directory, packs the code, builds it with no Dockerfile, and returns a live URL plus a claim link the human opens to keep the app on a free, card-free account. `logs` fetches the build and runtime logs so the agent can debug what it shipped. No velixir account is needed.
|
|
3
|
+
Deploy web apps in **any language** to [velixir](https://velixir.net), the European cloud, straight from your AI agent. `deploy` points at a source directory, packs the code, builds it with no Dockerfile, and returns a live URL plus a claim link the human opens to keep the app on a free, card-free account. `logs` fetches the build and runtime logs, and `access_logs` the HTTP requests the app served, so the agent can debug what it shipped. No velixir account is needed.
|
|
4
4
|
|
|
5
5
|
## Why
|
|
6
6
|
|
|
@@ -57,11 +57,28 @@ Fetch recent build and runtime logs for an app you deployed, so you can debug wi
|
|
|
57
57
|
|
|
58
58
|
Works for unclaimed (agent-deployed) apps addressed by deployment ID. Once an app is claimed it moves to the owner's account; use the dashboard or the authenticated API for a claimed app's logs.
|
|
59
59
|
|
|
60
|
+
## The `access_logs` tool
|
|
61
|
+
|
|
62
|
+
The HTTP requests an app served, newest first, with a summary of status codes and the slowest request: use it to check the app is getting traffic and to find failing requests.
|
|
63
|
+
|
|
64
|
+
| Input | Required | Description |
|
|
65
|
+
| --- | --- | --- |
|
|
66
|
+
| `deployment_id` | one of these | From the `deploy` response. Works until the user claims the app. No account needed. |
|
|
67
|
+
| `app_id` | one of these | An app the user owns. Needs `VELIXIR_API_KEY`. |
|
|
68
|
+
| `status` | no | `2xx`, `3xx`, `4xx`, `5xx`, `errors`, or a code like `404`. |
|
|
69
|
+
| `path` | no | Only paths containing this text. |
|
|
70
|
+
| `method` | no | HTTP method, e.g. `POST`. |
|
|
71
|
+
| `since_minutes` | no | Only the last N minutes. |
|
|
72
|
+
| `limit` | no | How many requests (default 50, max 200). |
|
|
73
|
+
|
|
74
|
+
Once an app is claimed its access logs belong to the owner (they include visitors' IP addresses), so the deployment ID stops working for them; use `app_id` with an API key.
|
|
75
|
+
|
|
60
76
|
## Config
|
|
61
77
|
|
|
62
78
|
| Env var | Default | Description |
|
|
63
79
|
| --- | --- | --- |
|
|
64
80
|
| `VELIXIR_API_URL` | `https://velixir.net` | Override for staging or self-host. |
|
|
81
|
+
| `VELIXIR_API_KEY` | (none) | Optional. Lets `access_logs` read apps the user owns, by `app_id`. Create one at velixir.net under Settings, API keys. |
|
|
65
82
|
|
|
66
83
|
## Requirements
|
|
67
84
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@velixir/mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Deploy web apps in any language to Velixir (the European cloud) straight from your AI agent: point deploy at a directory for a live URL and claim link, then read logs to debug what you shipped.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
package/src/index.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// Velixir MCP server. Exposes
|
|
2
|
+
// Velixir MCP server. Exposes three tools:
|
|
3
3
|
// - `deploy`: pack a source directory and POST it to Velixir's account-less deploy
|
|
4
4
|
// endpoint (POST /api/v1/deploy), returning a live URL + a single-use claim link
|
|
5
5
|
// the human opens to keep the app on a free, card-free account.
|
|
6
6
|
// - `logs`: fetch recent build + runtime logs for a deployment by its ID
|
|
7
7
|
// (GET /api/v1/deploy/{id}/logs), so the agent can debug what it just shipped.
|
|
8
|
-
//
|
|
8
|
+
// - `access_logs`: the HTTP requests an app served (GET /api/v1/deploy/{id}/access-logs for an
|
|
9
|
+
// unclaimed deploy, or /api/v1/apps/{id}/access-logs with VELIXIR_API_KEY for an owned app).
|
|
10
|
+
// No Velixir account is needed for deploy, logs, or access_logs on an unclaimed deploy.
|
|
9
11
|
//
|
|
10
12
|
// Zero setup: run with `npx -y @velixir/mcp`. Point VELIXIR_API_URL at a different
|
|
11
13
|
// host for staging/self-host (default https://velixir.net).
|
|
@@ -46,7 +48,14 @@ async function tarballOf(dir) {
|
|
|
46
48
|
return Buffer.concat(chunks);
|
|
47
49
|
}
|
|
48
50
|
|
|
49
|
-
|
|
51
|
+
// Anonymous reads are rate limited per client (a burst, then one every two seconds). Tell the
|
|
52
|
+
// agent to wait instead of handing it a raw 429 it might retry in a tight loop.
|
|
53
|
+
function rateLimited(res) {
|
|
54
|
+
const wait = Number(res.headers.get("retry-after")) || 60;
|
|
55
|
+
return { isError: true, content: [{ type: "text", text: `Rate limited by Velixir. Wait about ${wait} seconds before calling this again, and avoid polling in a tight loop.` }] };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const server = new McpServer({ name: "velixir", version: "0.3.0" });
|
|
50
59
|
|
|
51
60
|
server.tool(
|
|
52
61
|
"deploy",
|
|
@@ -146,6 +155,7 @@ server.tool(
|
|
|
146
155
|
return { isError: true, content: [{ type: "text", text: `Could not reach Velixir at ${API_URL}: ${err?.message ?? err}` }] };
|
|
147
156
|
}
|
|
148
157
|
|
|
158
|
+
if (res.status === 429) return rateLimited(res);
|
|
149
159
|
if (res.status === 404) {
|
|
150
160
|
return { isError: true, content: [{ type: "text", text: `No logs for deployment ${deployment_id}. It may not exist, may already be claimed (use the dashboard for claimed apps), or its unclaimed window may have passed.` }] };
|
|
151
161
|
}
|
|
@@ -172,5 +182,100 @@ server.tool(
|
|
|
172
182
|
},
|
|
173
183
|
);
|
|
174
184
|
|
|
185
|
+
// Optional: an API key (velixir.net → Settings → API keys) lets `access_logs` read apps the user
|
|
186
|
+
// owns, by app ID. Without it the tool still works for unclaimed deploys, by deployment ID.
|
|
187
|
+
const API_KEY = process.env.VELIXIR_API_KEY || "";
|
|
188
|
+
|
|
189
|
+
function statusClass(s) {
|
|
190
|
+
return s >= 500 ? "5xx" : s >= 400 ? "4xx" : s >= 300 ? "3xx" : "2xx";
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
server.tool(
|
|
194
|
+
"access_logs",
|
|
195
|
+
"Read the HTTP access logs for an app on Velixir: one line per request it served (time, status, method, path, duration, size, visitor IP), newest first, with a summary of status codes. Use this to see whether the app is getting traffic and to debug failing requests (filter with status: \"5xx\" or \"errors\"). For an app you deployed with the `deploy` tool, pass its deployment_id (works until the user claims it). For an app the user owns, pass app_id; that needs a VELIXIR_API_KEY in the MCP server's environment.",
|
|
196
|
+
{
|
|
197
|
+
deployment_id: z
|
|
198
|
+
.string()
|
|
199
|
+
.optional()
|
|
200
|
+
.describe("The deployment ID returned by the `deploy` tool (unclaimed apps, no account needed)."),
|
|
201
|
+
app_id: z
|
|
202
|
+
.string()
|
|
203
|
+
.optional()
|
|
204
|
+
.describe("The app's ID, for an app the user owns. Requires VELIXIR_API_KEY."),
|
|
205
|
+
status: z
|
|
206
|
+
.string()
|
|
207
|
+
.optional()
|
|
208
|
+
.describe("Filter: 2xx, 3xx, 4xx, 5xx, errors (4xx and 5xx), or an exact code like 404."),
|
|
209
|
+
path: z.string().optional().describe("Filter: only paths containing this text (case-insensitive)."),
|
|
210
|
+
method: z.string().optional().describe("Filter: HTTP method, e.g. POST."),
|
|
211
|
+
since_minutes: z.number().int().positive().optional().describe("Only requests from the last N minutes."),
|
|
212
|
+
limit: z.number().int().optional().describe("How many requests to return (default 50, max 200)."),
|
|
213
|
+
},
|
|
214
|
+
async ({ deployment_id, app_id, status, path: pathFilter, method, since_minutes, limit }) => {
|
|
215
|
+
if (!deployment_id && !app_id) {
|
|
216
|
+
return { isError: true, content: [{ type: "text", text: "Pass deployment_id (from the deploy tool) or app_id (needs VELIXIR_API_KEY)." }] };
|
|
217
|
+
}
|
|
218
|
+
if (!deployment_id && !API_KEY) {
|
|
219
|
+
return { isError: true, content: [{ type: "text", text: "Reading an owned app by app_id needs VELIXIR_API_KEY set in this MCP server's environment (create one at https://velixir.net under Settings, API keys)." }] };
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const qs = new URLSearchParams({ limit: String(Math.min(Math.max(limit ?? 50, 1), 200)) });
|
|
223
|
+
if (status) qs.set("status", status);
|
|
224
|
+
if (pathFilter) qs.set("path", pathFilter);
|
|
225
|
+
if (method) qs.set("method", method);
|
|
226
|
+
if (since_minutes) qs.set("after", new Date(Date.now() - since_minutes * 60_000).toISOString());
|
|
227
|
+
|
|
228
|
+
const url = deployment_id
|
|
229
|
+
? `${API_URL}/api/v1/deploy/${encodeURIComponent(deployment_id)}/access-logs?${qs}`
|
|
230
|
+
: `${API_URL}/api/v1/apps/${encodeURIComponent(app_id)}/access-logs?${qs}`;
|
|
231
|
+
const headers = deployment_id || !API_KEY ? {} : { "X-Api-Key": API_KEY };
|
|
232
|
+
|
|
233
|
+
let res, body;
|
|
234
|
+
try {
|
|
235
|
+
res = await fetch(url, { headers });
|
|
236
|
+
body = await res.text();
|
|
237
|
+
} catch (err) {
|
|
238
|
+
return { isError: true, content: [{ type: "text", text: `Could not reach Velixir at ${API_URL}: ${err?.message ?? err}` }] };
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
if (res.status === 429) return rateLimited(res);
|
|
242
|
+
if (res.status === 404) {
|
|
243
|
+
const why = deployment_id
|
|
244
|
+
? `No unclaimed deployment ${deployment_id}. Once the user claims the app, read its access logs by app_id with a VELIXIR_API_KEY, or in the dashboard.`
|
|
245
|
+
: `App ${app_id} not found, or this API key can't read it.`;
|
|
246
|
+
return { isError: true, content: [{ type: "text", text: why }] };
|
|
247
|
+
}
|
|
248
|
+
if (res.status === 401 || res.status === 403) {
|
|
249
|
+
return { isError: true, content: [{ type: "text", text: "VELIXIR_API_KEY was rejected. Check the key in this MCP server's environment." }] };
|
|
250
|
+
}
|
|
251
|
+
if (!res.ok) {
|
|
252
|
+
let msg = body;
|
|
253
|
+
try { msg = JSON.parse(body).error ?? body; } catch { /* plain text */ }
|
|
254
|
+
return { isError: true, content: [{ type: "text", text: `Could not fetch access logs (HTTP ${res.status}): ${msg}` }] };
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
let data;
|
|
258
|
+
try { data = JSON.parse(body); } catch { data = {}; }
|
|
259
|
+
const entries = Array.isArray(data.entries) ? data.entries : [];
|
|
260
|
+
if (!entries.length) {
|
|
261
|
+
return { content: [{ type: "text", text: "No requests match yet. If the app was just deployed, open its URL once and try again: lines arrive within a few seconds." }] };
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const counts = {};
|
|
265
|
+
for (const e of entries) counts[statusClass(e.status)] = (counts[statusClass(e.status)] ?? 0) + 1;
|
|
266
|
+
const slowest = entries.reduce((a, b) => (b.requestTimeMs > a.requestTimeMs ? b : a));
|
|
267
|
+
const out = [
|
|
268
|
+
`${entries.length} request(s), newest first. Status: ${Object.entries(counts).map(([k, v]) => `${k} ${v}`).join(", ")}.`,
|
|
269
|
+
`Slowest: ${slowest.method} ${slowest.path} took ${slowest.requestTimeMs} ms (status ${slowest.status}).`,
|
|
270
|
+
"",
|
|
271
|
+
...entries.map(e =>
|
|
272
|
+
`${e.timestamp} ${e.status} ${e.method} ${e.path}${e.query ? "?" + e.query : ""} ${e.requestTimeMs}ms ${e.bytesSent}B ip=${e.clientIp}` +
|
|
273
|
+
(e.status >= 400 && e.userAgent ? ` ua="${e.userAgent}"` : "")),
|
|
274
|
+
];
|
|
275
|
+
if (data.nextBefore) out.push("", `More, older requests exist; narrow with since_minutes, status or path.`);
|
|
276
|
+
return { content: [{ type: "text", text: out.join("\n") }] };
|
|
277
|
+
},
|
|
278
|
+
);
|
|
279
|
+
|
|
175
280
|
const transport = new StdioServerTransport();
|
|
176
281
|
await server.connect(transport);
|