@edgegap/mcp 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/tools.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * The golden-path tools: getting a server image right and into a registry,
3
- * deploying it, and the two things players need around it — a relay for
4
- * peer-to-peer games and a matchmaker config for dedicated ones.
3
+ * deploying it as an authoritative dedicated server, matching players into it,
4
+ * and — for games built host-client — relays as the alternative.
5
5
  *
6
6
  * Tool descriptions are written for a coding agent, not a human reading docs.
7
7
  * Each one says when to reach for it and what to call next, because the main
@@ -11,8 +11,66 @@ import { z } from 'zod';
11
11
  import { EdgegapApiError } from './client.js';
12
12
  import { assertAppAllowed, redact } from './config.js';
13
13
  import { TokenUnavailableError } from './auth.js';
14
- import { validateServerConfig, REFERENCE_DOCKERFILES, PROTOCOLS, NETCODE_NAMES, } from './serverconfig.js';
14
+ import { validateServerConfig, PROTOCOLS, NETCODE_NAMES, } from './serverconfig.js';
15
+ import { generateDockerfile, DockerfileInputError } from './dockerfile.js';
15
16
  import { buildMatchmakerConfig, DASHBOARD_URL } from './matchmaker.js';
17
+ /**
18
+ * The one definition of "dedicated server vs relay" this server gives agents.
19
+ * Used in the server instructions, the relay tool description, and every relay
20
+ * result, so the recommendation cannot drift between them.
21
+ *
22
+ * Agents left alone tend to pick relays because they need no server image.
23
+ * That optimises the agent's effort, not the developer's game, so the default
24
+ * here is the authoritative server and relays need a stated reason.
25
+ */
26
+ export const ARCHITECTURE_GUIDANCE = 'Dedicated server vs relay — recommend a dedicated server by default.\n' +
27
+ '- Dedicated (authoritative) server (edgegap_deploy): Edgegap runs the headless server ' +
28
+ 'build, and the server owns the game state. No player has host advantage, cheating is ' +
29
+ 'much harder, the match survives any player leaving, every player is one hop from the ' +
30
+ 'server, and performance does not depend on a player\'s PC or home connection.\n' +
31
+ '- Relay (edgegap_create_relay_session): NOT a game server. Edgegap only forwards traffic ' +
32
+ 'between players; one player\'s game is the host and owns the state. The host can cheat ' +
33
+ 'and has zero latency while everyone else has two hops, the host\'s machine and upload ' +
34
+ 'bandwidth cap the match, and the match ends when the host quits unless the game ' +
35
+ 'implements host migration.\n' +
36
+ 'Use a relay only when the developer explicitly wants peer-to-peer/host-client, or the ' +
37
+ 'game\'s netcode is already built as a listen server and moving to a dedicated server is ' +
38
+ 'not an option. "It needs no server image" is not a reason: edgegap_generate_dockerfile ' +
39
+ 'removes most of that work. If unsure, ask the developer before choosing a relay.';
40
+ /**
41
+ * Server instructions, shared by the local server and the hosted Worker so
42
+ * both give agents the same golden path. Only the credential paragraph differs.
43
+ */
44
+ export function serverInstructions(mode) {
45
+ const credentials = mode === 'local'
46
+ ? 'Credentials: if no token was configured, the first tool call asks the developer for one. '
47
+ : 'Credentials: the token comes from the Authorization header on this connection. ';
48
+ return ('Host multiplayer games on Edgegap. The recommended setup is an authoritative dedicated ' +
49
+ 'server per match; relays exist for games built host-client.\n\n' +
50
+ ARCHITECTURE_GUIDANCE +
51
+ '\n\n' +
52
+ 'Golden path for a first dedicated-server deployment:\n' +
53
+ '1. edgegap_generate_dockerfile if the project has no Dockerfile, or ' +
54
+ 'edgegap_validate_server_config on the one it has, before building\n' +
55
+ '2. edgegap_get_registry_credentials, then docker build --platform linux/amd64 and push\n' +
56
+ '3. edgegap_list_registry_tags to confirm the push landed\n' +
57
+ '4. edgegap_list_apps, then edgegap_create_app if no suitable application exists\n' +
58
+ '5. edgegap_create_app_version to register the image\n' +
59
+ '6. edgegap_deploy to start a server near the players\n' +
60
+ '7. edgegap_wait_for_deployment to get the connection address\n' +
61
+ '8. edgegap_stop_deployment when finished\n' +
62
+ 'To match players into those servers, edgegap_build_matchmaker_config produces the ' +
63
+ '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 ' +
66
+ 'deployment errors, read the container logs before redeploying.\n\n' +
67
+ credentials +
68
+ 'That token is org-wide and cannot be scoped by Edgegap, so it authorises far more than ' +
69
+ 'any single task needs. Treat it as a supervised credential: do not use it for work the ' +
70
+ 'developer did not ask for, do not enumerate or modify unrelated applications, and do ' +
71
+ 'not repeat operations against it to explore what is possible. If the developer declines ' +
72
+ 'to provide a token, stop and report which operation needed it — do not retry.');
73
+ }
16
74
  /** 1x1 transparent PNG. The create-app endpoint requires an image and agents
17
75
  * have no sensible one to supply; a placeholder beats a blocked flow. */
18
76
  const PLACEHOLDER_IMAGE = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==';
@@ -321,8 +379,9 @@ export function registerTools(server, client, config, auth) {
321
379
  if (mutating) {
322
380
  server.registerTool('edgegap_deploy', {
323
381
  title: 'Deploy a game server',
324
- description: 'Start one containerized instance of an application version, placed near the players ' +
325
- 'you specify. Returns immediately with a request_id; the server is still starting and ' +
382
+ description: 'Start one authoritative dedicated game server from an application version, placed near ' +
383
+ 'the players you specify. This is the recommended way to host a multiplayer match: the ' +
384
+ 'server owns the game state, so no player hosts it. Returns immediately with a request_id; the server is still starting and ' +
326
385
  'has no connection details yet. Follow this call with edgegap_wait_for_deployment to ' +
327
386
  'get the address players connect to. Always stop deployments you started for testing.',
328
387
  inputSchema: {
@@ -434,18 +493,47 @@ export function registerTools(server, client, config, auth) {
434
493
  // ---------------------------------------------------------------- 8 ----
435
494
  server.registerTool('edgegap_list_deployments', {
436
495
  title: 'List running deployments',
437
- description: 'List active deployments, optionally filtered. Use this to find deployments left running ' +
438
- 'from earlier sessions before starting new ones — orphaned servers cost money.',
496
+ description: 'List active deployments, optionally filtered and sorted. Use this to find deployments left running ' +
497
+ 'from earlier sessions before starting new ones — orphaned servers cost money. ' +
498
+ 'Filter by status, application, version, tags, request_id, created_at, fleet_name or host_name, ' +
499
+ 'e.g. [{field:"application",operator:"eq",value:"my-game"},{field:"status",operator:"eq",value:"ready"}]. ' +
500
+ 'Operators: eq and neq on every field except created_at (eq, gte, lte); in and nin with an array value ' +
501
+ 'on request_id, tags, application, version, fleet_name, host_name; ilike with % wildcards on fleet_name ' +
502
+ 'and host_name. At most one filter per field. Sort by created_at or available_session_sockets.',
439
503
  inputSchema: {
440
- filter: z
441
- .string()
504
+ filters: z
505
+ .array(z.object({
506
+ field: z.enum([
507
+ 'status', 'request_id', 'tags', 'created_at', 'application',
508
+ 'version', 'fleet_name', 'host_name',
509
+ ]),
510
+ operator: z.enum(['eq', 'neq', 'in', 'nin', 'gte', 'lte', 'ilike']),
511
+ value: z
512
+ .union([z.string(), z.array(z.string())])
513
+ .describe('A string, or an array of strings for in/nin. created_at is ISO 8601, e.g. "2026-09-30T00:00:00Z".'),
514
+ }))
515
+ .optional()
516
+ .describe('Omit for all deployments.'),
517
+ order_by: z
518
+ .array(z.object({
519
+ field: z.enum(['created_at', 'available_session_sockets']),
520
+ order: z.enum(['asc', 'desc']),
521
+ }))
442
522
  .optional()
443
- .describe('Edgegap filter expression, e.g. by tag. Omit for all deployments.'),
523
+ .describe('e.g. [{field:"created_at",order:"asc"}] for oldest first.'),
444
524
  limit: z.number().int().min(1).max(100).optional().describe('Default 50.'),
445
525
  },
446
526
  annotations: { readOnlyHint: true, openWorldHint: true },
447
- }, async ({ filter, limit }) => guard(auth, async () => {
448
- const res = await client.listDeployments({ query: filter, limit: limit ?? 50 });
527
+ }, async ({ filters, order_by, limit }) => guard(auth, async () => {
528
+ const fields = (filters ?? []).map((f) => f.field);
529
+ const repeated = fields.find((f, i) => fields.indexOf(f) !== i);
530
+ if (repeated) {
531
+ return fail(`Only one filter per field is allowed, and "${repeated}" has more than one. Combine them with "in" or "nin".`);
532
+ }
533
+ const query = filters?.length || order_by?.length
534
+ ? JSON.stringify({ filters: filters ?? [], ...(order_by?.length ? { order_by } : {}) })
535
+ : undefined;
536
+ const res = await client.listDeployments({ query, limit: limit ?? 50 });
449
537
  const rows = (res.data ?? []).map((d) => ({
450
538
  request_id: d.request_id,
451
539
  ready: d.ready,
@@ -504,6 +592,94 @@ export function registerTools(server, client, config, auth) {
504
592
  });
505
593
  }));
506
594
  // ============================================= before the first deploy ====
595
+ // -------------------------------------------------------------- 11a ----
596
+ // Pure text generation: no token, no network, so it is always registered and
597
+ // never goes through guard().
598
+ server.registerTool('edgegap_generate_dockerfile', {
599
+ title: 'Generate a game server Dockerfile',
600
+ description: 'Write a Dockerfile for this project\'s headless game server build, ready for Edgegap: ' +
601
+ 'linux/amd64 base, the build folder copied in, the binary made executable, the right ' +
602
+ 'headless flags (Unity -batchmode -nographics, Godot --headless), a non-root user where ' +
603
+ 'the engine needs it (Unreal refuses root), CRLF fixes for start scripts, and EXPOSE ' +
604
+ 'lines matching the ports. Call this when the project has no Dockerfile, before ' +
605
+ 'building anything. Look at the build output first so you can pass the real build ' +
606
+ 'folder, binary name and port; anything you omit is assumed and listed under ' +
607
+ 'assumptions, which you must confirm with the developer or the project files. Write the ' +
608
+ 'result to Dockerfile, then build. The output is checked against ' +
609
+ 'edgegap_validate_server_config before it is returned. Makes no API calls.',
610
+ inputSchema: {
611
+ engine: z.enum(['unity', 'unreal', 'godot', 'other']).describe('Game engine of the server build.'),
612
+ build_path: z
613
+ .string()
614
+ .optional()
615
+ .describe('Server build folder, relative to where docker build runs. Defaults: unity ' +
616
+ '"Builds/EdgegapServer", unreal "." (run from inside the packaged LinuxServer folder), godot "build".'),
617
+ executable: z
618
+ .string()
619
+ .optional()
620
+ .describe('File name of the server binary or start script inside build_path. Defaults: unity ' +
621
+ '"ServerBuild", unreal "StartServer.sh", godot "server.x86_64". Required for "other".'),
622
+ ports: z
623
+ .array(z.object({
624
+ port: z.number().int().min(1).max(59999),
625
+ protocol: z.enum(PROTOCOLS),
626
+ name: z.string().optional(),
627
+ }))
628
+ .optional()
629
+ .describe('Ports the server listens on. Default: 7777, with the protocol the netcode uses (UDP if unknown).'),
630
+ netcode: z
631
+ .string()
632
+ .optional()
633
+ .describe(`Networking transport, to pick the protocol. Known: ${NETCODE_NAMES.join(', ')}.`),
634
+ launch_args: z
635
+ .array(z.string())
636
+ .optional()
637
+ .describe('Extra server arguments, one per entry, e.g. ["-log", "-port=7777"].'),
638
+ base_image: z.string().optional().describe('Default "ubuntu:22.04".'),
639
+ },
640
+ annotations: { readOnlyHint: true, idempotentHint: true, openWorldHint: false },
641
+ }, async (args) => {
642
+ let generated;
643
+ try {
644
+ generated = generateDockerfile(args);
645
+ }
646
+ catch (err) {
647
+ if (err instanceof DockerfileInputError)
648
+ return fail(err.message);
649
+ throw err;
650
+ }
651
+ // Never hand back something our own validator would reject.
652
+ const check = validateServerConfig({
653
+ dockerfile: generated.dockerfile,
654
+ engine: args.engine,
655
+ netcode: args.netcode,
656
+ ports: generated.ports,
657
+ });
658
+ if (check.errors.length > 0) {
659
+ return fail('The generated Dockerfile failed validation, which means these inputs combine badly:\n- ' +
660
+ check.errors.map((e) => `${e.message} ${e.fix}`).join('\n- '));
661
+ }
662
+ const ref = '<image>:<unique-build-tag>';
663
+ const portFlags = generated.ports
664
+ .flatMap((p) => p.protocol === 'TCP/UDP'
665
+ ? [`-p ${p.port}:${p.port}/udp`, `-p ${p.port}:${p.port}/tcp`]
666
+ : [`-p ${p.port}:${p.port}/${p.protocol === 'UDP' ? 'udp' : 'tcp'}`])
667
+ .join(' ');
668
+ return ok({
669
+ dockerfile: generated.dockerfile,
670
+ assumptions: generated.assumptions,
671
+ warnings: check.warnings.length ? check.warnings : undefined,
672
+ ports_for_create_app_version: generated.ports,
673
+ commands: {
674
+ build: `docker build --platform linux/amd64 -t ${ref} .`,
675
+ // --platform belongs on build only: the image is already linux/amd64.
676
+ test_locally: `docker run --rm ${portFlags} ${ref}`,
677
+ },
678
+ next_step: 'Confirm every assumption, write this to Dockerfile, build it, and run it locally to check ' +
679
+ 'the server starts and stays up. Then push it (edgegap_get_registry_credentials) and ' +
680
+ 'register it with edgegap_create_app_version using ports_for_create_app_version.',
681
+ });
682
+ });
507
683
  // --------------------------------------------------------------- 11 ----
508
684
  // Pure text analysis: no token, no network, so it is always registered and
509
685
  // never goes through guard().
@@ -515,8 +691,8 @@ export function registerTools(server, client, config, auth) {
515
691
  'runs linux/amd64), Unreal running as root, missing Unity -batchmode -nographics, a ' +
516
692
  'server bound to localhost, EXPOSE ports that do not match the version ports, a protocol ' +
517
693
  'that does not match the netcode transport, the "latest" tag, and bad CPU/memory ratios. ' +
518
- 'Pass the Dockerfile text (read it from disk first). With no Dockerfile and an engine of ' +
519
- 'unity or unreal, returns Edgegap\'s reference Dockerfile to start from. Makes no API calls.',
694
+ 'Pass the Dockerfile text (read it from disk first). If there is no Dockerfile yet, call ' +
695
+ 'edgegap_generate_dockerfile instead. Makes no API calls.',
520
696
  inputSchema: {
521
697
  dockerfile: z.string().optional().describe('Full text of the Dockerfile.'),
522
698
  engine: z
@@ -544,8 +720,11 @@ export function registerTools(server, client, config, auth) {
544
720
  annotations: { readOnlyHint: true, idempotentHint: true, openWorldHint: false },
545
721
  }, async (args) => {
546
722
  const { engine, errors, warnings } = validateServerConfig(args);
547
- const reference = REFERENCE_DOCKERFILES[engine];
548
- const wantReference = reference && (args.dockerfile === undefined || errors.length > 0);
723
+ // A known-good starting point when there is nothing to check, or what was
724
+ // checked is broken. Only for engines with a real default binary name.
725
+ const reference = engine !== 'other' && (args.dockerfile === undefined || errors.length > 0)
726
+ ? generateDockerfile({ engine, ports: args.ports, netcode: args.netcode }).dockerfile
727
+ : undefined;
549
728
  const verdict = errors.length > 0 ? 'fail' : warnings.length > 0 ? 'pass_with_warnings' : 'pass';
550
729
  return ok({
551
730
  verdict,
@@ -558,9 +737,10 @@ export function registerTools(server, client, config, auth) {
558
737
  resources: args.cpu_units !== undefined || args.memory_mb !== undefined,
559
738
  image: args.docker_tag !== undefined || args.docker_image !== undefined,
560
739
  },
561
- reference_dockerfile: wantReference ? reference : undefined,
740
+ reference_dockerfile: reference,
562
741
  next_step: verdict === 'fail'
563
- ? 'Fix every error and call this again before building. Do not build or push an image that fails here.'
742
+ ? 'Fix every error and call this again before building. Do not build or push an image that ' +
743
+ 'fails here. edgegap_generate_dockerfile can write a correct one for this project.'
564
744
  : 'Build with "docker build --platform linux/amd64 -t <image>:<unique-tag> ." and run it ' +
565
745
  'locally with the same port mapping to confirm it starts. Then push it; ' +
566
746
  'edgegap_get_registry_credentials gives you a registry and the exact commands.',
@@ -673,12 +853,17 @@ export function registerTools(server, client, config, auth) {
673
853
  // --------------------------------------------------------------- 14 ----
674
854
  if (mutating) {
675
855
  server.registerTool('edgegap_create_relay_session', {
676
- title: 'Create a relay session for a peer-to-peer game',
677
- description: 'Create an Edgegap relay session so players in a peer-to-peer or host-client game connect ' +
678
- 'through the nearest relay instead of needing NAT punch-through or a dedicated server. ' +
679
- 'Use this for co-op and P2P games; use edgegap_deploy for dedicated servers. Needs no ' +
680
- 'application, version or image. Pass every player\'s public IP, host first. Waits until ' +
681
- 'the relay is ready and returns its address plus a per-player authorization token for the ' +
856
+ title: 'Create a relay session (host-client games only)',
857
+ description: 'A relay is NOT a game server and is not the recommended default — for a multiplayer ' +
858
+ 'match, deploy an authoritative dedicated server with edgegap_deploy instead. A relay ' +
859
+ 'only forwards traffic between players while one player\'s game acts as host and owns ' +
860
+ 'the game state: the host can cheat and has a latency advantage, the host\'s PC and ' +
861
+ 'connection cap the match, and the match ends if the host quits. Only use this when the ' +
862
+ 'developer has chosen peer-to-peer/host-client, or the netcode is already a listen ' +
863
+ 'server and a dedicated server is not an option; if that has not been established, ask ' +
864
+ 'first. Never pick it only because it needs no server image. ' +
865
+ 'Creates an Edgegap relay session for every player\'s public IP, host first, waits until ' +
866
+ 'it is ready, and returns the relay address plus per-player authorization tokens for the ' +
682
867
  'relay transport. Relay sessions are billed while open: delete test sessions with ' +
683
868
  'edgegap_delete_relay_session when finished.',
684
869
  inputSchema: {
@@ -776,8 +961,8 @@ export function registerTools(server, client, config, auth) {
776
961
  'longer a player waits. Checks the referenced application version exists and has ports. ' +
777
962
  'Edgegap has no API for creating a matchmaker, so this tool does NOT create one: save the ' +
778
963
  'returned config to a file (e.g. matchmaker-config.json) and have the developer upload it ' +
779
- 'on the Matchmaker page of the dashboard. Use it for dedicated-server games; P2P games ' +
780
- 'want edgegap_create_relay_session instead.',
964
+ 'on the Matchmaker page of the dashboard. The matchmaker starts an authoritative dedicated ' +
965
+ 'server for each match, which is the recommended setup for multiplayer games.',
781
966
  inputSchema: {
782
967
  profile_name: z.string().describe('Profile clients will queue into, e.g. "casual-2v2".'),
783
968
  application: z.string().describe('Application the matchmaker deploys.'),
@@ -875,5 +1060,8 @@ function compactRelay(s) {
875
1060
  'token, and each player\'s own authorization token. The host connects on server_port; ' +
876
1061
  'every other player connects on client_port.'
877
1062
  : undefined,
1063
+ architecture_note: 'This is a relay, not a game server: the host player\'s game owns the match. If the ' +
1064
+ 'developer has not explicitly chosen host-client, tell them about the trade-offs. ' +
1065
+ ARCHITECTURE_GUIDANCE,
878
1066
  };
879
1067
  }
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "@edgegap/mcp",
3
3
  "mcpName": "dev.edgegap/mcp",
4
- "version": "0.2.0",
4
+ "version": "0.3.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",
8
- "build": "tsc && chmod +x dist/index.js",
8
+ "build": "tsc && chmod +x dist/index.js dist/http.js",
9
9
  "typecheck": "tsc --noEmit",
10
10
  "typecheck:worker": "tsc -p worker/tsconfig.json --noEmit",
11
- "test": "node smoke.mjs && node guards.mjs && node elicit.mjs && node newtools.mjs",
11
+ "test": "node test/smoke.mjs && node test/guards.mjs && node test/elicit.mjs && node test/newtools.mjs && node test/http.mjs",
12
+ "start:http": "node dist/http.js",
12
13
  "worker:dev": "wrangler dev --config worker/wrangler.jsonc --local --port 8787",
13
14
  "worker:check": "wrangler deploy --config worker/wrangler.jsonc --dry-run --outdir=.wrangler/dryrun",
14
15
  "worker:deploy": "wrangler deploy --config worker/wrangler.jsonc",
@@ -38,7 +39,8 @@
38
39
  },
39
40
  "type": "module",
40
41
  "bin": {
41
- "edgegap-mcp": "dist/index.js"
42
+ "edgegap-mcp": "dist/index.js",
43
+ "edgegap-mcp-http": "dist/http.js"
42
44
  },
43
45
  "files": [
44
46
  "dist",