@edgegap/mcp 0.3.3 โ†’ 0.4.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 CHANGED
@@ -157,7 +157,7 @@ To keep your API token on your own machine, run the server locally instead. Leav
157
157
  }
158
158
  ```
159
159
 
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`.
160
+ Needs Node 18+. Pin a version in production (`@edgegap/mcp@0.4.0`) rather than floating on latest. Registered in the official MCP registry as `dev.edgegap/mcp`.
161
161
 
162
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`:
163
163
 
@@ -171,7 +171,11 @@ The local server can also limit what an agent can do. These variables have no ef
171
171
 
172
172
  ## ๐Ÿงฐ Tools
173
173
 
174
- Your agent picks the right tool from your request. You don't need to name them, but knowing what's available helps you ask. Tools marked โ— change something in your account and are hidden when `EDGEGAP_READ_ONLY=1`.
174
+ Your agent picks the right tool from your request. You don't need to name them, but knowing what's available helps you ask. Tools marked โ— change something in your account, accept `dry_run`, and are hidden when `EDGEGAP_READ_ONLY=1`.
175
+
176
+ | Tool | What it does |
177
+ | --- | --- |
178
+ | `edgegap_context` | Shows which API this server talks to, its version, local or hosted, and the guardrails in force. No API call; never shows the token. |
175
179
 
176
180
  ### Before Your First Deployment
177
181
 
@@ -190,12 +194,12 @@ Your agent picks the right tool from your request. You don't need to name them,
190
194
  | `edgegap_create_app` โ— | Creates an application. |
191
195
  | `edgegap_list_app_versions` | Lists versions with their image, resources, ports (with TLS Upgrade), and whether a registry login is set. |
192
196
  | `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://`. |
193
- | `edgegap_deploy` โ— | Deploys an authoritative dedicated server close to your players. |
197
+ | `edgegap_deploy` โ— | Deploys an authoritative dedicated server close to your players. Always tagged `edgegap-mcp`, and reports when Edgegap will stop it. |
194
198
  | `edgegap_wait_for_deployment` | Waits until the server is ready and returns the connection address. |
195
199
  | `edgegap_get_deployment` | Reads a deployment's status. |
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). |
200
+ | `edgegap_list_deployments` | Lists running deployments, filtered by application, version, status, tags and more, and sorted by age. Finds servers left running; `only_agent_deployments: true` lists every one an agent started. See [Filter Deployments](https://docs.edgegap.com/learn/orchestration/deployments#filter-deployments). |
197
201
  | `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. |
198
- | `edgegap_stop_deployment` โ— | Stops one deployment. |
202
+ | `edgegap_stop_deployment` โ— | Stops one deployment, by its exact request ID. No bulk stop. |
199
203
 
200
204
  ### Matchmaking
201
205
 
@@ -227,6 +231,22 @@ A relay is not a game server: it forwards traffic while one player's game hosts
227
231
  * *"My deployment failed. Read the logs and tell me why."*
228
232
  * *"My game uses host-client networking. Set up an Edgegap relay for two players."*
229
233
 
234
+ ## ๐Ÿ›ก๏ธ Guardrails
235
+
236
+ Your API token can do anything in your organization, so the server adds its own limits around what an agent does with it. They apply in both the local server and the hosted endpoint.
237
+
238
+ | Guardrail | What it does |
239
+ | --- | --- |
240
+ | Dry run | Every tool that changes something takes `dry_run: true`: it returns the exact method, host, path and body, with the token, registry tokens and env values masked, and sends nothing. Local checks still run. |
241
+ | No token in containers | A deploy or version is refused, with nothing sent, if your API token appears in an env var name or value, a tag, or a webhook URL. Env values are never echoed back. |
242
+ | Agent tag | Every deployment gets the `edgegap-mcp` tag, even when the agent passes its own tags. `edgegap_list_deployments` with `only_agent_deployments: true` finds them all. |
243
+ | Auto-stop | Every deploy reports when Edgegap will stop it: the version's `max_duration`, capped at `EDGEGAP_MAX_DURATION_MINUTES` (default 60) for versions the agent creates. Edgegap has no per-deployment time limit, so a version made elsewhere can run up to its own limit (1440 minutes by default); the result warns when it is over an hour or unlimited. |
244
+ | Strict stop | `edgegap_stop_deployment` stops one deployment by its exact request ID. Empty IDs, wildcards and lists are refused. There is no bulk stop. |
245
+ | Host on every result | Every result starts with the API host, e.g. `[api.edgegap.com]`, or `[custom ยท host]` when `EDGEGAP_BASE_URL` points elsewhere. A base URL naming `api.edgegap.com` must be exactly `https://api.edgegap.com`, or the server refuses to start. |
246
+ | Redaction | The token is stripped from every error before it reaches the agent. |
247
+
248
+ The server identifies itself with `User-Agent: edgegap-mcp/<version> (<MCP client name>)` on every API call, and sends nothing else about you or your machine.
249
+
230
250
  ## ๐Ÿšจ Troubleshooting
231
251
 
232
252
  Review common error codes and learn how to unlock your integration.
package/dist/client.js CHANGED
@@ -6,6 +6,29 @@
6
6
  * picking the wrong one. This wraps only what the golden path needs.
7
7
  */
8
8
  import { redact } from './config.js';
9
+ import { VERSION } from './version.js';
10
+ const SECRET_KEYS = /^(private_token|registry_token|token|password|secret|api_key)$/i;
11
+ /**
12
+ * Deep copy of a request body with secrets masked: registry tokens and the
13
+ * like by key name, every environment variable value (we never echo those),
14
+ * and the API token anywhere it appears.
15
+ */
16
+ export function maskSecrets(value, apiToken) {
17
+ if (typeof value === 'string') {
18
+ return apiToken && value.includes(apiToken) ? value.split(apiToken).join('***') : value;
19
+ }
20
+ if (Array.isArray(value))
21
+ return value.map((v) => maskSecrets(v, apiToken));
22
+ if (!value || typeof value !== 'object')
23
+ return value;
24
+ const obj = value;
25
+ const isEnvVar = typeof obj.key === 'string' && 'value' in obj;
26
+ const out = {};
27
+ for (const [k, v] of Object.entries(obj)) {
28
+ out[k] = (SECRET_KEYS.test(k) && v != null) || (isEnvVar && k === 'value') ? '***' : maskSecrets(v, apiToken);
29
+ }
30
+ return out;
31
+ }
9
32
  export class EdgegapApiError extends Error {
10
33
  status;
11
34
  apiMessage;
@@ -21,9 +44,29 @@ export class EdgegapApiError extends Error {
21
44
  export class EdgegapClient {
22
45
  config;
23
46
  auth;
24
- constructor(config, auth) {
47
+ options;
48
+ constructor(config, auth, options = {}) {
25
49
  this.config = config;
26
50
  this.auth = auth;
51
+ this.options = options;
52
+ }
53
+ /**
54
+ * A client that records requests instead of sending them, for dry runs.
55
+ * Tools call it exactly as they call the real one, so the request shown is
56
+ * the request that would be sent โ€” not a second copy of the path logic.
57
+ */
58
+ dryRun() {
59
+ const requests = [];
60
+ const client = new EdgegapClient(this.config, this.auth, {
61
+ ...this.options,
62
+ recorder: (r) => requests.push(r),
63
+ });
64
+ return { client, requests };
65
+ }
66
+ /** "edgegap-mcp/<version> (<client>)". Nothing else identifying is sent. */
67
+ userAgent() {
68
+ const client = this.options.clientName?.();
69
+ return `edgegap-mcp/${VERSION}${client ? ` (${client.replace(/[^\w .\-/]/g, '')})` : ''}`;
27
70
  }
28
71
  async request(method, version, path, options = {}) {
29
72
  const base = version === 'v2' ? this.config.baseUrlV2 : this.config.baseUrlV1;
@@ -33,6 +76,18 @@ export class EdgegapClient {
33
76
  url.searchParams.set(key, String(value));
34
77
  }
35
78
  }
79
+ if (this.options.recorder) {
80
+ // Dry run: record and stop. Never ask for or read the token here โ€” the
81
+ // header is shown masked, and a dry run must not trigger the prompt.
82
+ this.options.recorder({
83
+ method,
84
+ host: url.host,
85
+ path: url.pathname + url.search,
86
+ headers: { Authorization: 'token ***', 'Content-Type': 'application/json', 'User-Agent': this.userAgent() },
87
+ ...(options.body === undefined ? {} : { body: maskSecrets(options.body, this.auth.current) }),
88
+ });
89
+ return {};
90
+ }
36
91
  // Resolved per request rather than at construction: the developer may not
37
92
  // have been asked for a token yet.
38
93
  const token = await this.auth.get();
@@ -47,7 +102,7 @@ export class EdgegapClient {
47
102
  Authorization: `token ${token}`,
48
103
  'Content-Type': 'application/json',
49
104
  Accept: 'application/json',
50
- 'User-Agent': 'edgegap-mcp',
105
+ 'User-Agent': this.userAgent(),
51
106
  },
52
107
  body: options.body === undefined ? undefined : JSON.stringify(options.body),
53
108
  signal: controller.signal,
@@ -92,6 +147,10 @@ export class EdgegapClient {
92
147
  listAppVersions(appName) {
93
148
  return this.request('GET', 'v1', `/v1/app/${encodeURIComponent(appName)}/versions`);
94
149
  }
150
+ /** One version. The response is the version itself, not wrapped. */
151
+ getAppVersion(appName, versionName) {
152
+ return this.request('GET', 'v1', `/v1/app/${encodeURIComponent(appName)}/version/${encodeURIComponent(versionName)}`);
153
+ }
95
154
  createAppVersion(appName, body) {
96
155
  return this.request('POST', 'v1', `/v1/app/${encodeURIComponent(appName)}/version`, { body });
97
156
  }
package/dist/config.js CHANGED
@@ -4,6 +4,42 @@
4
4
  * Everything here exists to keep the blast radius of an autonomous agent small.
5
5
  * The Edgegap API token is org-wide, so the server layers its own limits on top.
6
6
  */
7
+ /** Edgegap's production API. A base URL naming this host must be exactly it. */
8
+ export const DEFAULT_API_HOST = 'api.edgegap.com';
9
+ /**
10
+ * Validates EDGEGAP_BASE_URL and returns it without a trailing slash.
11
+ *
12
+ * The token travels in a header to whatever host this names, so a typo or a
13
+ * plain-http URL is a credential leak, not a misconfiguration. A URL naming
14
+ * Edgegap's own host must be https; anything else is labelled "custom" on
15
+ * every tool result (see hostLabel) so it cannot go unnoticed.
16
+ */
17
+ export function parseBaseUrl(raw) {
18
+ const value = raw?.trim() || `https://${DEFAULT_API_HOST}`;
19
+ let url;
20
+ try {
21
+ url = new URL(value);
22
+ }
23
+ catch {
24
+ throw new ConfigError(`EDGEGAP_BASE_URL "${value}" is not a valid URL.`);
25
+ }
26
+ if (url.protocol !== 'https:' && url.protocol !== 'http:') {
27
+ throw new ConfigError(`EDGEGAP_BASE_URL must be an http(s) URL, not ${url.protocol}`);
28
+ }
29
+ if (url.hostname === DEFAULT_API_HOST && (url.protocol !== 'https:' || url.port !== '')) {
30
+ throw new ConfigError(`EDGEGAP_BASE_URL names ${DEFAULT_API_HOST} but is not https://${DEFAULT_API_HOST}. ` +
31
+ 'The API token would be sent unencrypted or to the wrong port. Use https.');
32
+ }
33
+ if (url.username || url.password) {
34
+ throw new ConfigError('EDGEGAP_BASE_URL must not contain a username or password.');
35
+ }
36
+ return value.replace(/\/+$/, '');
37
+ }
38
+ /** "api.edgegap.com", or "custom ยท <host>" when EDGEGAP_BASE_URL points elsewhere. */
39
+ export function hostLabel(config) {
40
+ const host = new URL(config.baseUrlV1).host;
41
+ return host === DEFAULT_API_HOST ? host : `custom ยท ${host}`;
42
+ }
7
43
  export class ConfigError extends Error {
8
44
  }
9
45
  function parseList(raw) {
@@ -30,8 +66,9 @@ export function loadConfig(env = process.env) {
30
66
  const envToken = raw ? stripTokenPrefix(raw) || undefined : undefined;
31
67
  return {
32
68
  envToken,
33
- baseUrlV1: env.EDGEGAP_BASE_URL?.trim() || 'https://api.edgegap.com',
34
- baseUrlV2: (env.EDGEGAP_BASE_URL?.trim() || 'https://api.edgegap.com') + '/v2',
69
+ baseUrlV1: parseBaseUrl(env.EDGEGAP_BASE_URL),
70
+ baseUrlV2: parseBaseUrl(env.EDGEGAP_BASE_URL) + '/v2',
71
+ transport: 'local',
35
72
  readOnly: env.EDGEGAP_READ_ONLY === '1' || env.EDGEGAP_READ_ONLY === 'true',
36
73
  appAllowlist: parseList(env.EDGEGAP_APP_ALLOWLIST),
37
74
  maxDurationCeiling: parseIntEnv(env.EDGEGAP_MAX_DURATION_MINUTES, 60),
package/dist/http.js CHANGED
@@ -16,6 +16,7 @@ import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/
16
16
  import { loadConfig, ConfigError } from './config.js';
17
17
  import { EdgegapClient } from './client.js';
18
18
  import { registerTools, serverInstructions } from './tools.js';
19
+ import { VERSION } from './version.js';
19
20
  import { StaticTokenProvider } from './auth.js';
20
21
  import { extractToken, unavailableMessage } from './hosted.js';
21
22
  const MAX_BODY_BYTES = 1_000_000;
@@ -52,7 +53,7 @@ function main() {
52
53
  let config;
53
54
  try {
54
55
  // No ambient credential, by design: every token comes from the request.
55
- config = { ...loadConfig(), envToken: undefined };
56
+ config = { ...loadConfig(), envToken: undefined, transport: 'hosted' };
56
57
  }
57
58
  catch (err) {
58
59
  if (err instanceof ConfigError) {
@@ -91,8 +92,11 @@ function main() {
91
92
  }
92
93
  const { token, problem } = extractToken(req.headers.authorization);
93
94
  const auth = new StaticTokenProvider(token, problem ? unavailableMessage(problem) : undefined);
94
- const server = new McpServer({ name: 'edgegap', version: '0.3.3' }, { instructions: serverInstructions('hosted') });
95
- registerTools(server, new EdgegapClient(config, auth), config, auth);
95
+ const server = new McpServer({ name: 'edgegap', version: VERSION }, { instructions: serverInstructions('hosted') });
96
+ const client = new EdgegapClient(config, auth, {
97
+ clientName: () => server.server.getClientVersion()?.name,
98
+ });
99
+ registerTools(server, client, config, auth);
96
100
  const transport = new StreamableHTTPServerTransport({
97
101
  sessionIdGenerator: undefined,
98
102
  enableJsonResponse: true,
package/dist/index.js CHANGED
@@ -15,6 +15,7 @@ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
15
15
  import { loadConfig, ConfigError } from './config.js';
16
16
  import { EdgegapClient } from './client.js';
17
17
  import { registerTools, serverInstructions } from './tools.js';
18
+ import { VERSION } from './version.js';
18
19
  import { TokenProvider, warnIfTokenInArgv } from './auth.js';
19
20
  async function main() {
20
21
  let config;
@@ -29,12 +30,15 @@ async function main() {
29
30
  }
30
31
  throw err;
31
32
  }
32
- const server = new McpServer({ name: 'edgegap', version: '0.3.3' }, { instructions: serverInstructions('local') });
33
+ const server = new McpServer({ name: 'edgegap', version: VERSION }, { instructions: serverInstructions('local') });
33
34
  warnIfTokenInArgv();
34
35
  const auth = new TokenProvider(config);
35
36
  auth.attach(server.server);
36
37
  auth.installExitHandlers();
37
- registerTools(server, new EdgegapClient(config, auth), config, auth);
38
+ const client = new EdgegapClient(config, auth, {
39
+ clientName: () => server.server.getClientVersion()?.name,
40
+ });
41
+ registerTools(server, client, config, auth);
38
42
  if (!config.envToken) {
39
43
  process.stderr.write('[edgegap-mcp] no token configured: you will be asked for one at first ' +
40
44
  'use. It stays in memory on this machine and is never written to disk ' +
package/dist/tools.js CHANGED
@@ -9,7 +9,8 @@
9
9
  */
10
10
  import { z } from 'zod';
11
11
  import { EdgegapApiError } from './client.js';
12
- import { assertAppAllowed, redact } from './config.js';
12
+ import { assertAppAllowed, redact, hostLabel } from './config.js';
13
+ import { VERSION } from './version.js';
13
14
  import { TokenUnavailableError } from './auth.js';
14
15
  import { validateServerConfig, PROTOCOLS, NETCODE_NAMES, } from './serverconfig.js';
15
16
  import { generateDockerfile, DockerfileInputError } from './dockerfile.js';
@@ -61,9 +62,13 @@ export function serverInstructions(mode) {
61
62
  '8. edgegap_stop_deployment when finished\n' +
62
63
  'To match players into those servers, edgegap_build_matchmaker_config produces the ' +
63
64
  'config the developer uploads in the dashboard.\n\n' +
64
- 'Deployments and relay sessions cost money while running. Tag test deployments, and ' +
65
- 'stop deployments and delete relay sessions you created before ending the task. If a ' +
65
+ 'Deployments and relay sessions cost money while running. Stop deployments and delete ' +
66
+ 'relay sessions you created before ending the task; edgegap_list_deployments with ' +
67
+ `only_agent_deployments: true lists every deployment tagged "${AGENT_TAG}". If a ` +
66
68
  'deployment errors, read the container logs before redeploying.\n\n' +
69
+ 'Guardrails: edgegap_context shows which API and limits this session has. Every tool that ' +
70
+ 'changes something takes dry_run: true to show the exact request and send nothing; use it ' +
71
+ 'when unsure. Never put the API token in env vars, tags or URLs: such calls are refused.\n\n' +
67
72
  credentials +
68
73
  'That token is org-wide and cannot be scoped by Edgegap, so it authorises far more than ' +
69
74
  'any single task needs. Treat it as a supervised credential: do not use it for work the ' +
@@ -240,10 +245,153 @@ function buildUsers(input) {
240
245
  }
241
246
  return users;
242
247
  }
248
+ // ================================================================ guardrails ====
249
+ /**
250
+ * Added to every deployment this server starts, whatever tags the caller
251
+ * passes, so agent deployments can always be found and cleaned up:
252
+ * edgegap_list_deployments with only_agent_deployments: true.
253
+ */
254
+ export const AGENT_TAG = 'edgegap-mcp';
255
+ /**
256
+ * A single Edgegap request_id ("61b1be8f54d9"). Anything else โ€” empty, a
257
+ * wildcard, a list, whitespace โ€” is refused before a stop is sent, so a stop
258
+ * can only ever hit the one deployment it names.
259
+ */
260
+ const REQUEST_ID = /^[A-Za-z0-9]{6,64}$/;
261
+ /** A single relay session_id, e.g. "0724828881e2-S". */
262
+ const SESSION_ID = /^[A-Za-z0-9][A-Za-z0-9-]{4,63}$/;
263
+ function checkRequestId(id) {
264
+ if (REQUEST_ID.test(id))
265
+ return undefined;
266
+ return fail(`"${id.slice(0, 80)}" is not a single request_id. Pass exactly one request_id, e.g. "61b1be8f54d9", ` +
267
+ 'as returned by edgegap_deploy or edgegap_list_deployments. Wildcards, lists and empty IDs ' +
268
+ 'are refused, and there is no bulk stop.');
269
+ }
270
+ /** The dry_run parameter every write tool takes. */
271
+ const dryRunParam = z
272
+ .boolean()
273
+ .optional()
274
+ .describe('Show the exact request (method, host, path, body) with secrets masked, and send nothing. ' +
275
+ 'Local checks still run. Use it to confirm a billable or destructive call before making it.');
276
+ function dryRunResult(requests, notes = []) {
277
+ return ok({
278
+ dry_run: true,
279
+ sent: false,
280
+ requests,
281
+ notes: notes.length ? notes : undefined,
282
+ next_step: 'Nothing was sent. Call again without dry_run to do it.',
283
+ });
284
+ }
285
+ /**
286
+ * Refuses to put the server's own API token into a container or a URL.
287
+ *
288
+ * Env vars, tags and webhook URLs end up in places the agent and other people
289
+ * can read โ€” container environments, the dashboard, third-party endpoints. An
290
+ * agent that "helpfully" passes the token along (say, so the game server can
291
+ * call the API) would hand an org-wide credential to all of them. Nothing is
292
+ * sent when this fires, and the matching value is never echoed.
293
+ *
294
+ * Returns undefined when clean. In a dry run the token is only checked if this
295
+ * session already holds one: a dry run must not trigger the token prompt.
296
+ */
297
+ async function tokenLeak(auth, dryRun, fields) {
298
+ const token = dryRun ? auth.current : await auth.get();
299
+ if (!token)
300
+ return undefined;
301
+ const needles = [token, token.replace(/-/g, '')].filter((n) => n.length >= 16);
302
+ const hit = fields.find(([, v]) => v && needles.some((n) => v.toLowerCase().includes(n.toLowerCase())));
303
+ if (!hit)
304
+ return undefined;
305
+ return fail(`Refused: ${hit[0]} contains this server's Edgegap API token. Nothing was sent. ` +
306
+ 'The token is organization-wide; putting it in a container, tag or URL exposes it to ' +
307
+ 'everything that can read those. If the game server needs to call Edgegap, give it a ' +
308
+ 'separate, purpose-made credential, and never this one.');
309
+ }
310
+ /**
311
+ * How long a new deployment can run before Edgegap stops it, from the
312
+ * version's max_duration. The API takes no per-deployment limit, so this is
313
+ * the only bound there is, and the agent should hear it on every deploy.
314
+ */
315
+ function autoStop(maxDuration) {
316
+ if (maxDuration === undefined || maxDuration === null) {
317
+ return { auto_stop: 'unknown: the version did not report max_duration. Stop this deployment when done.' };
318
+ }
319
+ if (maxDuration <= 0) {
320
+ return {
321
+ auto_stop: 'none',
322
+ warning: 'This version has no max_duration, so the deployment runs and bills until it is stopped. ' +
323
+ 'Stop it with edgegap_stop_deployment when done, or give the version a max_duration.',
324
+ };
325
+ }
326
+ const hours = maxDuration >= 120 ? ` (${Math.round(maxDuration / 60)} hours)` : '';
327
+ return {
328
+ auto_stop_after_minutes: maxDuration,
329
+ ...(maxDuration > 60
330
+ ? {
331
+ warning: `Edgegap stops this deployment after ${maxDuration} minutes${hours}, the version's ` +
332
+ 'max_duration. Stop it yourself when done testing; versions created with ' +
333
+ 'edgegap_create_app_version are capped by EDGEGAP_MAX_DURATION_MINUTES instead.',
334
+ }
335
+ : {}),
336
+ };
337
+ }
338
+ /** Prepends "[api.edgegap.com]" (or "[custom ยท host]") to a tool result. */
339
+ function withHost(result, label) {
340
+ return { ...result, content: [{ type: 'text', text: `[${label}]` }, ...result.content] };
341
+ }
243
342
  export function registerTools(server, client, config, auth) {
244
343
  const mutating = !config.readOnly;
344
+ // Every result names the API host it came from, first, so a session pointed
345
+ // at a custom EDGEGAP_BASE_URL can never be mistaken for production.
346
+ const label = hostLabel(config);
347
+ const tool = ((name, def, cb) => server.registerTool(name, def, (async (...a) => withHost(await cb(...a), label))));
348
+ // ---------------------------------------------------------------- 0 ----
349
+ // No token, no network: describes this server's own configuration, so an
350
+ // agent can check where it is pointed and what is allowed before acting.
351
+ tool('edgegap_context', {
352
+ title: 'Show this Edgegap MCP server\'s configuration',
353
+ description: 'Report which Edgegap API this server talks to, its version, whether it is the local or ' +
354
+ 'hosted server, and the guardrails in force: read-only mode, application allowlist, ' +
355
+ 'max_duration ceiling, the tag forced onto every deployment, and which tools support ' +
356
+ 'dry_run. Call it first when unsure what this session is allowed to do, or before ' +
357
+ 'anything billable. Makes no API call and never shows the token.',
358
+ inputSchema: {},
359
+ annotations: { readOnlyHint: true, idempotentHint: true, openWorldHint: false },
360
+ }, async () => {
361
+ const hosted = config.transport === 'hosted';
362
+ return ok({
363
+ server: `@edgegap/mcp ${VERSION}`,
364
+ transport: hosted ? 'hosted (Streamable HTTP)' : 'local (stdio)',
365
+ api_host: label,
366
+ api_base_url: config.baseUrlV1,
367
+ token: hosted
368
+ ? auth.current
369
+ ? 'received on this request\'s Authorization header'
370
+ : 'none on this request: send it as an Authorization header'
371
+ : config.envToken
372
+ ? 'from EDGEGAP_API_TOKEN'
373
+ : auth.current
374
+ ? 'provided by the developer this session (memory only)'
375
+ : 'not yet provided: the developer is asked on first use',
376
+ token_scope: 'organization-wide (Edgegap cannot scope tokens)',
377
+ read_only: config.readOnly,
378
+ app_allowlist: config.appAllowlist.length ? config.appAllowlist : 'none (all applications)',
379
+ max_duration_ceiling_minutes: config.maxDurationCeiling,
380
+ forced_deploy_tag: AGENT_TAG,
381
+ guardrails: {
382
+ dry_run: mutating
383
+ ? 'deploy, stop_deployment, create_app, create_app_version, create/authorize/delete relay'
384
+ : 'n/a: read-only, no write tools are registered',
385
+ token_in_container: 'deploys and versions are refused if the API token appears in an env var, tag or webhook URL',
386
+ stop: 'one exact request_id per call; no bulk stop',
387
+ auto_stop: 'each deploy reports its version\'s max_duration; Edgegap has no per-deployment time limit',
388
+ results: `every result starts with [${label}]`,
389
+ },
390
+ user_agent: `edgegap-mcp/${VERSION} (<MCP client name>)`,
391
+ });
392
+ });
245
393
  // ---------------------------------------------------------------- 1 ----
246
- server.registerTool('edgegap_list_apps', {
394
+ tool('edgegap_list_apps', {
247
395
  title: 'List Edgegap applications',
248
396
  description: 'List the applications in the Edgegap organization. Start here before creating or ' +
249
397
  'deploying anything, so you reuse an existing application instead of making a duplicate. ' +
@@ -264,7 +412,7 @@ export function registerTools(server, client, config, auth) {
264
412
  }));
265
413
  // ---------------------------------------------------------------- 2 ----
266
414
  if (mutating) {
267
- server.registerTool('edgegap_create_app', {
415
+ tool('edgegap_create_app', {
268
416
  title: 'Create an Edgegap application',
269
417
  description: 'Create a new application to hold game server versions. Only call this after ' +
270
418
  'edgegap_list_apps confirms no suitable application exists. Creating an application ' +
@@ -276,15 +424,18 @@ export function registerTools(server, client, config, auth) {
276
424
  .max(64)
277
425
  .describe('Application name, 3-64 chars. Usually the game or project name.'),
278
426
  is_active: z.boolean().optional().describe('Whether deployments are allowed. Default true.'),
427
+ dry_run: dryRunParam,
279
428
  },
280
429
  annotations: { destructiveHint: false, idempotentHint: false, openWorldHint: true },
281
- }, async ({ name, is_active }) => guard(auth, async () => {
430
+ }, async ({ name, is_active, dry_run }) => guard(auth, async () => {
282
431
  assertAppAllowed(config, name);
283
- const res = await client.createApp({
284
- name,
285
- is_active: is_active ?? true,
286
- image: PLACEHOLDER_IMAGE,
287
- });
432
+ const body = { name, is_active: is_active ?? true, image: PLACEHOLDER_IMAGE };
433
+ if (dry_run) {
434
+ const dry = client.dryRun();
435
+ await dry.client.createApp(body);
436
+ return dryRunResult(dry.requests);
437
+ }
438
+ const res = await client.createApp(body);
288
439
  return ok({
289
440
  created: res.name,
290
441
  active: res.is_active,
@@ -293,7 +444,7 @@ export function registerTools(server, client, config, auth) {
293
444
  }));
294
445
  }
295
446
  // ---------------------------------------------------------------- 3 ----
296
- server.registerTool('edgegap_list_app_versions', {
447
+ tool('edgegap_list_app_versions', {
297
448
  title: 'List versions of an application',
298
449
  description: 'List the versions under an application, with their container image, resources, ports ' +
299
450
  '(including whether TLS Upgrade is on, which browser/WebGL clients need for wss://) and ' +
@@ -330,7 +481,7 @@ export function registerTools(server, client, config, auth) {
330
481
  }));
331
482
  // ---------------------------------------------------------------- 4 ----
332
483
  if (mutating) {
333
- server.registerTool('edgegap_create_app_version', {
484
+ tool('edgegap_create_app_version', {
334
485
  title: 'Create an application version',
335
486
  description: 'Register a container image as a deployable version of an application. The image must ' +
336
487
  'already be pushed to a registry that Edgegap can pull from (see ' +
@@ -390,11 +541,22 @@ export function registerTools(server, client, config, auth) {
390
541
  env: z
391
542
  .array(z.object({ key: z.string(), value: z.string() }))
392
543
  .optional()
393
- .describe('Environment variables injected into the container.'),
544
+ .describe('Environment variables injected into the container. Values are never echoed back.'),
545
+ dry_run: dryRunParam,
394
546
  },
395
547
  annotations: { destructiveHint: false, idempotentHint: false, openWorldHint: true },
396
548
  }, async (args) => guarded(auth, NOT_FOUND.app, async () => {
397
549
  assertAppAllowed(config, args.application);
550
+ const leak = await tokenLeak(auth, args.dry_run, [
551
+ ...(args.env ?? []).flatMap((e) => [
552
+ [`env var name "${e.key.slice(0, 40)}"`, e.key],
553
+ [`the value of env var "${e.key.slice(0, 40)}"`, e.value],
554
+ ]),
555
+ ['registry_username', args.registry_username],
556
+ ['registry_token', args.registry_token],
557
+ ]);
558
+ if (leak)
559
+ return leak;
398
560
  if (args.memory_mb > args.cpu_units * 2) {
399
561
  return fail(`memory_mb (${args.memory_mb}) exceeds twice cpu_units (${args.cpu_units}). ` +
400
562
  `Edgegap rejects this. Either lower memory_mb to ${args.cpu_units * 2} or raise cpu_units.`);
@@ -408,29 +570,35 @@ export function registerTools(server, client, config, auth) {
408
570
  const capped = Math.min(requested, config.maxDurationCeiling);
409
571
  const hasRegistryLogin = Boolean(args.registry_username && args.registry_token);
410
572
  const edgegapRegistry = /(^|\/\/)registry\.edgegap\.com\/?$/.test(args.docker_repository.trim());
573
+ const body = {
574
+ name: args.name,
575
+ is_active: true,
576
+ req_cpu: args.cpu_units,
577
+ req_memory: args.memory_mb,
578
+ docker_repository: args.docker_repository,
579
+ docker_image: args.docker_image,
580
+ docker_tag: args.docker_tag,
581
+ private_username: args.registry_username,
582
+ private_token: args.registry_token,
583
+ verify_image: args.verify_image ?? false,
584
+ max_duration: capped,
585
+ ports: args.ports.map((p) => ({
586
+ port: p.port,
587
+ protocol: p.protocol,
588
+ name: p.name ?? 'gameport',
589
+ to_check: p.to_check ?? true,
590
+ tls_upgrade: p.tls_upgrade ?? false,
591
+ })),
592
+ envs: args.env?.map((e) => ({ key: e.key, value: e.value, is_hidden: false })),
593
+ };
594
+ if (args.dry_run) {
595
+ const dry = client.dryRun();
596
+ await dry.client.createAppVersion(args.application, body);
597
+ return dryRunResult(dry.requests, capped < requested ? [`max_duration capped to ${capped} minutes by EDGEGAP_MAX_DURATION_MINUTES.`] : []);
598
+ }
411
599
  let res;
412
600
  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
- });
601
+ res = await client.createAppVersion(args.application, body);
434
602
  }
435
603
  catch (err) {
436
604
  // verify_image pulls with the version's registry login. Without one
@@ -465,13 +633,17 @@ export function registerTools(server, client, config, auth) {
465
633
  }
466
634
  // ---------------------------------------------------------------- 5 ----
467
635
  if (mutating) {
468
- server.registerTool('edgegap_deploy', {
636
+ tool('edgegap_deploy', {
469
637
  title: 'Deploy a game server',
470
638
  description: 'Start one authoritative dedicated game server from an application version, placed near ' +
471
639
  'the players you specify. This is the recommended way to host a multiplayer match: the ' +
472
640
  'server owns the game state, so no player hosts it. Returns immediately with a request_id; the server is still starting and ' +
473
641
  'has no connection details yet. Follow this call with edgegap_wait_for_deployment to ' +
474
- 'get the address players connect to. Always stop deployments you started for testing.',
642
+ 'get the address players connect to. Always stop deployments you started for testing. ' +
643
+ `Every deployment is tagged "${AGENT_TAG}" in addition to any tags you pass, so ` +
644
+ 'edgegap_list_deployments with only_agent_deployments: true finds them all. Runs until ' +
645
+ 'stopped or until the version\'s max_duration, which the result reports. Refused, with ' +
646
+ 'nothing sent, if the API token appears in an env var or tag.',
475
647
  inputSchema: {
476
648
  application: z.string().describe('Application name.'),
477
649
  version: z.string().describe('Version name within the application.'),
@@ -479,13 +651,14 @@ export function registerTools(server, client, config, auth) {
479
651
  env: z
480
652
  .array(z.object({ key: z.string(), value: z.string() }))
481
653
  .optional()
482
- .describe('Environment variables for this deployment only.'),
654
+ .describe('Environment variables for this deployment only. Values are never echoed back.'),
483
655
  tags: z
484
- .array(z.string())
656
+ .array(z.string().min(1).max(40))
485
657
  .optional()
486
- .describe('Tags for filtering later, e.g. ["agent-test"]. Recommended.'),
658
+ .describe(`Extra tags for filtering later, e.g. ["agent-test"]. "${AGENT_TAG}" is always added.`),
487
659
  cpu_units: z.number().int().min(256).optional().describe('Override the version CPU.'),
488
660
  memory_mb: z.number().int().min(256).optional().describe('Override the version memory.'),
661
+ dry_run: dryRunParam,
489
662
  },
490
663
  annotations: { destructiveHint: false, idempotentHint: false, openWorldHint: true },
491
664
  }, async (args) => guarded(auth, NOT_FOUND.app, async () => {
@@ -495,11 +668,23 @@ export function registerTools(server, client, config, auth) {
495
668
  return fail('No player locations given. Supply users.ip_addresses (e.g. the developer\'s own ' +
496
669
  'public IP) or users.geo_coordinates. Edgegap needs at least one to choose a region.');
497
670
  }
671
+ // Forced, whatever the caller passed: the tag is how agent
672
+ // deployments are found and cleaned up, so it cannot be optional.
673
+ const tags = [...new Set([...(args.tags ?? []), AGENT_TAG])];
674
+ const leak = await tokenLeak(auth, args.dry_run, [
675
+ ...(args.env ?? []).flatMap((e) => [
676
+ [`env var name "${e.key.slice(0, 40)}"`, e.key],
677
+ [`the value of env var "${e.key.slice(0, 40)}"`, e.value],
678
+ ]),
679
+ ...tags.map((t) => [`tag "${t.slice(0, 8)}โ€ฆ"`, t]),
680
+ ]);
681
+ if (leak)
682
+ return leak;
498
683
  const body = {
499
684
  application: args.application,
500
685
  version: args.version,
501
686
  users,
502
- tags: args.tags ?? ['mcp'],
687
+ tags,
503
688
  };
504
689
  if (args.env) {
505
690
  body.environment_variables = args.env.map((e) => ({
@@ -511,16 +696,31 @@ export function registerTools(server, client, config, auth) {
511
696
  if (args.cpu_units && args.memory_mb) {
512
697
  body.resources = { cpu_units: args.cpu_units, memory_mib: args.memory_mb };
513
698
  }
699
+ if (args.dry_run) {
700
+ const dry = client.dryRun();
701
+ await dry.client.deploy(body);
702
+ return dryRunResult(dry.requests, [
703
+ `Tagged "${AGENT_TAG}" automatically.`,
704
+ 'Auto-stop comes from the version\'s max_duration; a real deploy reports it.',
705
+ ]);
706
+ }
707
+ // Edgegap has no per-deployment time limit: a deployment runs until
708
+ // stopped or until its version's max_duration (default 1440 minutes,
709
+ // a full day). Read it first so the agent knows how long an
710
+ // unstopped test server will keep billing.
711
+ const version = await client.getAppVersion(args.application, args.version);
514
712
  const res = await client.deploy(body);
515
713
  return ok({
516
714
  request_id: res.request_id,
517
715
  status: 'starting',
716
+ tags,
717
+ ...autoStop(version.max_duration),
518
718
  next_step: `Call edgegap_wait_for_deployment with request_id ${res.request_id}.`,
519
719
  });
520
720
  }));
521
721
  }
522
722
  // ---------------------------------------------------------------- 6 ----
523
- server.registerTool('edgegap_get_deployment', {
723
+ tool('edgegap_get_deployment', {
524
724
  title: 'Get deployment status',
525
725
  description: 'Read the current status of one deployment, including connection address and ports once ' +
526
726
  'it is ready. For a deployment you just created, prefer edgegap_wait_for_deployment โ€” it ' +
@@ -534,7 +734,7 @@ export function registerTools(server, client, config, auth) {
534
734
  return ok(compactDeployment(d));
535
735
  }));
536
736
  // ---------------------------------------------------------------- 7 ----
537
- server.registerTool('edgegap_wait_for_deployment', {
737
+ tool('edgegap_wait_for_deployment', {
538
738
  title: 'Wait for a deployment to become ready',
539
739
  description: 'Poll a deployment until it is ready, errors, or the timeout expires, then return the ' +
540
740
  'connection details. This is the tool to call right after edgegap_deploy. Do not build ' +
@@ -579,7 +779,7 @@ export function registerTools(server, client, config, auth) {
579
779
  `call edgegap_get_deployment to check again, or edgegap_stop_deployment to clean up.`);
580
780
  }));
581
781
  // ---------------------------------------------------------------- 8 ----
582
- server.registerTool('edgegap_list_deployments', {
782
+ tool('edgegap_list_deployments', {
583
783
  title: 'List running deployments',
584
784
  description: 'List active deployments, optionally filtered and sorted. Use this to find deployments left running ' +
585
785
  'from earlier sessions before starting new ones โ€” orphaned servers cost money. ' +
@@ -587,8 +787,15 @@ export function registerTools(server, client, config, auth) {
587
787
  'e.g. [{field:"application",operator:"eq",value:"my-game"},{field:"status",operator:"eq",value:"ready"}]. ' +
588
788
  'Operators: eq and neq on every field except created_at (eq, gte, lte); in and nin with an array value ' +
589
789
  'on request_id, tags, application, version, fleet_name, host_name; ilike with % wildcards on fleet_name ' +
590
- 'and host_name. At most one filter per field. Sort by created_at or available_session_sockets.',
790
+ 'and host_name. At most one filter per field. Sort by created_at or available_session_sockets. ' +
791
+ `To find every deployment an agent started through this server, pass only_agent_deployments: true ` +
792
+ `(the same as filtering tags in ["${AGENT_TAG}", "mcp"]).`,
591
793
  inputSchema: {
794
+ only_agent_deployments: z
795
+ .boolean()
796
+ .optional()
797
+ .describe(`Only deployments started through this server: tagged "${AGENT_TAG}", or "mcp" by versions ` +
798
+ 'up to 0.3.3. Cannot be combined with a tags filter.'),
592
799
  filters: z
593
800
  .array(z.object({
594
801
  field: z.enum([
@@ -612,7 +819,14 @@ export function registerTools(server, client, config, auth) {
612
819
  limit: z.number().int().min(1).max(100).optional().describe('Default 50.'),
613
820
  },
614
821
  annotations: { readOnlyHint: true, openWorldHint: true },
615
- }, async ({ filters, order_by, limit }) => guard(auth, async () => {
822
+ }, async ({ only_agent_deployments, filters: given, order_by, limit }) => guard(auth, async () => {
823
+ let filters = given;
824
+ if (only_agent_deployments) {
825
+ if (given?.some((f) => f.field === 'tags')) {
826
+ return fail('only_agent_deployments already filters on tags. Drop the tags filter, or drop only_agent_deployments.');
827
+ }
828
+ filters = [...(given ?? []), { field: 'tags', operator: 'in', value: [AGENT_TAG, 'mcp'] }];
829
+ }
616
830
  const fields = (filters ?? []).map((f) => f.field);
617
831
  const repeated = fields.find((f, i) => fields.indexOf(f) !== i);
618
832
  if (repeated) {
@@ -633,22 +847,32 @@ export function registerTools(server, client, config, auth) {
633
847
  }));
634
848
  // ---------------------------------------------------------------- 9 ----
635
849
  if (mutating) {
636
- server.registerTool('edgegap_stop_deployment', {
850
+ tool('edgegap_stop_deployment', {
637
851
  title: 'Stop a deployment',
638
852
  description: 'Gracefully stop one deployment by request_id, sending SIGTERM to the container. ' +
639
853
  'Stop every deployment you started for testing before ending your task. This tool ' +
640
- 'stops exactly one deployment; bulk stop is deliberately not exposed.',
854
+ 'stops exactly one deployment, named by its exact request_id: empty IDs, wildcards ' +
855
+ 'and lists are refused, and bulk stop is deliberately not exposed.',
641
856
  inputSchema: {
642
- request_id: z.string().describe('The request_id of the deployment to stop.'),
857
+ request_id: z.string().describe('The exact request_id of the one deployment to stop, e.g. "61b1be8f54d9".'),
858
+ dry_run: dryRunParam,
643
859
  },
644
860
  annotations: { destructiveHint: true, idempotentHint: true, openWorldHint: true },
645
- }, async ({ request_id }) => guarded(auth, NOT_FOUND.deployment, async () => {
861
+ }, async ({ request_id, dry_run }) => guarded(auth, NOT_FOUND.deployment, async () => {
862
+ const bad = checkRequestId(request_id);
863
+ if (bad)
864
+ return bad;
865
+ if (dry_run) {
866
+ const dry = client.dryRun();
867
+ await dry.client.stopDeployment(request_id);
868
+ return dryRunResult(dry.requests);
869
+ }
646
870
  const res = await client.stopDeployment(request_id);
647
871
  return ok({ request_id, result: res.message ?? 'stop requested' });
648
872
  }));
649
873
  }
650
874
  // --------------------------------------------------------------- 10 ----
651
- server.registerTool('edgegap_get_deployment_logs', {
875
+ tool('edgegap_get_deployment_logs', {
652
876
  title: 'Get container logs for a deployment',
653
877
  description: 'Retrieve stdout/stderr and crash output for a deployment. Call this whenever a ' +
654
878
  'deployment errors or a server exits unexpectedly โ€” the crash exit code usually ' +
@@ -683,7 +907,7 @@ export function registerTools(server, client, config, auth) {
683
907
  // -------------------------------------------------------------- 11a ----
684
908
  // Pure text generation: no token, no network, so it is always registered and
685
909
  // never goes through guard().
686
- server.registerTool('edgegap_generate_dockerfile', {
910
+ tool('edgegap_generate_dockerfile', {
687
911
  title: 'Generate a game server Dockerfile',
688
912
  description: 'Write a Dockerfile for this project\'s headless game server build, ready for Edgegap: ' +
689
913
  'linux/amd64 base, the build folder copied in, the binary made executable, the right ' +
@@ -772,7 +996,7 @@ export function registerTools(server, client, config, auth) {
772
996
  // --------------------------------------------------------------- 11 ----
773
997
  // Pure text analysis: no token, no network, so it is always registered and
774
998
  // never goes through guard().
775
- server.registerTool('edgegap_validate_server_config', {
999
+ tool('edgegap_validate_server_config', {
776
1000
  title: 'Validate a game server Dockerfile and port config',
777
1001
  description: 'Check a game server Dockerfile and the ports/resources you intend to register against ' +
778
1002
  'what Edgegap requires, BEFORE building and pushing. Catches the failures that otherwise ' +
@@ -840,7 +1064,7 @@ export function registerTools(server, client, config, auth) {
840
1064
  // Mutating-only: it can provision the registry project, and it hands a
841
1065
  // secret to the agent. A read-only session has no business receiving one.
842
1066
  if (mutating) {
843
- server.registerTool('edgegap_get_registry_credentials', {
1067
+ tool('edgegap_get_registry_credentials', {
844
1068
  title: 'Get Edgegap container registry push credentials',
845
1069
  description: 'Get the push login for this organization\'s private Edgegap container registry ' +
846
1070
  '(registry.edgegap.com) and the exact docker login, build and push commands for your ' +
@@ -927,7 +1151,7 @@ export function registerTools(server, client, config, auth) {
927
1151
  }));
928
1152
  }
929
1153
  // --------------------------------------------------------------- 13 ----
930
- server.registerTool('edgegap_list_registry_tags', {
1154
+ tool('edgegap_list_registry_tags', {
931
1155
  title: 'List image tags in the Edgegap registry',
932
1156
  description: 'List the tags pushed for one image in this organization\'s Edgegap container registry, ' +
933
1157
  'with push time and size. Call it after docker push to confirm the tag landed before ' +
@@ -998,7 +1222,7 @@ export function registerTools(server, client, config, auth) {
998
1222
  // ================================================== peer-to-peer relays ====
999
1223
  // --------------------------------------------------------------- 14 ----
1000
1224
  if (mutating) {
1001
- server.registerTool('edgegap_create_relay_session', {
1225
+ tool('edgegap_create_relay_session', {
1002
1226
  title: 'Create a relay session (host-client games only)',
1003
1227
  description: 'A relay is NOT a game server and is not the recommended default โ€” for a multiplayer ' +
1004
1228
  'match, deploy an authoritative dedicated server with edgegap_deploy instead. A relay ' +
@@ -1020,13 +1244,20 @@ export function registerTools(server, client, config, auth) {
1020
1244
  webhook_url: z.string().url().optional().describe('Called when the session is ready.'),
1021
1245
  wait_until_ready: z.boolean().optional().describe('Poll until the relay is assigned. Default true.'),
1022
1246
  timeout_seconds: z.number().int().min(5).max(120).optional().describe('Default 30.'),
1247
+ dry_run: dryRunParam,
1023
1248
  },
1024
1249
  annotations: { destructiveHint: false, idempotentHint: false, openWorldHint: true },
1025
- }, async ({ user_ips, webhook_url, wait_until_ready, timeout_seconds }) => guard(auth, async () => {
1026
- const created = await client.createRelaySession({
1027
- users: user_ips.map((ip) => ({ ip })),
1028
- ...(webhook_url ? { webhook_url } : {}),
1029
- });
1250
+ }, async ({ user_ips, webhook_url, wait_until_ready, timeout_seconds, dry_run }) => guard(auth, async () => {
1251
+ const leak = await tokenLeak(auth, dry_run, [['webhook_url', webhook_url]]);
1252
+ if (leak)
1253
+ return leak;
1254
+ const body = { users: user_ips.map((ip) => ({ ip })), ...(webhook_url ? { webhook_url } : {}) };
1255
+ if (dry_run) {
1256
+ const dry = client.dryRun();
1257
+ await dry.client.createRelaySession(body);
1258
+ return dryRunResult(dry.requests);
1259
+ }
1260
+ const created = await client.createRelaySession(body);
1030
1261
  if (wait_until_ready === false) {
1031
1262
  return ok({
1032
1263
  ...compactRelay(created),
@@ -1055,7 +1286,7 @@ export function registerTools(server, client, config, auth) {
1055
1286
  }));
1056
1287
  }
1057
1288
  // --------------------------------------------------------------- 15 ----
1058
- server.registerTool('edgegap_get_relay_session', {
1289
+ tool('edgegap_get_relay_session', {
1059
1290
  title: 'Get a relay session',
1060
1291
  description: 'Read one relay session: whether it is ready, the relay address and ports, and each ' +
1061
1292
  'authorized player with their authorization token. edgegap_create_relay_session already ' +
@@ -1065,16 +1296,22 @@ export function registerTools(server, client, config, auth) {
1065
1296
  }, async ({ session_id }) => guarded(auth, NOT_FOUND.relay, async () => ok(compactRelay(await client.getRelaySession(session_id)))));
1066
1297
  if (mutating) {
1067
1298
  // ------------------------------------------------------------- 16 ----
1068
- server.registerTool('edgegap_authorize_relay_user', {
1299
+ tool('edgegap_authorize_relay_user', {
1069
1300
  title: 'Add a player to a relay session',
1070
1301
  description: 'Authorize one more player (by public IP) on an existing relay session, for a player ' +
1071
1302
  'joining after the session was created. Returns that player\'s authorization token.',
1072
1303
  inputSchema: {
1073
1304
  session_id: z.string(),
1074
1305
  user_ip: z.string().min(3).describe('Public IP of the joining player.'),
1306
+ dry_run: dryRunParam,
1075
1307
  },
1076
1308
  annotations: { destructiveHint: false, idempotentHint: true, openWorldHint: true },
1077
- }, async ({ session_id, user_ip }) => guarded(auth, NOT_FOUND.relay, async () => {
1309
+ }, async ({ session_id, user_ip, dry_run }) => guarded(auth, NOT_FOUND.relay, async () => {
1310
+ if (dry_run) {
1311
+ const dry = client.dryRun();
1312
+ await dry.client.authorizeRelayUser({ session_id, user_ip });
1313
+ return dryRunResult(dry.requests);
1314
+ }
1078
1315
  const res = await client.authorizeRelayUser({ session_id, user_ip });
1079
1316
  return ok({
1080
1317
  session_id: res.session_id,
@@ -1084,13 +1321,25 @@ export function registerTools(server, client, config, auth) {
1084
1321
  });
1085
1322
  }));
1086
1323
  // ------------------------------------------------------------- 17 ----
1087
- server.registerTool('edgegap_delete_relay_session', {
1324
+ tool('edgegap_delete_relay_session', {
1088
1325
  title: 'Delete a relay session',
1089
1326
  description: 'Close one relay session. Connected players lose their relay connection. Delete every ' +
1090
- 'session you created for testing before ending your task.',
1091
- inputSchema: { session_id: z.string() },
1327
+ 'session you created for testing before ending your task. Takes exactly one session_id; ' +
1328
+ 'empty IDs, wildcards and lists are refused.',
1329
+ inputSchema: {
1330
+ session_id: z.string().describe('The exact session_id of the one session to delete, e.g. "0724828881e2-S".'),
1331
+ dry_run: dryRunParam,
1332
+ },
1092
1333
  annotations: { destructiveHint: true, idempotentHint: true, openWorldHint: true },
1093
- }, async ({ session_id }) => guarded(auth, NOT_FOUND.relay, async () => {
1334
+ }, async ({ session_id, dry_run }) => guarded(auth, NOT_FOUND.relay, async () => {
1335
+ if (!SESSION_ID.test(session_id)) {
1336
+ return fail(`"${session_id.slice(0, 80)}" is not a single relay session_id. Pass exactly one, e.g. "0724828881e2-S".`);
1337
+ }
1338
+ if (dry_run) {
1339
+ const dry = client.dryRun();
1340
+ await dry.client.deleteRelaySession(session_id);
1341
+ return dryRunResult(dry.requests);
1342
+ }
1094
1343
  await client.deleteRelaySession(session_id);
1095
1344
  return ok({ session_id, result: 'deleted' });
1096
1345
  }));
@@ -1100,7 +1349,7 @@ export function registerTools(server, client, config, auth) {
1100
1349
  // Edgegap has no public API to create a matchmaker, so this does not create
1101
1350
  // one. It produces the configuration the dashboard asks for, checked against
1102
1351
  // the application version it points at.
1103
- server.registerTool('edgegap_build_matchmaker_config', {
1352
+ tool('edgegap_build_matchmaker_config', {
1104
1353
  title: 'Build a basic matchmaker configuration',
1105
1354
  description: 'Generate a ready-to-upload Edgegap matchmaker JSON configuration with one profile: team ' +
1106
1355
  'count and size, optional latency rule, and optional expansions that relax the rules the ' +
@@ -0,0 +1,6 @@
1
+ /**
2
+ * The server version, reported to MCP clients, in the User-Agent on every API
3
+ * call, and by edgegap_context. Keep in step with package.json and server.json;
4
+ * test/package.mjs fails the build when they disagree.
5
+ */
6
+ export const VERSION = '0.4.0';
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.3",
4
+ "version": "0.4.0",
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",