@velixir/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/README.md +30 -2
- package/package.json +2 -2
- package/src/index.js +167 -5
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.
|
|
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
|
|
|
@@ -42,15 +42,43 @@ Point the editor's MCP settings at the same command (`npx -y @velixir/mcp`).
|
|
|
42
42
|
| `language` | no | node, python, go, ruby, php, java, elixir, rust, dotnet, deno, fsharp. Auto-detected if omitted. |
|
|
43
43
|
| `port` | no | Only if the app hard-codes a port instead of reading the `PORT` env var. |
|
|
44
44
|
|
|
45
|
-
It returns the live URL, a claim URL (give this to the user), when the claim window closes, and a status URL to poll.
|
|
45
|
+
It returns the live URL, a claim URL (give this to the user), when the claim window closes, a **deployment ID** (pass it to `logs`), and a status URL to poll.
|
|
46
46
|
|
|
47
47
|
`node_modules`, `.git`, build output, and caches are skipped automatically. Nixpacks reinstalls dependencies and builds from source.
|
|
48
48
|
|
|
49
|
+
## The `logs` tool
|
|
50
|
+
|
|
51
|
+
Fetch recent build and runtime logs for an app you deployed, so you can debug without an account: a failed build returns the build error, a running app returns its recent container output.
|
|
52
|
+
|
|
53
|
+
| Input | Required | Description |
|
|
54
|
+
| --- | --- | --- |
|
|
55
|
+
| `deployment_id` | yes | The deployment ID from the `deploy` response. |
|
|
56
|
+
| `tail` | no | How many recent lines to fetch (default 200, max 1000). |
|
|
57
|
+
|
|
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
|
+
|
|
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
|
+
|
|
49
76
|
## Config
|
|
50
77
|
|
|
51
78
|
| Env var | Default | Description |
|
|
52
79
|
| --- | --- | --- |
|
|
53
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. |
|
|
54
82
|
|
|
55
83
|
## Requirements
|
|
56
84
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@velixir/mcp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Deploy web apps in any language to Velixir (the European cloud) straight from your AI agent
|
|
3
|
+
"version": "0.3.0",
|
|
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": {
|
|
7
7
|
"velixir-mcp": "src/index.js"
|
package/src/index.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// Velixir MCP server. Exposes
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
// on a free, card-free account.
|
|
2
|
+
// Velixir MCP server. Exposes three tools:
|
|
3
|
+
// - `deploy`: pack a source directory and POST it to Velixir's account-less deploy
|
|
4
|
+
// endpoint (POST /api/v1/deploy), returning a live URL + a single-use claim link
|
|
5
|
+
// the human opens to keep the app on a free, card-free account.
|
|
6
|
+
// - `logs`: fetch recent build + runtime logs for a deployment by its ID
|
|
7
|
+
// (GET /api/v1/deploy/{id}/logs), so the agent can debug what it just shipped.
|
|
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.
|
|
6
11
|
//
|
|
7
12
|
// Zero setup: run with `npx -y @velixir/mcp`. Point VELIXIR_API_URL at a different
|
|
8
13
|
// host for staging/self-host (default https://velixir.net).
|
|
@@ -43,7 +48,14 @@ async function tarballOf(dir) {
|
|
|
43
48
|
return Buffer.concat(chunks);
|
|
44
49
|
}
|
|
45
50
|
|
|
46
|
-
|
|
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" });
|
|
47
59
|
|
|
48
60
|
server.tool(
|
|
49
61
|
"deploy",
|
|
@@ -108,6 +120,9 @@ server.tool(
|
|
|
108
120
|
? `Claim URL: ${data.claim_url}\n(Give this to the user. Opening it keeps the app on a free, card-free Velixir account; unclaimed apps are removed after a short window.)`
|
|
109
121
|
: null,
|
|
110
122
|
data.claim_expires_at ? `Claim before: ${data.claim_expires_at}` : null,
|
|
123
|
+
data.deployment_id
|
|
124
|
+
? `Deployment ID: ${data.deployment_id}\n(Use the "logs" tool with this ID to see build/runtime logs and debug if the app doesn't come up.)`
|
|
125
|
+
: null,
|
|
111
126
|
data.status_url ? `Deployment status: ${data.status_url}` : null,
|
|
112
127
|
].filter(Boolean);
|
|
113
128
|
|
|
@@ -115,5 +130,152 @@ server.tool(
|
|
|
115
130
|
},
|
|
116
131
|
);
|
|
117
132
|
|
|
133
|
+
server.tool(
|
|
134
|
+
"logs",
|
|
135
|
+
"Fetch recent build and runtime logs for an app you deployed to Velixir, by its deployment ID (from the `deploy` tool's response). Use this to debug: if the build failed you get the build error; if it built but isn't responding you get the container's recent output. No Velixir account is needed.",
|
|
136
|
+
{
|
|
137
|
+
deployment_id: z
|
|
138
|
+
.string()
|
|
139
|
+
.describe("The deployment ID returned by the `deploy` tool."),
|
|
140
|
+
tail: z
|
|
141
|
+
.number()
|
|
142
|
+
.int()
|
|
143
|
+
.optional()
|
|
144
|
+
.describe("How many recent log lines to fetch (default 200, max 1000)."),
|
|
145
|
+
},
|
|
146
|
+
async ({ deployment_id, tail }) => {
|
|
147
|
+
const qs = tail != null ? `?tail=${encodeURIComponent(tail)}` : "";
|
|
148
|
+
const url = `${API_URL}/api/v1/deploy/${encodeURIComponent(deployment_id)}/logs${qs}`;
|
|
149
|
+
|
|
150
|
+
let res, body;
|
|
151
|
+
try {
|
|
152
|
+
res = await fetch(url);
|
|
153
|
+
body = await res.text();
|
|
154
|
+
} catch (err) {
|
|
155
|
+
return { isError: true, content: [{ type: "text", text: `Could not reach Velixir at ${API_URL}: ${err?.message ?? err}` }] };
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (res.status === 429) return rateLimited(res);
|
|
159
|
+
if (res.status === 404) {
|
|
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.` }] };
|
|
161
|
+
}
|
|
162
|
+
if (!res.ok) {
|
|
163
|
+
return { isError: true, content: [{ type: "text", text: `Could not fetch logs (HTTP ${res.status}): ${body}` }] };
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
let data;
|
|
167
|
+
try { data = JSON.parse(body); } catch { data = {}; }
|
|
168
|
+
|
|
169
|
+
const out = [];
|
|
170
|
+
if (data.status) out.push(`Status: ${data.status}`);
|
|
171
|
+
if (data.build_error) out.push(`Build error:\n${data.build_error}`);
|
|
172
|
+
|
|
173
|
+
const logLines = Array.isArray(data.lines) ? data.lines : [];
|
|
174
|
+
if (logLines.length) {
|
|
175
|
+
out.push("Recent logs:");
|
|
176
|
+
for (const l of logLines) out.push(l.line ?? "");
|
|
177
|
+
} else if (!data.build_error) {
|
|
178
|
+
out.push("No log lines yet (the app may still be starting, or has produced no output).");
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return { content: [{ type: "text", text: out.join("\n") }] };
|
|
182
|
+
},
|
|
183
|
+
);
|
|
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
|
+
|
|
118
280
|
const transport = new StdioServerTransport();
|
|
119
281
|
await server.connect(transport);
|