@edgegap/mcp 0.3.2 → 0.3.3

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 CHANGED
@@ -82,9 +82,24 @@ claude mcp add --transport http edgegap https://mcp.edgegap.dev/mcp \
82
82
  codex mcp add edgegap --url https://mcp.edgegap.dev/mcp
83
83
  ```
84
84
 
85
- #### claude.ai
85
+ #### Claude Desktop and claude.ai
86
86
 
87
- Add `https://mcp.edgegap.dev/mcp` as a custom connector and supply the same token.
87
+ 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.
88
+
89
+ In Claude Desktop, open **Settings → Developer → Edit Config** and add the local server to `claude_desktop_config.json`:
90
+
91
+ ```json
92
+ {
93
+ "mcpServers": {
94
+ "edgegap": {
95
+ "command": "npx",
96
+ "args": ["-y", "@edgegap/mcp"]
97
+ }
98
+ }
99
+ }
100
+ ```
101
+
102
+ 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.
88
103
 
89
104
  #### mcp.json
90
105
 
@@ -142,7 +157,7 @@ To keep your API token on your own machine, run the server locally instead. Leav
142
157
  }
143
158
  ```
144
159
 
145
- Needs Node 18+. Pin a version in production (`@edgegap/mcp@0.3.2`) rather than floating on latest. Registered in the official MCP registry as `dev.edgegap/mcp`.
160
+ Needs Node 18+. Pin a version in production (`@edgegap/mcp@0.3.3`) rather than floating on latest. Registered in the official MCP registry as `dev.edgegap/mcp`.
146
161
 
147
162
  The local server can also limit what an agent can do. These variables have no effect on the hosted endpoint at `mcp.edgegap.dev`:
148
163
 
@@ -150,7 +165,7 @@ The local server can also limit what an agent can do. These variables have no ef
150
165
  | --- | --- | --- |
151
166
  | `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. |
152
167
  | `EDGEGAP_READ_ONLY` | `0` | Set to `1` and the eight mutating tools are never registered, so the agent cannot be talked into calling them. |
153
- | `EDGEGAP_APP_ALLOWLIST` | *(empty)* | Comma-separated application names. Limits what the agent can create and deploy into, not what it can touch once running. See [DESIGN.md](DESIGN.md#scope-of-the-allowlist). |
168
+ | `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). |
154
169
  | `EDGEGAP_MAX_DURATION_MINUTES` | `60` | Ceiling on `max_duration` the agent may set on a version. |
155
170
  | `EDGEGAP_TIMEOUT_MS` | `30000` | Per-request HTTP timeout. |
156
171
 
@@ -173,20 +188,20 @@ Your agent picks the right tool from your request. You don't need to name them,
173
188
  | --- | --- |
174
189
  | `edgegap_list_apps` | Lists your applications. |
175
190
  | `edgegap_create_app` ● | Creates an application. |
176
- | `edgegap_list_app_versions` | Lists versions with their image, resources, and ports. |
177
- | `edgegap_create_app_version` ● | Registers a container image as a deployable version. |
191
+ | `edgegap_list_app_versions` | Lists versions with their image, resources, ports (with TLS Upgrade), and whether a registry login is set. |
192
+ | `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://`. |
178
193
  | `edgegap_deploy` ● | Deploys an authoritative dedicated server close to your players. |
179
194
  | `edgegap_wait_for_deployment` | Waits until the server is ready and returns the connection address. |
180
195
  | `edgegap_get_deployment` | Reads a deployment's status. |
181
196
  | `edgegap_list_deployments` | Lists running deployments, filtered by application, version, status, tags and more, and sorted by age. Finds servers left running. See [Filter Deployments](https://docs.edgegap.com/learn/orchestration/deployments#filter-deployments). |
182
- | `edgegap_get_deployment_logs` | Reads container logs and crash details. |
197
+ | `edgegap_get_deployment_logs` | Reads container logs and crash details while the deployment runs. After it stops, logs are only kept if Endpoint Storage was set up. |
183
198
  | `edgegap_stop_deployment` ● | Stops one deployment. |
184
199
 
185
200
  ### Matchmaking
186
201
 
187
202
  | Tool | What it does |
188
203
  | --- | --- |
189
- | `edgegap_build_matchmaker_config` | Generates a matchmaker configuration (teams, team size, optional latency rules and expansions) and checks that the version it deploys exists. Upload the result in the dashboard to create your matchmaker, which starts a dedicated server for each match. |
204
+ | `edgegap_build_matchmaker_config` | Generates a matchmaker configuration (teams, team size, optional latency rules and expansions) and checks that the version it deploys exists. Set `allowed_cors_origins` for browser (WebGL) clients. Upload the result in the dashboard to create your matchmaker, which starts a dedicated server for each match. |
190
205
 
191
206
  Learn more about the configuration in [Matchmaking](https://docs.edgegap.com/learn/matchmaking).
192
207
 
package/dist/auth.js CHANGED
@@ -37,6 +37,7 @@
37
37
  * The real fix is scoped, revocable, deploy-only credentials issued by Edgegap.
38
38
  * Until those exist, this file is a workaround and should be labelled as one.
39
39
  */
40
+ import { stripTokenPrefix } from './config.js';
40
41
  export class TokenUnavailableError extends Error {
41
42
  }
42
43
  /** Shown to the developer at the moment they are asked to hand over a token. */
@@ -181,7 +182,7 @@ export class TokenProvider {
181
182
  'organization with EDGEGAP_READ_ONLY=1.');
182
183
  }
183
184
  const raw = String(result.content.api_token ?? '').trim();
184
- const token = raw.replace(/^token\s+/i, '');
185
+ const token = stripTokenPrefix(raw);
185
186
  if (!token) {
186
187
  throw new TokenUnavailableError('An empty token was submitted. Nothing was stored.');
187
188
  }
package/dist/config.js CHANGED
@@ -26,8 +26,8 @@ export function loadConfig(env = process.env) {
26
26
  // anything works" step that loses people during onboarding.
27
27
  const raw = env.EDGEGAP_API_TOKEN?.trim();
28
28
  // Tokens are pasted by hand often enough that it is worth catching the
29
- // common mistake of including the "token " prefix twice.
30
- const envToken = raw ? raw.replace(/^token\s+/i, '') : undefined;
29
+ // common mistake of including the "token " prefix, once or more.
30
+ const envToken = raw ? stripTokenPrefix(raw) || undefined : undefined;
31
31
  return {
32
32
  envToken,
33
33
  baseUrlV1: env.EDGEGAP_BASE_URL?.trim() || 'https://api.edgegap.com',
@@ -52,6 +52,18 @@ export function assertAppAllowed(config, appName) {
52
52
  `allowlist rather than trying another application name.`);
53
53
  }
54
54
  }
55
+ /**
56
+ * Removes any run of "Bearer " / "token " prefixes from a pasted credential.
57
+ *
58
+ * The prefix gets doubled easily: the dashboard shows the header form
59
+ * ("token <uuid>"), so an EDGEGAP_API_TOKEN that already carries it, dropped
60
+ * into a config that adds "token " again, sends "token token <uuid>". Stripping
61
+ * only one left "token <uuid>", which the hosted server then mistook for a
62
+ * foreign credential and refused with a misleading message.
63
+ */
64
+ export function stripTokenPrefix(value) {
65
+ return value.trim().replace(/^(?:(?:bearer|token)\s+)+/i, '').trim();
66
+ }
55
67
  /**
56
68
  * Strips the live token out of text before it reaches the model.
57
69
  * Error strings from HTTP layers sometimes echo request headers back.
@@ -72,17 +72,31 @@ export function generateDockerfile(input) {
72
72
  throw new DockerfileInputError(`base_image "${base}" is not a valid image reference.`);
73
73
  }
74
74
  // ------------------------------------------------------------- ports ----
75
+ // A WebSocket transport means browser (WebGL) clients, which need wss://:
76
+ // Edgegap's TLS Upgrade on the WS port.
77
+ const browserNetcode = input.netcode !== undefined && protocolForNetcode(input.netcode) === 'WS';
78
+ let autoTls = false; // set when TLS was turned on without being asked for
75
79
  let ports;
76
80
  if (input.ports && input.ports.length > 0) {
77
- ports = input.ports.map((p, i) => ({
78
- port: p.port,
79
- protocol: p.protocol.toUpperCase(),
80
- name: p.name ?? (i === 0 ? 'gameport' : `port${i + 1}`),
81
- }));
81
+ ports = input.ports.map((p, i) => {
82
+ const protocol = p.protocol.toUpperCase();
83
+ let tls = p.tls_upgrade;
84
+ if (tls === undefined && browserNetcode && protocol === 'WS') {
85
+ tls = true;
86
+ autoTls = true;
87
+ }
88
+ return {
89
+ port: p.port,
90
+ protocol,
91
+ name: p.name ?? (i === 0 ? 'gameport' : `port${i + 1}`),
92
+ ...(tls !== undefined ? { tls_upgrade: tls } : {}),
93
+ };
94
+ });
82
95
  }
83
96
  else {
84
97
  const protocol = (input.netcode && protocolForNetcode(input.netcode)) || 'UDP';
85
- ports = [{ port: 7777, protocol, name: 'gameport' }];
98
+ ports = [{ port: 7777, protocol, name: 'gameport', ...(browserNetcode ? { tls_upgrade: true } : {}) }];
99
+ autoTls = browserNetcode;
86
100
  assumptions.push(`Assumed the server listens on 7777/${protocol}${input.netcode ? ` (the protocol ${input.netcode} uses)` : ''}. ` +
87
101
  'Confirm the port in the server\'s network/transport settings and pass ports if it differs.');
88
102
  }
@@ -172,6 +186,10 @@ export function generateDockerfile(input) {
172
186
  }
173
187
  }
174
188
  }
189
+ if (autoTls) {
190
+ assumptions.push('Turned on tls_upgrade for the WebSocket port, because WebSocket transports usually mean ' +
191
+ 'browser (WebGL) clients, which need wss://. Set tls_upgrade: false if no client runs in a browser.');
192
+ }
175
193
  assumptions.push(buildPath === '.'
176
194
  ? 'Run docker build from inside the server build folder (the folder itself is the build context).'
177
195
  : `Run docker build from the folder that contains ${buildPath}.`);
package/dist/hosted.js CHANGED
@@ -6,6 +6,7 @@
6
6
  * Edgegap token in its Authorization header, and it is used for that request
7
7
  * and discarded. See worker/DECISION.md.
8
8
  */
9
+ import { stripTokenPrefix } from './config.js';
9
10
  const TOKEN_URL = 'https://app.edgegap.com/user-settings?tab=tokens';
10
11
  /**
11
12
  * Edgegap API tokens are UUIDs. The strict form is the real test; the loose
@@ -27,7 +28,8 @@ function looksLikeEdgegapToken(value) {
27
28
  export function extractToken(header) {
28
29
  if (!header)
29
30
  return { token: undefined, problem: 'absent' };
30
- const value = header.replace(/^Bearer\s+/i, '').replace(/^token\s+/i, '').trim();
31
+ // Any run of "Bearer "/"token ", so "token token <uuid>" still works.
32
+ const value = stripTokenPrefix(header);
31
33
  if (!value)
32
34
  return { token: undefined, problem: 'absent' };
33
35
  if (!looksLikeEdgegapToken(value))
package/dist/http.js CHANGED
@@ -91,7 +91,7 @@ function main() {
91
91
  }
92
92
  const { token, problem } = extractToken(req.headers.authorization);
93
93
  const auth = new StaticTokenProvider(token, problem ? unavailableMessage(problem) : undefined);
94
- const server = new McpServer({ name: 'edgegap', version: '0.3.2' }, { instructions: serverInstructions('hosted') });
94
+ const server = new McpServer({ name: 'edgegap', version: '0.3.3' }, { instructions: serverInstructions('hosted') });
95
95
  registerTools(server, new EdgegapClient(config, auth), config, auth);
96
96
  const transport = new StreamableHTTPServerTransport({
97
97
  sessionIdGenerator: undefined,
package/dist/index.js CHANGED
@@ -29,7 +29,7 @@ async function main() {
29
29
  }
30
30
  throw err;
31
31
  }
32
- const server = new McpServer({ name: 'edgegap', version: '0.3.2' }, { instructions: serverInstructions('local') });
32
+ const server = new McpServer({ name: 'edgegap', version: '0.3.3' }, { instructions: serverInstructions('local') });
33
33
  warnIfTokenInArgv();
34
34
  const auth = new TokenProvider(config);
35
35
  auth.attach(server.server);
@@ -83,10 +83,20 @@ export function buildMatchmakerConfig(input) {
83
83
  if (input.team_count * input.min_team_size === 1) {
84
84
  cautions.push('A match of one player starts a server per ticket. Fine for testing, costly in production.');
85
85
  }
86
+ // Browser (WebGL) clients call the matchmaker directly, so their page's
87
+ // origin must be allowed. An origin is scheme + host (+ port), nothing more:
88
+ // a path or trailing slash never matches a browser's Origin header.
89
+ const origins = input.allowed_cors_origins ?? [];
90
+ for (const o of origins) {
91
+ if (!/^https?:\/\/[^/\s?#]+$/.test(o)) {
92
+ problems.push(`allowed_cors_origins entry "${o}" is not an origin. Use scheme and host only, e.g. "https://mygame.example.com" or "http://localhost:8080", with no path or trailing slash.`);
93
+ }
94
+ }
86
95
  const config = {
87
96
  version: input.config_version ?? MATCHMAKER_CONFIG_VERSION,
88
97
  inspect: input.inspect ?? true,
89
98
  max_deployment_retry_count: 3,
99
+ ...(origins.length ? { allowed_cors_origins: origins } : {}),
90
100
  profiles: {
91
101
  [input.profile_name]: {
92
102
  ticket_expiration_period: expiration,
@@ -196,6 +196,9 @@ export function validateServerConfig(input) {
196
196
  err('duplicate-port-name', `Port name "${name}" is used twice. Deployment ports are keyed by name, so one would hide the other.`, 'Give every port a distinct name, e.g. "gameport" and "webport".');
197
197
  }
198
198
  seenNames.add(name);
199
+ if (p.tls_upgrade && proto !== 'WS' && proto !== 'HTTP') {
200
+ err('tls-wrong-protocol', `ports[${idx}] has tls_upgrade on a ${p.protocol} port. Edgegap only offers TLS Upgrade on WS and HTTP ports.`, 'Use protocol "WS" for a WebSocket server, or drop tls_upgrade.');
201
+ }
199
202
  });
200
203
  if (input.netcode) {
201
204
  const expected = NETCODE_PROTOCOL[input.netcode.toLowerCase()];
@@ -208,6 +211,15 @@ export function validateServerConfig(input) {
208
211
  })) {
209
212
  err('netcode-protocol', `${input.netcode} speaks ${expected}, but no configured port uses ${expected}. Clients will time out connecting.`, `Set the game port's protocol to ${expected}.`);
210
213
  }
214
+ else if (expected === 'WS') {
215
+ // WebSocket transports are what browser (WebGL) builds use, and a
216
+ // browser on an https page refuses plain ws://.
217
+ for (const p of ports) {
218
+ if (p.protocol.toUpperCase() === 'WS' && !p.tls_upgrade) {
219
+ warn('ws-no-tls', `Port ${p.port} is WebSocket without tls_upgrade. Browser (WebGL) clients need wss://, which needs Edgegap's TLS Upgrade.`, 'Set tls_upgrade: true on this port in edgegap_create_app_version, unless no client runs in a browser.');
220
+ }
221
+ }
222
+ }
211
223
  }
212
224
  // Cross-check EXPOSE against the version ports. EXPOSE is documentation,
213
225
  // so a mismatch is not fatal on its own, but it is the best signal we have
package/dist/tools.js CHANGED
@@ -74,6 +74,10 @@ export function serverInstructions(mode) {
74
74
  /** 1x1 transparent PNG. The create-app endpoint requires an image and agents
75
75
  * have no sensible one to supply; a placeholder beats a blocked flow. */
76
76
  const PLACEHOLDER_IMAGE = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==';
77
+ /** Port protocols, uppercased. The API accepts "WS" but returns "Websocket". */
78
+ const WS_PROTOCOLS = new Set(['WS', 'WEBSOCKET']);
79
+ /** tls_upgrade is only valid on WebSocket and HTTP ports (per the API spec). */
80
+ const TLS_PROTOCOLS = new Set(['WS', 'WEBSOCKET', 'HTTP']);
77
81
  const TERMINAL_OK = ['READY', 'STATUS_READY'];
78
82
  const TERMINAL_BAD = ['ERROR', 'STATUS_ERROR', 'TERMINATED', 'STATUS_TERMINATED'];
79
83
  function ok(payload, notice) {
@@ -85,9 +89,25 @@ function ok(payload, notice) {
85
89
  function fail(message) {
86
90
  return { content: [{ type: 'text', text: message }], isError: true };
87
91
  }
92
+ /**
93
+ * What a 404 means, per kind of resource. A 404 from Edgegap only says "not
94
+ * found"; which thing is missing, and what to do next, depends on the tool.
95
+ * One generic hint used to be attached to every 404, which sent agents to
96
+ * edgegap_list_apps for stopped deployments and missing registry images.
97
+ */
98
+ const NOT_FOUND = {
99
+ app: 'the application or version name does not exist. Call edgegap_list_apps, then ' +
100
+ 'edgegap_list_app_versions, to find the right names.',
101
+ deployment: 'no deployment with that request_id. It may have stopped and been cleaned up, or the ' +
102
+ 'request_id is wrong. Running deployments are listed by edgegap_list_deployments.',
103
+ logs: 'no logs for this deployment. Container logs only exist while a deployment is running; ' +
104
+ 'once it has stopped they are gone, unless Endpoint Storage was configured on the version ' +
105
+ 'before it ran. If it is still running, check the request_id with edgegap_list_deployments.',
106
+ relay: 'no relay session with that session_id. It may already have been deleted.',
107
+ };
88
108
  /** Wraps a handler so API errors come back as readable, self-correctable text
89
109
  * rather than a protocol-level exception the agent cannot act on. */
90
- function guard(auth, fn) {
110
+ function guard(auth, fn, notFound) {
91
111
  const handled = fn().catch((err) => {
92
112
  if (err instanceof TokenUnavailableError) {
93
113
  // Not a failure to correct — a decision the human made. Say so plainly
@@ -95,7 +115,7 @@ function guard(auth, fn) {
95
115
  return fail(err.message);
96
116
  }
97
117
  if (err instanceof EdgegapApiError) {
98
- const hint = errorHint(err);
118
+ const hint = errorHint(err, notFound);
99
119
  return fail(`${err.message}${hint ? `\n\nLikely cause: ${hint}` : ''}`);
100
120
  }
101
121
  return fail(redact(err.message ?? String(err), auth.current));
@@ -114,7 +134,11 @@ function guard(auth, fn) {
114
134
  };
115
135
  });
116
136
  }
117
- function errorHint(err) {
137
+ /** guard() with the 404 hint first, so it reads at the call site. */
138
+ function guarded(auth, notFound, fn) {
139
+ return guard(auth, fn, notFound);
140
+ }
141
+ function errorHint(err, notFound) {
118
142
  switch (err.status) {
119
143
  case 401:
120
144
  // Deliberately does not promise a re-prompt: the local server asks again
@@ -124,8 +148,16 @@ function errorHint(err) {
124
148
  'different organization. Check it at ' +
125
149
  'https://app.edgegap.com/user-settings?tab=tokens. The token has been ' +
126
150
  'discarded from this session.');
151
+ case 400:
152
+ // The deployment endpoints answer an unknown request_id with 400 ("Bad
153
+ // Request ID provided", or a generic "could not understand" for logs),
154
+ // not 404. Their only input is the request_id, so a 400 means that.
155
+ return notFound === NOT_FOUND.deployment || notFound === NOT_FOUND.logs ? notFound : undefined;
127
156
  case 404:
128
- return 'the application or version name does not exist. Call edgegap_list_apps first.';
157
+ // Only the tool knows what was not found; no hint beats a wrong one.
158
+ return notFound;
159
+ case 429:
160
+ return 'Edgegap rate-limited this token. Wait a few seconds before the next call, and do not retry in a loop.';
129
161
  case 409:
130
162
  return 'a resource with that name already exists. Pick a different name or reuse the existing one.';
131
163
  case 422:
@@ -263,24 +295,36 @@ export function registerTools(server, client, config, auth) {
263
295
  // ---------------------------------------------------------------- 3 ----
264
296
  server.registerTool('edgegap_list_app_versions', {
265
297
  title: 'List versions of an application',
266
- description: 'List the versions under an application, with their container image and resource ' +
267
- 'settings. Use this to find the version name to deploy, or to copy settings from a ' +
268
- 'working version when creating a new one.',
298
+ description: 'List the versions under an application, with their container image, resources, ports ' +
299
+ '(including whether TLS Upgrade is on, which browser/WebGL clients need for wss://) and ' +
300
+ 'whether a registry login is set for pulling the image. Use this to find the version ' +
301
+ 'name to deploy, to check a version is ready before deploying, or to copy settings from ' +
302
+ 'a working version when creating a new one.',
269
303
  inputSchema: {
270
304
  application: z.string().describe('Application name, as returned by edgegap_list_apps.'),
271
305
  },
272
306
  annotations: { readOnlyHint: true, openWorldHint: true },
273
- }, async ({ application }) => guard(auth, async () => {
274
- assertAppAllowed(config, application);
307
+ }, async ({ application }) =>
308
+ // Read-only, so not subject to EDGEGAP_APP_ALLOWLIST: the allowlist
309
+ // limits what the agent can create and deploy into, as documented.
310
+ guarded(auth, NOT_FOUND.app, async () => {
275
311
  const res = await client.listAppVersions(application);
276
312
  const versions = (res.versions ?? []).map((v) => ({
277
313
  name: v.name,
278
314
  active: v.is_active,
279
315
  image: [v.docker_repository, v.docker_image, v.docker_tag].filter(Boolean).join('/'),
316
+ // Whether a login is set, never the login itself: the API returns
317
+ // the registry token in this response.
318
+ registry_credentials_set: Boolean(v.private_username && v.private_token),
280
319
  cpu_units: v.req_cpu,
281
320
  memory_mb: v.req_memory,
282
321
  max_duration_minutes: v.max_duration,
283
- ports: v.ports?.map((p) => `${p.name ?? 'port'}:${p.port}/${p.protocol}`),
322
+ ports: v.ports?.map((p) => ({
323
+ name: p.name,
324
+ port: p.port,
325
+ protocol: p.protocol,
326
+ tls_upgrade: p.tls_upgrade ?? false,
327
+ })),
284
328
  }));
285
329
  return ok({ application, ...pageInfo(res.total_count, versions.length, 1), versions });
286
330
  }));
@@ -319,10 +363,20 @@ export function registerTools(server, client, config, auth) {
319
363
  .boolean()
320
364
  .optional()
321
365
  .describe('Readiness check on this port. Default true.'),
366
+ tls_upgrade: z
367
+ .boolean()
368
+ .optional()
369
+ .describe('Edgegap terminates TLS on this port, so clients connect with wss:// or https://. ' +
370
+ 'Required for browser (WebGL) clients, which cannot use plain ws:// from an https page. ' +
371
+ 'WS and HTTP ports only. Default false.'),
322
372
  }))
323
373
  .min(1)
324
374
  .describe('Ports to expose. At least one is required for players to connect.'),
325
- registry_username: z.string().optional().describe('Registry username, for private images.'),
375
+ registry_username: z
376
+ .string()
377
+ .optional()
378
+ .describe('Registry username. Needed for private images, including images in your own ' +
379
+ 'registry.edgegap.com project: Edgegap pulls with this login, not your API token.'),
326
380
  registry_token: z.string().optional().describe('Registry password or token.'),
327
381
  max_duration_minutes: z
328
382
  .number()
@@ -339,38 +393,72 @@ export function registerTools(server, client, config, auth) {
339
393
  .describe('Environment variables injected into the container.'),
340
394
  },
341
395
  annotations: { destructiveHint: false, idempotentHint: false, openWorldHint: true },
342
- }, async (args) => guard(auth, async () => {
396
+ }, async (args) => guarded(auth, NOT_FOUND.app, async () => {
343
397
  assertAppAllowed(config, args.application);
344
398
  if (args.memory_mb > args.cpu_units * 2) {
345
399
  return fail(`memory_mb (${args.memory_mb}) exceeds twice cpu_units (${args.cpu_units}). ` +
346
400
  `Edgegap rejects this. Either lower memory_mb to ${args.cpu_units * 2} or raise cpu_units.`);
347
401
  }
402
+ const badTls = args.ports.find((p) => p.tls_upgrade && !TLS_PROTOCOLS.has(p.protocol.toUpperCase()));
403
+ if (badTls) {
404
+ return fail(`Port ${badTls.port} is ${badTls.protocol}; tls_upgrade only works on WS and HTTP ports. ` +
405
+ 'Use protocol "WS" for a WebSocket server, or drop tls_upgrade.');
406
+ }
348
407
  const requested = args.max_duration_minutes ?? config.maxDurationCeiling;
349
408
  const capped = Math.min(requested, config.maxDurationCeiling);
350
- const res = await client.createAppVersion(args.application, {
351
- name: args.name,
352
- is_active: true,
353
- req_cpu: args.cpu_units,
354
- req_memory: args.memory_mb,
355
- docker_repository: args.docker_repository,
356
- docker_image: args.docker_image,
357
- docker_tag: args.docker_tag,
358
- private_username: args.registry_username,
359
- private_token: args.registry_token,
360
- verify_image: args.verify_image ?? false,
361
- max_duration: capped,
362
- ports: args.ports.map((p) => ({
363
- port: p.port,
364
- protocol: p.protocol,
365
- name: p.name ?? 'gameport',
366
- to_check: p.to_check ?? true,
367
- })),
368
- envs: args.env?.map((e) => ({ key: e.key, value: e.value, is_hidden: false })),
369
- });
409
+ const hasRegistryLogin = Boolean(args.registry_username && args.registry_token);
410
+ const edgegapRegistry = /(^|\/\/)registry\.edgegap\.com\/?$/.test(args.docker_repository.trim());
411
+ let res;
412
+ try {
413
+ res = await client.createAppVersion(args.application, {
414
+ name: args.name,
415
+ is_active: true,
416
+ req_cpu: args.cpu_units,
417
+ req_memory: args.memory_mb,
418
+ docker_repository: args.docker_repository,
419
+ docker_image: args.docker_image,
420
+ docker_tag: args.docker_tag,
421
+ private_username: args.registry_username,
422
+ private_token: args.registry_token,
423
+ verify_image: args.verify_image ?? false,
424
+ max_duration: capped,
425
+ ports: args.ports.map((p) => ({
426
+ port: p.port,
427
+ protocol: p.protocol,
428
+ name: p.name ?? 'gameport',
429
+ to_check: p.to_check ?? true,
430
+ tls_upgrade: p.tls_upgrade ?? false,
431
+ })),
432
+ envs: args.env?.map((e) => ({ key: e.key, value: e.value, is_hidden: false })),
433
+ });
434
+ }
435
+ catch (err) {
436
+ // verify_image pulls with the version's registry login. Without one
437
+ // — even for the org's own registry.edgegap.com project — Edgegap
438
+ // answers a bare 400 "Unable to login with the given credentials".
439
+ if (err instanceof EdgegapApiError && err.status === 400 && /login|credential/i.test(err.apiMessage)) {
440
+ return fail(registryLoginNeeded(args.docker_repository, hasRegistryLogin));
441
+ }
442
+ throw err;
443
+ }
444
+ const notes = [];
445
+ if (edgegapRegistry && !hasRegistryLogin) {
446
+ notes.push('No registry login was set. Edgegap pulls images from registry.edgegap.com with the ' +
447
+ 'version\'s registry login, not your API token, so deployments of this version will ' +
448
+ 'likely fail to pull (424) until the developer adds the Container Registry username ' +
449
+ 'and token to this version in the dashboard.');
450
+ }
451
+ for (const p of args.ports) {
452
+ if (WS_PROTOCOLS.has(p.protocol.toUpperCase()) && !p.tls_upgrade) {
453
+ notes.push(`Port ${p.port} is WebSocket without tls_upgrade. If clients run in a browser (WebGL), ` +
454
+ 'they need wss://: create the version with tls_upgrade: true on this port.');
455
+ }
456
+ }
370
457
  return ok({
371
458
  created: `${args.application}/${res.version?.name ?? args.name}`,
372
459
  max_duration_minutes: capped,
373
460
  capped_by_server: capped < requested ? config.maxDurationCeiling : undefined,
461
+ notes: notes.length ? notes : undefined,
374
462
  next_step: 'Call edgegap_deploy to start an instance.',
375
463
  });
376
464
  }));
@@ -400,7 +488,7 @@ export function registerTools(server, client, config, auth) {
400
488
  memory_mb: z.number().int().min(256).optional().describe('Override the version memory.'),
401
489
  },
402
490
  annotations: { destructiveHint: false, idempotentHint: false, openWorldHint: true },
403
- }, async (args) => guard(auth, async () => {
491
+ }, async (args) => guarded(auth, NOT_FOUND.app, async () => {
404
492
  assertAppAllowed(config, args.application);
405
493
  const users = buildUsers(args.users);
406
494
  if (users.length === 0) {
@@ -441,7 +529,7 @@ export function registerTools(server, client, config, auth) {
441
529
  request_id: z.string().describe('The request_id returned by edgegap_deploy.'),
442
530
  },
443
531
  annotations: { readOnlyHint: true, openWorldHint: true },
444
- }, async ({ request_id }) => guard(auth, async () => {
532
+ }, async ({ request_id }) => guarded(auth, NOT_FOUND.deployment, async () => {
445
533
  const d = await client.getDeployment(request_id);
446
534
  return ok(compactDeployment(d));
447
535
  }));
@@ -463,7 +551,7 @@ export function registerTools(server, client, config, auth) {
463
551
  .describe('How long to wait before giving up. Default 180.'),
464
552
  },
465
553
  annotations: { readOnlyHint: true, idempotentHint: true, openWorldHint: true },
466
- }, async ({ request_id, timeout_seconds }) => guard(auth, async () => {
554
+ }, async ({ request_id, timeout_seconds }) => guarded(auth, NOT_FOUND.deployment, async () => {
467
555
  const budgetMs = (timeout_seconds ?? 180) * 1000;
468
556
  const startedAt = Date.now();
469
557
  let intervalMs = 2000;
@@ -554,7 +642,7 @@ export function registerTools(server, client, config, auth) {
554
642
  request_id: z.string().describe('The request_id of the deployment to stop.'),
555
643
  },
556
644
  annotations: { destructiveHint: true, idempotentHint: true, openWorldHint: true },
557
- }, async ({ request_id }) => guard(auth, async () => {
645
+ }, async ({ request_id }) => guarded(auth, NOT_FOUND.deployment, async () => {
558
646
  const res = await client.stopDeployment(request_id);
559
647
  return ok({ request_id, result: res.message ?? 'stop requested' });
560
648
  }));
@@ -577,7 +665,7 @@ export function registerTools(server, client, config, auth) {
577
665
  .describe('Truncate logs to this length, keeping the tail. Default 8000.'),
578
666
  },
579
667
  annotations: { readOnlyHint: true, openWorldHint: true },
580
- }, async ({ request_id, max_characters }) => guard(auth, async () => {
668
+ }, async ({ request_id, max_characters }) => guarded(auth, NOT_FOUND.logs, async () => {
581
669
  const res = await client.getDeploymentLogs(request_id);
582
670
  const cap = max_characters ?? 8000;
583
671
  const tail = (s) => !s ? undefined : s.length > cap ? `...[truncated]...\n${s.slice(-cap)}` : s;
@@ -624,6 +712,7 @@ export function registerTools(server, client, config, auth) {
624
712
  port: z.number().int().min(1).max(59999),
625
713
  protocol: z.enum(PROTOCOLS),
626
714
  name: z.string().optional(),
715
+ tls_upgrade: z.boolean().optional().describe('TLS Upgrade (wss/https) on a WS or HTTP port, for browser clients.'),
627
716
  }))
628
717
  .optional()
629
718
  .describe('Ports the server listens on. Default: 7777, with the protocol the netcode uses (UDP if unknown).'),
@@ -708,6 +797,7 @@ export function registerTools(server, client, config, auth) {
708
797
  port: z.number().int(),
709
798
  protocol: z.string(),
710
799
  name: z.string().optional(),
800
+ tls_upgrade: z.boolean().optional().describe('TLS Upgrade (wss/https) on a WS or HTTP port, for browser clients.'),
711
801
  }))
712
802
  .optional()
713
803
  .describe('Ports you plan to pass to edgegap_create_app_version.'),
@@ -972,7 +1062,7 @@ export function registerTools(server, client, config, auth) {
972
1062
  'waits for readiness; use this to re-read a session or one created with wait_until_ready false.',
973
1063
  inputSchema: { session_id: z.string().describe('Returned by edgegap_create_relay_session.') },
974
1064
  annotations: { readOnlyHint: true, openWorldHint: true },
975
- }, async ({ session_id }) => guard(auth, async () => ok(compactRelay(await client.getRelaySession(session_id)))));
1065
+ }, async ({ session_id }) => guarded(auth, NOT_FOUND.relay, async () => ok(compactRelay(await client.getRelaySession(session_id)))));
976
1066
  if (mutating) {
977
1067
  // ------------------------------------------------------------- 16 ----
978
1068
  server.registerTool('edgegap_authorize_relay_user', {
@@ -984,7 +1074,7 @@ export function registerTools(server, client, config, auth) {
984
1074
  user_ip: z.string().min(3).describe('Public IP of the joining player.'),
985
1075
  },
986
1076
  annotations: { destructiveHint: false, idempotentHint: true, openWorldHint: true },
987
- }, async ({ session_id, user_ip }) => guard(auth, async () => {
1077
+ }, async ({ session_id, user_ip }) => guarded(auth, NOT_FOUND.relay, async () => {
988
1078
  const res = await client.authorizeRelayUser({ session_id, user_ip });
989
1079
  return ok({
990
1080
  session_id: res.session_id,
@@ -1000,7 +1090,7 @@ export function registerTools(server, client, config, auth) {
1000
1090
  'session you created for testing before ending your task.',
1001
1091
  inputSchema: { session_id: z.string() },
1002
1092
  annotations: { destructiveHint: true, idempotentHint: true, openWorldHint: true },
1003
- }, async ({ session_id }) => guard(auth, async () => {
1093
+ }, async ({ session_id }) => guarded(auth, NOT_FOUND.relay, async () => {
1004
1094
  await client.deleteRelaySession(session_id);
1005
1095
  return ok({ session_id, result: 'deleted' });
1006
1096
  }));
@@ -1044,9 +1134,15 @@ export function registerTools(server, client, config, auth) {
1044
1134
  ticket_expiration: z.string().optional().describe('Default "5m".'),
1045
1135
  inspect: z.boolean().optional().describe('Expose the inspection API for debugging. Default true; turn off for production.'),
1046
1136
  verify_version: z.boolean().optional().describe('Look up the application version first. Default true.'),
1137
+ allowed_cors_origins: z
1138
+ .array(z.string())
1139
+ .optional()
1140
+ .describe('Origins of web pages allowed to call the matchmaker, e.g. ["https://mygame.example.com", ' +
1141
+ '"http://localhost:8080"]. Required when game clients run in a browser (WebGL): browsers ' +
1142
+ 'block matchmaker calls from any origin not listed. Scheme and host only, no path.'),
1047
1143
  },
1048
1144
  annotations: { readOnlyHint: true, idempotentHint: true, openWorldHint: true },
1049
- }, async (args) => guard(auth, async () => {
1145
+ }, async (args) => guarded(auth, NOT_FOUND.app, async () => {
1050
1146
  assertAppAllowed(config, args.application);
1051
1147
  const { config: mmConfig, problems, cautions } = buildMatchmakerConfig(args);
1052
1148
  if (args.verify_version !== false) {
@@ -1087,6 +1183,9 @@ export function registerTools(server, client, config, auth) {
1087
1183
  'The dashboard then shows the matchmaker API URL and auth token. Game clients call POST {api_url}/tickets ' +
1088
1184
  `with header "Authorization: <auth token>" and profile "${args.profile_name}", then poll GET {api_url}/memberships/{id} until it returns the server address.`,
1089
1185
  'That auth token is safe to ship in game clients: it grants no access to the Edgegap API.',
1186
+ args.allowed_cors_origins?.length
1187
+ ? `Browser clients are allowed from: ${args.allowed_cors_origins.join(', ')}. Add any other origin the game is served from (each staging or production URL) before uploading.`
1188
+ : 'If game clients run in a browser (WebGL), set allowed_cors_origins to the origin of every page that serves the game, including http://localhost:<port> for local testing, or browsers will block the matchmaker calls.',
1090
1189
  ],
1091
1190
  });
1092
1191
  }));
@@ -1117,6 +1216,26 @@ function registryCredentialsUnavailable(imageName, tag) {
1117
1216
  'Or push to any other registry Edgegap can pull from (Docker Hub, GHCR, ECR, GCR, GitLab) ' +
1118
1217
  'and pass its registry_username/registry_token to edgegap_create_app_version.');
1119
1218
  }
1219
+ /**
1220
+ * What edgegap_create_app_version says when Edgegap could not log in to the
1221
+ * registry to verify the image. The agent should not be handed the registry
1222
+ * login just to get past this, so the dashboard route comes first.
1223
+ */
1224
+ function registryLoginNeeded(repository, hadLogin) {
1225
+ return (`Edgegap could not log in to ${repository} to verify the image, so the version was not ` +
1226
+ 'created. ' +
1227
+ (hadLogin
1228
+ ? 'The registry_username/registry_token given were rejected: check them.'
1229
+ : 'Edgegap pulls images with a registry login set on the version, not your API token — ' +
1230
+ 'this applies to your own registry.edgegap.com project too.') +
1231
+ '\n\nOptions:\n' +
1232
+ '1. Create the version again with verify_image false, then have the developer open it in ' +
1233
+ `the dashboard (${DASHBOARD_URL}) and add the registry username and token (for ` +
1234
+ 'registry.edgegap.com, the ones on the Container Registry page). Deployments fail to pull ' +
1235
+ 'until they do.\n' +
1236
+ '2. If the developer chooses to give them to you, pass registry_username and registry_token. ' +
1237
+ 'They are registry-scoped, not the org API token. Do not write them into files.');
1238
+ }
1120
1239
  /** Trims a relay session down to what a game client integration needs. */
1121
1240
  function compactRelay(s) {
1122
1241
  return {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@edgegap/mcp",
3
3
  "mcpName": "dev.edgegap/mcp",
4
- "version": "0.3.2",
4
+ "version": "0.3.3",
5
5
  "description": "Check, push, and deploy game servers on Edgegap from your coding agent, with relays for P2P games. Runs locally; your API token never leaves your machine.",
6
6
  "scripts": {
7
7
  "prebuild": "rm -rf dist",
@@ -35,13 +35,13 @@
35
35
  },
36
36
  "dependencies": {
37
37
  "@modelcontextprotocol/sdk": "^1.30.0",
38
- "@modelcontextprotocol/server": "^2.0.0",
39
- "agents": "^0.23.0",
40
38
  "zod": "^4.6.2"
41
39
  },
42
40
  "devDependencies": {
43
41
  "@cloudflare/workers-types": "^5.20260911.1",
42
+ "@modelcontextprotocol/server": "^2.0.0",
44
43
  "@types/node": "^22.20.2",
44
+ "agents": "^0.23.0",
45
45
  "typescript": "^7.0.2",
46
46
  "wrangler": "^4.131.1"
47
47
  },