@edgegap/mcp 0.10.0 → 0.12.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 +78 -10
- package/dist/auth.js +16 -6
- package/dist/callreport.js +157 -0
- package/dist/client.js +9 -0
- package/dist/hosted.js +4 -1
- package/dist/http.js +1 -1
- package/dist/outputs.js +128 -0
- package/dist/skills.generated.js +64 -25
- package/dist/skills.js +12 -1
- package/dist/tools.js +668 -119
- package/dist/version.js +1 -1
- package/package.json +8 -7
package/README.md
CHANGED
|
@@ -78,10 +78,16 @@ claude mcp add --transport http edgegap https://mcp.edgegap.dev/mcp \
|
|
|
78
78
|
|
|
79
79
|
#### ChatGPT Codex
|
|
80
80
|
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
Codex reads the token from an environment variable and sends it as `Authorization: Bearer <token>`, which the hosted endpoint accepts. In `~/.codex/config.toml`:
|
|
82
|
+
|
|
83
|
+
```toml
|
|
84
|
+
[mcp_servers.edgegap]
|
|
85
|
+
url = "https://mcp.edgegap.dev/mcp"
|
|
86
|
+
bearer_token_env_var = "EDGEGAP_API_TOKEN"
|
|
83
87
|
```
|
|
84
88
|
|
|
89
|
+
Then set `EDGEGAP_API_TOKEN` to your token in the environment Codex starts from.
|
|
90
|
+
|
|
85
91
|
#### Claude Desktop and claude.ai
|
|
86
92
|
|
|
87
93
|
Custom connectors in claude.ai and Claude Desktop cannot send an `Authorization` header, so the hosted endpoint never receives your token from them: the connector shows as connected, but every tool call fails. Use the [Local Server](#local-server) instead.
|
|
@@ -101,6 +107,53 @@ In Claude Desktop, open **Settings → Developer → Edit Config** and add the l
|
|
|
101
107
|
|
|
102
108
|
Leave the token out and you're asked for it on first use. claude.ai in the browser can't run a local server, so it can't use Edgegap MCP until the hosted endpoint supports OAuth.
|
|
103
109
|
|
|
110
|
+
#### Cursor
|
|
111
|
+
|
|
112
|
+
The **Cursor** button at the top of this page installs it; to do it by hand, add this to `~/.cursor/mcp.json` (or `.cursor/mcp.json` in a project):
|
|
113
|
+
|
|
114
|
+
```json
|
|
115
|
+
{
|
|
116
|
+
"mcpServers": {
|
|
117
|
+
"edgegap": {
|
|
118
|
+
"url": "https://mcp.edgegap.dev/mcp",
|
|
119
|
+
"headers": { "Authorization": "token xxxxxxxx-e458-4592-b607-c2c28afd8b62" }
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
#### VS Code (Copilot agent mode)
|
|
126
|
+
|
|
127
|
+
The **VS Code** button at the top of this page installs it; to do it by hand, add this to `.vscode/mcp.json` (VS Code uses `servers`, not `mcpServers`):
|
|
128
|
+
|
|
129
|
+
```json
|
|
130
|
+
{
|
|
131
|
+
"servers": {
|
|
132
|
+
"edgegap": {
|
|
133
|
+
"type": "http",
|
|
134
|
+
"url": "https://mcp.edgegap.dev/mcp",
|
|
135
|
+
"headers": { "Authorization": "token xxxxxxxx-e458-4592-b607-c2c28afd8b62" }
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
#### Windsurf
|
|
142
|
+
|
|
143
|
+
In `~/.codeium/windsurf/mcp_config.json`, run the [Local Server](#local-server), which works in every client that starts MCP servers as commands:
|
|
144
|
+
|
|
145
|
+
```json
|
|
146
|
+
{
|
|
147
|
+
"mcpServers": {
|
|
148
|
+
"edgegap": {
|
|
149
|
+
"command": "npx",
|
|
150
|
+
"args": ["-y", "@edgegap/mcp"],
|
|
151
|
+
"env": { "EDGEGAP_API_TOKEN": "xxxxxxxx-e458-4592-b607-c2c28afd8b62" }
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
104
157
|
#### mcp.json
|
|
105
158
|
|
|
106
159
|
Most agentic IDEs also support integration by pasting JSON configuration:
|
|
@@ -161,14 +214,14 @@ To keep your API token on your own machine, run the server locally instead. Leav
|
|
|
161
214
|
}
|
|
162
215
|
```
|
|
163
216
|
|
|
164
|
-
Needs Node 18+. Pin a version in production (`@edgegap/mcp@0.
|
|
217
|
+
Needs Node 18+. Pin a version in production (`@edgegap/mcp@0.12.0`) rather than floating on latest. Registered in the official MCP registry as `dev.edgegap/mcp`.
|
|
165
218
|
|
|
166
219
|
The local server can also limit what an agent can do. These variables have no effect on the hosted endpoint at `mcp.edgegap.dev`:
|
|
167
220
|
|
|
168
221
|
| Variable | Default | Purpose |
|
|
169
222
|
| --- | --- | --- |
|
|
170
223
|
| `EDGEGAP_API_TOKEN` | *(prompted)* | API token. Optional: omit it and you're asked at first use. The `token ` prefix is added for you. Never pass it as a command-line argument. |
|
|
171
|
-
| `EDGEGAP_READ_ONLY` | `0` | Set to `1` and the
|
|
224
|
+
| `EDGEGAP_READ_ONLY` | `0` | Set to `1` and the tools that change something (marked ● in [Tools](#-tools)) are never registered, so the agent cannot be talked into calling them. |
|
|
172
225
|
| `EDGEGAP_APP_ALLOWLIST` | *(empty)* | Comma-separated application names. Limits what the agent can create and deploy into. Reading (listing apps and versions) is not limited, and neither is touching deployments once running. See [DESIGN.md](DESIGN.md#scope-of-the-allowlist). |
|
|
173
226
|
| `EDGEGAP_MAX_DURATION_MINUTES` | `60` | Ceiling on `max_duration` the agent may set on a version. |
|
|
174
227
|
| `EDGEGAP_MAX_AGENT_DEPLOYMENTS` | `5` | `edgegap_deploy` refuses while this many deployments tagged `edgegap-mcp` are running. `0` turns the cap off. |
|
|
@@ -187,6 +240,13 @@ The server includes the [Edgegap agent skills](https://github.com/edgegap/llm-ag
|
|
|
187
240
|
| `edgegap-fishnet` | Unity with FishNet end to end: headless server, Bayou/WebGL, matchmaker, end-to-end test. |
|
|
188
241
|
| `edgegap-purrnet` | Unity with PurrNet end to end: dedicated server, connect panel, matchmaker, end-to-end test. |
|
|
189
242
|
| `edgegap-fusion` | Unity with Photon Fusion 2 end to end: IL2CPP Linux server, server bound to 0.0.0.0, Edgegap deployment, BR200 kit. |
|
|
243
|
+
| `edgegap-fusion-simplefps` | Photon's Simple FPS sample on Edgegap dedicated servers. |
|
|
244
|
+
| `edgegap-godot` | Godot 4 with a Godot dedicated server: headless export, ENet or WebSocket, matchmaker. |
|
|
245
|
+
| `edgegap-colyseus` | Colyseus servers on Edgegap, direct or through the matchmaker. |
|
|
246
|
+
| `edgegap-nakama` | Nakama as the backend, starting Edgegap servers for its matches. |
|
|
247
|
+
| `edgegap-playfab` | PlayFab Matchmaking with Edgegap servers. |
|
|
248
|
+
| `edgegap-threejs` | Three.js and other browser games with their own Node.js server. |
|
|
249
|
+
| `edgegap-matchmaking` | Matchmaking design for any engine: who owns it, profiles, parties, region selection, backfill, third-party matchmakers. |
|
|
190
250
|
| `edgegap-manus` | Browser games built with Manus: backend matchmaking, Steam sign-in, signed join tokens, Node WebSocket server. |
|
|
191
251
|
| `edgegap-unreal` | Unreal Engine end to end: source engine, Linux server, matchmaker, end-to-end test. |
|
|
192
252
|
| `edgegap-eos-voice` | Voice chat for an Unreal game on Edgegap with EOS Voice: server-side room tokens, match and team rooms. |
|
|
@@ -200,8 +260,8 @@ The server includes the [Edgegap agent skills](https://github.com/edgegap/llm-ag
|
|
|
200
260
|
They're served three ways, so every MCP client can reach them:
|
|
201
261
|
|
|
202
262
|
- **Tools:** `edgegap_list_skills` and `edgegap_get_skill`, which loads a skill's `SKILL.md`, or one of its reference documents or templates with `file`.
|
|
203
|
-
- **Prompts:** one per skill, named after it. In Claude Code they show up as slash commands, e.g. `/
|
|
204
|
-
- **Resources:**
|
|
263
|
+
- **Prompts:** `deploy-game-server` ("Deploy my game server to Edgegap") is the place to start: it finds the engine and netcode, loads the matching skill and walks the golden path, cleanup included. There is also one prompt per skill, named after it. In Claude Code they show up as slash commands, e.g. `/mcp__edgegap__deploy-game-server`.
|
|
264
|
+
- **Resources:** each skill's `SKILL.md` is listed, at `edgegap-skill://<skill>/SKILL.md`; every other file is read through the `edgegap-skill://{skill}/{+path}` template, e.g. `edgegap-skill://edgegap-unity/references/deploy.md`.
|
|
205
265
|
|
|
206
266
|
Each release bundles the skills at the commit pinned in `scripts/skills-pin.txt`; `edgegap_context` reports which pack is loaded. `edgegap_list_skills` also reads the latest pack version from GitHub (one version number, cached for an hour; `EDGEGAP_SKILLS_CHECK=off` turns it off) and says when a newer one is out, and `edgegap_get_skill` adds the same note under a skill's header.
|
|
207
267
|
|
|
@@ -235,7 +295,7 @@ Your agent picks the right tool from your request. You don't need to name them,
|
|
|
235
295
|
| `edgegap_list_app_versions` | Lists versions with their image, resources, ports (with TLS Upgrade), and whether a registry login is set. |
|
|
236
296
|
| `edgegap_get_app_version` | Reads one version in full: image, resources, ports, max duration, image caching, restart policy, and env var names (never values). |
|
|
237
297
|
| `edgegap_create_app_version` ● | Registers a container image as a deployable version. Supports TLS Upgrade on WS and HTTP ports, which browser (WebGL) clients need for `wss://`. |
|
|
238
|
-
| `edgegap_update_app_version` ● | Changes an existing version: a new image tag, on/off, max duration, registry login, image caching (`force_cache`), shutdown grace period. Only the fields passed change
|
|
298
|
+
| `edgegap_update_app_version` ● | Changes an existing version: a new image tag, on/off, max duration, registry login, image caching (`force_cache`), shutdown grace period, ports, env vars. Only the fields passed change, but `ports` and `env` replace the whole list. Running deployments keep the old settings. |
|
|
239
299
|
| `edgegap_list_locations` | Lists the cities Edgegap deploys to, or, for one version, only those with capacity right now. |
|
|
240
300
|
| `edgegap_list_ping_beacons` | Lists the ping beacons game clients measure latency against before matchmaking. |
|
|
241
301
|
| `edgegap_deploy` ● | Deploys an authoritative dedicated server close to your players. Always tagged `edgegap-mcp`, and reports when Edgegap will stop it. |
|
|
@@ -298,7 +358,7 @@ Your API token can do anything in your organization, so the server adds its own
|
|
|
298
358
|
|
|
299
359
|
The server identifies itself with `User-Agent: edgegap-mcp/<version> (<MCP client name>)` on every API call.
|
|
300
360
|
|
|
301
|
-
**Usage analytics.** The local server and the self-hosted Docker image send nothing beyond the API calls themselves. The hosted endpoint at `mcp.edgegap.dev` uses [PostHog MCP Analytics](https://posthog.com/docs/mcp-analytics) (`@posthog/mcp`) and sends usage events to Edgegap's PostHog: which MCP client connected, which tool, prompt or skill resource was used, the names (not values) of the arguments passed, whether a call succeeded
|
|
361
|
+
**Usage analytics.** The local server and the self-hosted Docker image send nothing beyond the API calls themselves. The hosted endpoint at `mcp.edgegap.dev` uses [PostHog MCP Analytics](https://posthog.com/docs/mcp-analytics) (`@posthog/mcp`) and sends usage events to Edgegap's PostHog: which MCP client connected, which tool, prompt or skill resource was used, the names (not values) of the arguments passed, whether a call succeeded, its error code, the stage it failed at and the Edgegap API status, how long it took, whether it was a dry run, a few facts about the call (how a wait for a deployment ended, a validation result, which skill was loaded), which golden-path step was reached, plus the server version and Cloudflare's country code. On a failed call it also sends the error message, after removing your token, the values of the arguments you passed, and anything shaped like a credential, an IP address or an ID, cut to 300 characters. Deployment IDs are only sent as a keyed hash. Only named metadata properties are let through. It never sends your token, tool argument values (IP addresses, env vars, app or image names) or results, and GeoIP is off. It adds no parameters to the tools. Events from one token are grouped under a keyed, non-reversible hash of it. The full list is in [docs/analytics.md](docs/analytics.md). To opt out, send the header `X-Edgegap-Telemetry: off` (or `DNT: 1`), or use the local server.
|
|
302
362
|
|
|
303
363
|
## 🚨 Troubleshooting
|
|
304
364
|
|
|
@@ -320,6 +380,14 @@ Edgegap could not pull your container image. Check the repository, image name, a
|
|
|
320
380
|
|
|
321
381
|
Edgegap only gives registry credentials to the quick-start token the Unity and Unreal plugins use, so with a regular API token your agent can't retrieve them and asks you instead. Copy the Project, Username and Token from the [dashboard](https://app.edgegap.com) under **Container Registry**, or push to another registry Edgegap can pull from (Docker Hub, GitHub, AWS ECR, GCP, GitLab). See [External Registries](https://docs.edgegap.com/docs/tools-and-integrations/docker/external-registries).
|
|
322
382
|
|
|
383
|
+
### "status": "empty" or "not_configured"
|
|
384
|
+
|
|
385
|
+
Not an error. A list with nothing in it (no applications yet, no deployments running, an image never pushed) or a feature this organization has not set up (relays, a registry this token cannot read) comes back as a normal result with `status` and a `next_step`. Your agent should do the next step instead of retrying.
|
|
386
|
+
|
|
387
|
+
### No Token Yet
|
|
388
|
+
|
|
389
|
+
The skills (`edgegap_list_skills`, `edgegap_get_skill`), `edgegap_context`, `edgegap_generate_dockerfile` and `edgegap_validate_server_config` work without a token, so an agent can prepare the server build first. Create an account at [app.edgegap.com](https://app.edgegap.com) and a token under [User Settings → Tokens](https://app.edgegap.com/user-settings?tab=tokens). `edgegap_context` with `check_token: true` says whether the session's token is present and accepted, and shows its last four characters so you can find it on that page.
|
|
390
|
+
|
|
323
391
|
### Server Starts Locally but Not on Edgegap
|
|
324
392
|
|
|
325
393
|
Ask your agent to validate your server configuration, or to generate a new Dockerfile. The most common causes are an image built on Apple Silicon without `docker build --platform linux/amd64`, a server listening on a different port than the version exposes, or a UDP transport configured as TCP.
|
|
@@ -342,10 +410,10 @@ docker run --rm -p 8080:8080 edgegap-mcp
|
|
|
342
410
|
|
|
343
411
|
Clients connect to `http://<host>:8080/mcp` with their own `Authorization` header, the same way they connect to the hosted endpoint. The image holds no credential, and `/health` answers without one. `PORT`, `HOST`, `EDGEGAP_READ_ONLY`, `EDGEGAP_APP_ALLOWLIST`, `EDGEGAP_MAX_DURATION_MINUTES` and `EDGEGAP_MAX_AGENT_DEPLOYMENTS` apply. Read [worker/DECISION.md](worker/DECISION.md) before exposing it beyond a private network.
|
|
344
412
|
|
|
345
|
-
Prebuilt images for `linux/amd64` and `linux/arm64` are published to `ghcr.io/edgegap/edgegap-mcp
|
|
413
|
+
Prebuilt images for `linux/amd64` and `linux/arm64` are published to `ghcr.io/edgegap/llm-mcp-server` (and, for existing setups, the old name `ghcr.io/edgegap/edgegap-mcp`), tagged `main` and `sha-<commit>` on every push to `main`, plus the version on `v*` tags:
|
|
346
414
|
|
|
347
415
|
```bash
|
|
348
|
-
docker run --rm -p 8080:8080 ghcr.io/edgegap/
|
|
416
|
+
docker run --rm -p 8080:8080 ghcr.io/edgegap/llm-mcp-server:main
|
|
349
417
|
```
|
|
350
418
|
|
|
351
419
|
## Development
|
package/dist/auth.js
CHANGED
|
@@ -39,6 +39,11 @@
|
|
|
39
39
|
*/
|
|
40
40
|
import { stripTokenPrefix } from './config.js';
|
|
41
41
|
export class TokenUnavailableError extends Error {
|
|
42
|
+
reason;
|
|
43
|
+
constructor(message, reason = 'absent') {
|
|
44
|
+
super(message);
|
|
45
|
+
this.reason = reason;
|
|
46
|
+
}
|
|
42
47
|
}
|
|
43
48
|
/** Shown to the developer at the moment they are asked to hand over a token. */
|
|
44
49
|
export const PRIVILEGE_WARNING = 'This token grants full access to your entire Edgegap organization: every ' +
|
|
@@ -141,7 +146,10 @@ export class TokenProvider {
|
|
|
141
146
|
'This MCP client does not support interactive prompts, so the token has ' +
|
|
142
147
|
'to be supplied up front. Add it to your MCP client config:\n\n' +
|
|
143
148
|
' "env": { "EDGEGAP_API_TOKEN": "your-token" }\n\n' +
|
|
144
|
-
'Generate a token at https://app.edgegap.com/user-settings?tab=tokens
|
|
149
|
+
'Generate a token at https://app.edgegap.com/user-settings?tab=tokens ' +
|
|
150
|
+
'(no Edgegap account yet? Sign up free at https://app.edgegap.com).\n\n' +
|
|
151
|
+
'Until then, edgegap_context, edgegap_list_skills, edgegap_get_skill, edgegap_generate_dockerfile ' +
|
|
152
|
+
'and edgegap_validate_server_config work without a token.\n\n' +
|
|
145
153
|
PRIVILEGE_WARNING);
|
|
146
154
|
}
|
|
147
155
|
const result = await this.server.elicitInput({
|
|
@@ -172,19 +180,19 @@ export class TokenProvider {
|
|
|
172
180
|
if (result.action !== 'accept' || !result.content) {
|
|
173
181
|
throw new TokenUnavailableError('The developer declined to provide an Edgegap API token. Do not retry ' +
|
|
174
182
|
'automatically. Stop and tell them which operation needed it, so they ' +
|
|
175
|
-
'can decide whether to continue.');
|
|
183
|
+
'can decide whether to continue.', 'declined');
|
|
176
184
|
}
|
|
177
185
|
const acknowledged = result.content.acknowledged === true;
|
|
178
186
|
if (!acknowledged) {
|
|
179
187
|
throw new TokenUnavailableError('The token privilege acknowledgement was not accepted, so no token was ' +
|
|
180
188
|
'stored. Nothing has been sent to Edgegap. If the org-wide scope is the ' +
|
|
181
189
|
'concern, the safer setup is a token from a separate non-production ' +
|
|
182
|
-
'organization with EDGEGAP_READ_ONLY=1.');
|
|
190
|
+
'organization with EDGEGAP_READ_ONLY=1.', 'declined');
|
|
183
191
|
}
|
|
184
192
|
const raw = String(result.content.api_token ?? '').trim();
|
|
185
193
|
const token = stripTokenPrefix(raw);
|
|
186
194
|
if (!token) {
|
|
187
|
-
throw new TokenUnavailableError('An empty token was submitted. Nothing was stored.');
|
|
195
|
+
throw new TokenUnavailableError('An empty token was submitted. Nothing was stored.', 'declined');
|
|
188
196
|
}
|
|
189
197
|
this.cached = token;
|
|
190
198
|
return token;
|
|
@@ -193,6 +201,7 @@ export class TokenProvider {
|
|
|
193
201
|
export class StaticTokenProvider {
|
|
194
202
|
token;
|
|
195
203
|
unavailableMessage;
|
|
204
|
+
problem;
|
|
196
205
|
used = false;
|
|
197
206
|
/**
|
|
198
207
|
* @param token credential for this request, if the caller found a usable one
|
|
@@ -202,9 +211,10 @@ export class StaticTokenProvider {
|
|
|
202
211
|
* distinction is the whole difference between a developer who can fix their
|
|
203
212
|
* setup and one staring at a generic 401. Defaults to the generic text.
|
|
204
213
|
*/
|
|
205
|
-
constructor(token, unavailableMessage) {
|
|
214
|
+
constructor(token, unavailableMessage, problem = 'absent') {
|
|
206
215
|
this.token = token;
|
|
207
216
|
this.unavailableMessage = unavailableMessage;
|
|
217
|
+
this.problem = problem;
|
|
208
218
|
}
|
|
209
219
|
get current() {
|
|
210
220
|
return this.token;
|
|
@@ -213,7 +223,7 @@ export class StaticTokenProvider {
|
|
|
213
223
|
if (!this.token) {
|
|
214
224
|
throw new TokenUnavailableError(this.unavailableMessage ??
|
|
215
225
|
'No Edgegap API token on this request. Send it as an Authorization ' +
|
|
216
|
-
'header on the MCP connection.');
|
|
226
|
+
'header on the MCP connection.', this.problem);
|
|
217
227
|
}
|
|
218
228
|
return this.token;
|
|
219
229
|
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What one tool call did, for analytics: success, a stable error code, the
|
|
3
|
+
* stage it failed at, the Edgegap API status, and a few tool-specific facts.
|
|
4
|
+
*
|
|
5
|
+
* Built by the tool wrapper in tools.ts and handed to RegisterOptions.onToolCall.
|
|
6
|
+
* Only the hosted Worker passes that hook (worker/telemetry.ts); the local
|
|
7
|
+
* server and the Docker image send nothing. Nothing here does I/O, so the
|
|
8
|
+
* same rules run in Node and in the Worker and are unit-tested directly.
|
|
9
|
+
*
|
|
10
|
+
* Values in `props` must already be safe to send: names, counts, enums.
|
|
11
|
+
* Values in `hash` are raw identifiers (a deployment request_id) that the
|
|
12
|
+
* telemetry side hashes before sending; they never leave the Worker as-is.
|
|
13
|
+
*/
|
|
14
|
+
const MAX_MESSAGE = 300;
|
|
15
|
+
/**
|
|
16
|
+
* Error text made safe to send: the API token and anything shaped like a
|
|
17
|
+
* credential or an identifier is masked, then it is cut to 300 characters.
|
|
18
|
+
* The tool layer already strips the session's own token; this is the second
|
|
19
|
+
* net, for registry tokens, other UUIDs, JWTs, IPs and long opaque strings.
|
|
20
|
+
*/
|
|
21
|
+
export function sanitizeErrorMessage(text, token, args) {
|
|
22
|
+
if (!text)
|
|
23
|
+
return undefined;
|
|
24
|
+
let out = text;
|
|
25
|
+
if (token && token.length >= 8) {
|
|
26
|
+
for (const needle of [token, token.replace(/-/g, '')]) {
|
|
27
|
+
if (needle.length >= 8)
|
|
28
|
+
out = out.split(needle).join('***');
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
// The call's own argument values (application and image names, IPs, env
|
|
32
|
+
// values) are the developer's data: replaced by the argument's name.
|
|
33
|
+
for (const [name, value] of argumentStrings(args)) {
|
|
34
|
+
out = out.split(value).join(`<${name}>`);
|
|
35
|
+
}
|
|
36
|
+
out = out
|
|
37
|
+
// "[api.edgegap.com]" host label and "NOTE: ..." first-use notices add nothing.
|
|
38
|
+
.replace(/^\[[^\]\n]+\]\n?/, '')
|
|
39
|
+
.replace(/\n*NOTE: [\s\S]*$/, '')
|
|
40
|
+
.replace(/\b(eyJ[\w-]+\.[\w-]+\.[\w-]+)/g, '***')
|
|
41
|
+
.replace(/\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b/gi, '***')
|
|
42
|
+
.replace(/((?:token|password|secret|api[_-]?key|authorization)["']?\s*[:=]\s*["']?)[^\s"',}]+/gi, '$1***')
|
|
43
|
+
.replace(/\b\d{1,3}(?:\.\d{1,3}){3}\b/g, '<ip>')
|
|
44
|
+
.replace(/\b[A-Za-z0-9+/_$-]{32,}={0,2}/g, '***')
|
|
45
|
+
.trim();
|
|
46
|
+
return out.length > MAX_MESSAGE ? `${out.slice(0, MAX_MESSAGE - 1)}…` : out;
|
|
47
|
+
}
|
|
48
|
+
/** Every string value in a call's arguments, longest first, with its top-level name. */
|
|
49
|
+
function argumentStrings(args) {
|
|
50
|
+
const out = [];
|
|
51
|
+
const walk = (name, v) => {
|
|
52
|
+
if (typeof v === 'string') {
|
|
53
|
+
if (v.trim().length >= 3)
|
|
54
|
+
out.push([name, v]);
|
|
55
|
+
}
|
|
56
|
+
else if (Array.isArray(v)) {
|
|
57
|
+
for (const x of v)
|
|
58
|
+
walk(name, x);
|
|
59
|
+
}
|
|
60
|
+
else if (v && typeof v === 'object') {
|
|
61
|
+
for (const x of Object.values(v))
|
|
62
|
+
walk(name, x);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
for (const [k, v] of Object.entries(args ?? {}))
|
|
66
|
+
walk(k, v);
|
|
67
|
+
return out.sort((a, b) => b[1].length - a[1].length);
|
|
68
|
+
}
|
|
69
|
+
/** The error code for an Edgegap API status, given what the tool was looking for. */
|
|
70
|
+
export function codeForStatus(status, notFound, forbidden, message = '') {
|
|
71
|
+
if (/quota|limit reached|exceed|upgrade your plan|plan limit/i.test(message) && [400, 402, 403, 429].includes(status)) {
|
|
72
|
+
return 'QUOTA_REACHED';
|
|
73
|
+
}
|
|
74
|
+
switch (status) {
|
|
75
|
+
case 400:
|
|
76
|
+
return notFound === 'DEPLOYMENT_NOT_FOUND' || notFound === 'LOGS_NOT_FOUND' ? notFound : 'UPSTREAM_REJECTED';
|
|
77
|
+
case 401:
|
|
78
|
+
return 'AUTH_REJECTED';
|
|
79
|
+
case 403:
|
|
80
|
+
return forbidden ?? 'FORBIDDEN';
|
|
81
|
+
case 404:
|
|
82
|
+
return notFound ?? 'NOT_FOUND';
|
|
83
|
+
case 409:
|
|
84
|
+
return 'CONFLICT';
|
|
85
|
+
case 422:
|
|
86
|
+
return 'NO_CAPACITY';
|
|
87
|
+
case 424:
|
|
88
|
+
return 'IMAGE_PULL_FAILED';
|
|
89
|
+
case 429:
|
|
90
|
+
return 'RATE_LIMITED';
|
|
91
|
+
default:
|
|
92
|
+
return status >= 500 ? 'UPSTREAM_ERROR' : 'UPSTREAM_REJECTED';
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/** The code for a tool's own refusal, read from its wording. */
|
|
96
|
+
export function codeForToolFailure(text) {
|
|
97
|
+
if (/^Refused|refused/.test(text))
|
|
98
|
+
return 'GUARDRAIL_REFUSED';
|
|
99
|
+
if (/No skill named|is not a file in the/.test(text))
|
|
100
|
+
return 'SKILL_NOT_FOUND';
|
|
101
|
+
if (/^Invalid arguments|Input validation error/.test(text))
|
|
102
|
+
return 'VALIDATION_FAILED';
|
|
103
|
+
return 'VALIDATION_FAILED';
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Fills in what the tool did not say itself: the code from the API status or
|
|
107
|
+
* the wording, and the stage from whether, and how, the API was called.
|
|
108
|
+
*/
|
|
109
|
+
export function finishReport(input) {
|
|
110
|
+
const { meta = {}, upstream } = input;
|
|
111
|
+
const statuses = upstream.filter((u) => typeof u === 'number');
|
|
112
|
+
const last = upstream[upstream.length - 1];
|
|
113
|
+
const failedUpstream = upstream.find((u) => typeof u !== 'number' || u >= 400);
|
|
114
|
+
let code = meta.code;
|
|
115
|
+
let stage = meta.stage;
|
|
116
|
+
if (input.isError) {
|
|
117
|
+
if (!code) {
|
|
118
|
+
if (last === 'timeout')
|
|
119
|
+
code = 'TIMEOUT';
|
|
120
|
+
else if (last === 'network')
|
|
121
|
+
code = 'NETWORK';
|
|
122
|
+
else if (typeof failedUpstream === 'number')
|
|
123
|
+
code = codeForStatus(failedUpstream, undefined, undefined, input.text);
|
|
124
|
+
else
|
|
125
|
+
code = codeForToolFailure(input.text);
|
|
126
|
+
}
|
|
127
|
+
if (!stage) {
|
|
128
|
+
if (code.startsWith('AUTH_') && code !== 'AUTH_REJECTED')
|
|
129
|
+
stage = 'pre_flight';
|
|
130
|
+
else if (failedUpstream !== undefined)
|
|
131
|
+
stage = 'upstream';
|
|
132
|
+
else
|
|
133
|
+
stage = upstream.length ? 'post_process' : 'pre_flight';
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
const props = {};
|
|
137
|
+
for (const [k, v] of Object.entries(meta.props ?? {}))
|
|
138
|
+
if (v !== undefined)
|
|
139
|
+
props[k] = v;
|
|
140
|
+
const hash = {};
|
|
141
|
+
for (const [k, v] of Object.entries(meta.hash ?? {}))
|
|
142
|
+
if (v)
|
|
143
|
+
hash[k] = v;
|
|
144
|
+
return {
|
|
145
|
+
tool: input.tool,
|
|
146
|
+
requestId: input.requestId,
|
|
147
|
+
success: !input.isError,
|
|
148
|
+
...(input.isError ? { error_code: code, error_message: sanitizeErrorMessage(input.text, input.token, input.args), failed_stage: stage } : {}),
|
|
149
|
+
upstream_status: statuses.length ? statuses[statuses.length - 1] : null,
|
|
150
|
+
upstream_calls: upstream.length,
|
|
151
|
+
latency_ms: input.latencyMs,
|
|
152
|
+
...(input.dryRun ? { dry_run: true } : {}),
|
|
153
|
+
props,
|
|
154
|
+
hash,
|
|
155
|
+
milestones: input.isError ? [] : [...new Set(meta.milestones ?? [])],
|
|
156
|
+
};
|
|
157
|
+
}
|
package/dist/client.js
CHANGED
|
@@ -45,6 +45,12 @@ export class EdgegapClient {
|
|
|
45
45
|
config;
|
|
46
46
|
auth;
|
|
47
47
|
options;
|
|
48
|
+
/**
|
|
49
|
+
* Every Edgegap API response this client has seen, in order: the HTTP
|
|
50
|
+
* status, or "timeout"/"network". The tool wrapper reads the entries a call
|
|
51
|
+
* added to report what the API said. Statuses only, never bodies.
|
|
52
|
+
*/
|
|
53
|
+
upstream = [];
|
|
48
54
|
constructor(config, auth, options = {}) {
|
|
49
55
|
this.config = config;
|
|
50
56
|
this.auth = auth;
|
|
@@ -110,13 +116,16 @@ export class EdgegapClient {
|
|
|
110
116
|
}
|
|
111
117
|
catch (err) {
|
|
112
118
|
if (err instanceof Error && err.name === 'AbortError') {
|
|
119
|
+
this.upstream.push('timeout');
|
|
113
120
|
throw new Error(`Request to ${method} ${path} timed out after ${this.config.requestTimeoutMs}ms.`);
|
|
114
121
|
}
|
|
122
|
+
this.upstream.push('network');
|
|
115
123
|
throw new Error(redact(`Network error calling ${method} ${path}: ${err.message}`, token));
|
|
116
124
|
}
|
|
117
125
|
finally {
|
|
118
126
|
clearTimeout(timer);
|
|
119
127
|
}
|
|
128
|
+
this.upstream.push(response.status);
|
|
120
129
|
const raw = await response.text();
|
|
121
130
|
let parsed = undefined;
|
|
122
131
|
if (raw) {
|
package/dist/hosted.js
CHANGED
|
@@ -45,7 +45,10 @@ export function extractToken(header) {
|
|
|
45
45
|
* rather than pointing at docs.
|
|
46
46
|
*/
|
|
47
47
|
export function unavailableMessage(problem) {
|
|
48
|
-
const common = `Get a token at ${TOKEN_URL}
|
|
48
|
+
const common = `Get a token at ${TOKEN_URL} (no Edgegap account yet? Sign up free at https://app.edgegap.com). ` +
|
|
49
|
+
'Until then, edgegap_context, edgegap_list_skills, edgegap_get_skill, edgegap_generate_dockerfile and ' +
|
|
50
|
+
'edgegap_validate_server_config work without one, so you can prepare the server build first.\n\n' +
|
|
51
|
+
'The token is used for the request and discarded — ' +
|
|
49
52
|
'never stored. Edgegap tokens are organization-wide and cannot be scoped, ' +
|
|
50
53
|
'so prefer the local server (npx -y @edgegap/mcp), which keeps the token ' +
|
|
51
54
|
'on your own machine and never sends it through Edgegap infrastructure.';
|
package/dist/http.js
CHANGED
|
@@ -91,7 +91,7 @@ function main() {
|
|
|
91
91
|
return;
|
|
92
92
|
}
|
|
93
93
|
const { token, problem } = extractToken(req.headers.authorization);
|
|
94
|
-
const auth = new StaticTokenProvider(token, problem ? unavailableMessage(problem) : undefined);
|
|
94
|
+
const auth = new StaticTokenProvider(token, problem ? unavailableMessage(problem) : undefined, problem);
|
|
95
95
|
const server = new McpServer({ name: 'edgegap', version: VERSION }, { instructions: serverInstructions('hosted') });
|
|
96
96
|
const client = new EdgegapClient(config, auth, {
|
|
97
97
|
clientName: () => server.server.getClientVersion()?.name,
|
package/dist/outputs.js
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Output schemas for the tools whose results have a stable shape. Clients that
|
|
3
|
+
* read structuredContent can rely on these fields; the JSON text in content is
|
|
4
|
+
* the same payload.
|
|
5
|
+
*
|
|
6
|
+
* Deliberately loose: every field is optional, and objects keep
|
|
7
|
+
* fields not listed here. The SDK rejects a successful result that does not
|
|
8
|
+
* match its tool's schema, so a schema stricter than the Edgegap API's own
|
|
9
|
+
* answers would turn a working call into an error. They document the fields
|
|
10
|
+
* agents use, rather than police them. ok() drops null fields, so no schema
|
|
11
|
+
* needs nullable (each one doubles the JSON Schema). Dry runs of write tools return their
|
|
12
|
+
* own fields (dry_run, sent, requests), which pass for the same reason.
|
|
13
|
+
*/
|
|
14
|
+
import { z } from 'zod';
|
|
15
|
+
const str = z.string().optional();
|
|
16
|
+
const num = z.number().optional();
|
|
17
|
+
const bool = z.boolean().optional();
|
|
18
|
+
const strs = z.array(z.string()).optional();
|
|
19
|
+
const obj = (shape) => z.looseObject(shape).optional();
|
|
20
|
+
const list = (shape) => z.array(z.looseObject(shape)).optional();
|
|
21
|
+
/** total, and when a page is short: showing, truncated, next_step. */
|
|
22
|
+
const page = { total: num, showing: num, truncated: bool, next_step: str };
|
|
23
|
+
const port = { name: str, port: num, protocol: str, tls_upgrade: bool };
|
|
24
|
+
const version = {
|
|
25
|
+
name: str,
|
|
26
|
+
active: bool,
|
|
27
|
+
image: str,
|
|
28
|
+
registry_credentials_set: bool,
|
|
29
|
+
cpu_units: num,
|
|
30
|
+
memory_mb: num,
|
|
31
|
+
max_duration_minutes: num,
|
|
32
|
+
ports: list(port),
|
|
33
|
+
};
|
|
34
|
+
const deployment = {
|
|
35
|
+
request_id: str,
|
|
36
|
+
status: str,
|
|
37
|
+
running: bool,
|
|
38
|
+
ready: bool,
|
|
39
|
+
error: bool,
|
|
40
|
+
error_detail: str,
|
|
41
|
+
fqdn: str,
|
|
42
|
+
public_ip: str,
|
|
43
|
+
application: str,
|
|
44
|
+
version: str,
|
|
45
|
+
location: str,
|
|
46
|
+
elapsed_seconds: num,
|
|
47
|
+
ports: list({ name: str, connect: str, external: num, internal: num, protocol: str }),
|
|
48
|
+
next_step: str,
|
|
49
|
+
};
|
|
50
|
+
const series = obj({ latest: num, average: num, peak: num, samples: num, labels: strs, from: str, to: str });
|
|
51
|
+
/** Loose at the top level too: a raw shape becomes additionalProperties: false
|
|
52
|
+
* in JSON Schema, and clients that validate results reject extra fields. */
|
|
53
|
+
const out = (shape) => z.looseObject(shape);
|
|
54
|
+
const shapes = {
|
|
55
|
+
context: {
|
|
56
|
+
server: str,
|
|
57
|
+
transport: str,
|
|
58
|
+
api_host: str,
|
|
59
|
+
api_base_url: str,
|
|
60
|
+
read_only: bool,
|
|
61
|
+
max_duration_ceiling_minutes: num,
|
|
62
|
+
skills_pack: str,
|
|
63
|
+
forced_deploy_tag: str,
|
|
64
|
+
guardrails: obj({}),
|
|
65
|
+
},
|
|
66
|
+
listApps: { ...page, applications: list({ name: str, active: bool, last_updated: str }) },
|
|
67
|
+
listAppVersions: { application: str, ...page, versions: list(version) },
|
|
68
|
+
getAppVersion: {
|
|
69
|
+
application: str,
|
|
70
|
+
...version,
|
|
71
|
+
force_cache: bool,
|
|
72
|
+
caching_percent: num,
|
|
73
|
+
verify_image: bool,
|
|
74
|
+
restart_policy: str,
|
|
75
|
+
termination_grace_period_seconds: num,
|
|
76
|
+
env: list({ key: str, hidden: bool }),
|
|
77
|
+
auto_stop_after_minutes: num,
|
|
78
|
+
auto_stop: str,
|
|
79
|
+
warning: str,
|
|
80
|
+
},
|
|
81
|
+
listLocations: {
|
|
82
|
+
filtered_for: str,
|
|
83
|
+
...page,
|
|
84
|
+
locations: list({ city: str, region: str, country: str, continent: str, latitude: num, longitude: num }),
|
|
85
|
+
messages: strs,
|
|
86
|
+
},
|
|
87
|
+
listPingBeacons: { total: num, beacons: list({ host: str, udp_port: num, tcp_port: num, city: str, country: str, continent: str }) },
|
|
88
|
+
deploy: {
|
|
89
|
+
request_id: str,
|
|
90
|
+
status: str,
|
|
91
|
+
tags: strs,
|
|
92
|
+
auto_stop_after_minutes: num,
|
|
93
|
+
auto_stop: str,
|
|
94
|
+
warning: str,
|
|
95
|
+
resources: obj({ cpu_units: num, memory_mib: num }),
|
|
96
|
+
next_step: str,
|
|
97
|
+
},
|
|
98
|
+
deployment,
|
|
99
|
+
waitForDeployment: { ...deployment, waited_seconds: num },
|
|
100
|
+
listDeployments: { ...page, deployments: list({ request_id: str, ready: bool, fqdn: str, started: str, tags: strs }) },
|
|
101
|
+
metrics: {
|
|
102
|
+
request_id: str,
|
|
103
|
+
cpu: series,
|
|
104
|
+
cpu_throttle_rate: series,
|
|
105
|
+
memory: series,
|
|
106
|
+
network_receive: series,
|
|
107
|
+
network_transmit: series,
|
|
108
|
+
totals: obj({ received: num, transmitted: num, disk_read: num, disk_written: num }),
|
|
109
|
+
note: str,
|
|
110
|
+
},
|
|
111
|
+
listRegistryTags: {
|
|
112
|
+
image_name: str,
|
|
113
|
+
note: str,
|
|
114
|
+
...page,
|
|
115
|
+
tags: list({ tag: str, pushed: str, size_mb: num, digest: str }),
|
|
116
|
+
},
|
|
117
|
+
listRelaySessions: {
|
|
118
|
+
...page,
|
|
119
|
+
sessions: list({ session_id: str, status: str, ready: bool, linked: bool, players: num, relay: str, error: str }),
|
|
120
|
+
},
|
|
121
|
+
validateServerConfig: {
|
|
122
|
+
verdict: str,
|
|
123
|
+
engine: str,
|
|
124
|
+
errors: list({ severity: str, code: str, message: str, fix: str, line: num }),
|
|
125
|
+
warnings: list({ severity: str, code: str, message: str, fix: str, line: num }),
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
export const OUTPUT = Object.fromEntries(Object.entries(shapes).map(([k, v]) => [k, out(v)]));
|