@edgegap/mcp 0.2.0 → 0.2.2
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/LICENSE +201 -201
- package/README.md +341 -303
- package/dist/dockerfile.js +185 -0
- package/dist/index.js +2 -30
- package/dist/serverconfig.js +4 -48
- package/dist/tools.js +177 -19
- package/package.json +1 -1
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a game server Dockerfile for a specific project.
|
|
3
|
+
*
|
|
4
|
+
* The validator in serverconfig.ts tells an agent what is wrong with a
|
|
5
|
+
* Dockerfile; this writes one that is right to begin with, for the project's
|
|
6
|
+
* actual build folder, binary name, ports and launch arguments, so the agent
|
|
7
|
+
* does not have to adapt a fixed template by trial and error.
|
|
8
|
+
*
|
|
9
|
+
* Unity and Unreal output follows the Dockerfiles Edgegap ships in its engine
|
|
10
|
+
* plugins. Godot and "other" follow the same conventions. Every template must
|
|
11
|
+
* pass validateServerConfig; newtools.mjs enforces that.
|
|
12
|
+
*/
|
|
13
|
+
import { protocolForNetcode } from './serverconfig.js';
|
|
14
|
+
// Every value below is interpolated into Dockerfile lines, and launch_args into
|
|
15
|
+
// a shell command for Unity, so each is restricted to characters that cannot
|
|
16
|
+
// start a new instruction, quote out of an argument, or run a subshell.
|
|
17
|
+
const PATH_RE = /^[A-Za-z0-9._\-/]+$/;
|
|
18
|
+
const FILE_RE = /^[A-Za-z0-9._-]+$/;
|
|
19
|
+
const ARG_RE = /^[A-Za-z0-9._\-=:/,+@]+$/;
|
|
20
|
+
const IMAGE_RE = /^[a-z0-9][a-z0-9._\-/:@]*$/;
|
|
21
|
+
const DEFAULTS = {
|
|
22
|
+
unity: { build_path: 'Builds/EdgegapServer', executable: 'ServerBuild' },
|
|
23
|
+
unreal: { build_path: '.', executable: 'StartServer.sh' },
|
|
24
|
+
godot: { build_path: 'build', executable: 'server.x86_64' },
|
|
25
|
+
other: { build_path: 'build' },
|
|
26
|
+
};
|
|
27
|
+
export class DockerfileInputError extends Error {
|
|
28
|
+
}
|
|
29
|
+
function exposeLines(ports) {
|
|
30
|
+
const lines = [];
|
|
31
|
+
for (const p of ports) {
|
|
32
|
+
const proto = p.protocol.toUpperCase();
|
|
33
|
+
if (proto === 'TCP/UDP')
|
|
34
|
+
lines.push(`EXPOSE ${p.port}/udp`, `EXPOSE ${p.port}/tcp`);
|
|
35
|
+
else
|
|
36
|
+
lines.push(`EXPOSE ${p.port}/${proto === 'UDP' ? 'udp' : 'tcp'}`);
|
|
37
|
+
}
|
|
38
|
+
return lines;
|
|
39
|
+
}
|
|
40
|
+
/** Linux packages every template installs: CA certificates, so the server can
|
|
41
|
+
* call HTTPS APIs (Edgegap's context API, backends, analytics). */
|
|
42
|
+
const APT = [
|
|
43
|
+
'RUN apt-get update && \\',
|
|
44
|
+
' apt-get install -y --no-install-recommends ca-certificates && \\',
|
|
45
|
+
' apt-get clean && rm -rf /var/lib/apt/lists/*',
|
|
46
|
+
];
|
|
47
|
+
/** Unprivileged user. Required for Unreal, good practice everywhere else. */
|
|
48
|
+
const USER_SETUP = 'RUN useradd -m -u 1000 server';
|
|
49
|
+
export function generateDockerfile(input) {
|
|
50
|
+
const engine = input.engine;
|
|
51
|
+
const defaults = DEFAULTS[engine];
|
|
52
|
+
const assumptions = [];
|
|
53
|
+
const buildPath = input.build_path ?? defaults.build_path;
|
|
54
|
+
const executable = input.executable ?? defaults.executable;
|
|
55
|
+
const base = input.base_image ?? 'ubuntu:22.04';
|
|
56
|
+
const args = input.launch_args ?? [];
|
|
57
|
+
if (!executable) {
|
|
58
|
+
throw new DockerfileInputError('executable is required for engine "other": the file name of the server binary or start script inside build_path.');
|
|
59
|
+
}
|
|
60
|
+
if (!PATH_RE.test(buildPath) || buildPath.split('/').includes('..') || buildPath.startsWith('/')) {
|
|
61
|
+
throw new DockerfileInputError(`build_path "${buildPath}" must be a relative path inside the Docker build context (letters, digits, ".", "_", "-", "/"; no "..").`);
|
|
62
|
+
}
|
|
63
|
+
if (!FILE_RE.test(executable)) {
|
|
64
|
+
throw new DockerfileInputError(`executable "${executable}" must be a plain file name (letters, digits, ".", "_", "-").`);
|
|
65
|
+
}
|
|
66
|
+
for (const a of args) {
|
|
67
|
+
if (!ARG_RE.test(a)) {
|
|
68
|
+
throw new DockerfileInputError(`launch argument "${a}" contains characters that are not allowed (spaces, quotes, $, ;, |, &, backticks). Pass each argument separately.`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (!IMAGE_RE.test(base)) {
|
|
72
|
+
throw new DockerfileInputError(`base_image "${base}" is not a valid image reference.`);
|
|
73
|
+
}
|
|
74
|
+
// ------------------------------------------------------------- ports ----
|
|
75
|
+
let ports;
|
|
76
|
+
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
|
+
}));
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
const protocol = (input.netcode && protocolForNetcode(input.netcode)) || 'UDP';
|
|
85
|
+
ports = [{ port: 7777, protocol, name: 'gameport' }];
|
|
86
|
+
assumptions.push(`Assumed the server listens on 7777/${protocol}${input.netcode ? ` (the protocol ${input.netcode} uses)` : ''}. ` +
|
|
87
|
+
'Confirm the port in the server\'s network/transport settings and pass ports if it differs.');
|
|
88
|
+
}
|
|
89
|
+
// --------------------------------------------------------- templates ----
|
|
90
|
+
const expose = exposeLines(ports);
|
|
91
|
+
let lines;
|
|
92
|
+
if (engine === 'unity') {
|
|
93
|
+
// Shell form so $UNITY_COMMANDLINE_ARGS (settable per deployment) expands.
|
|
94
|
+
// Edgegap's plugin template also prints `env` first; that is left out on
|
|
95
|
+
// purpose, since it writes every environment variable, hidden ones
|
|
96
|
+
// included, into the container logs.
|
|
97
|
+
const command = [`/root/build/${executable}`, '-batchmode', '-nographics', ...args, '$UNITY_COMMANDLINE_ARGS'].join(' ');
|
|
98
|
+
lines = [
|
|
99
|
+
`FROM ${base}`,
|
|
100
|
+
'',
|
|
101
|
+
'ARG DEBIAN_FRONTEND=noninteractive',
|
|
102
|
+
...APT,
|
|
103
|
+
'',
|
|
104
|
+
`# Linux Dedicated Server build folder (${executable}, *_Data, UnityPlayer.so).`,
|
|
105
|
+
`COPY ${buildPath} /root/build/`,
|
|
106
|
+
'WORKDIR /root/',
|
|
107
|
+
`RUN chmod +x /root/build/${executable}`,
|
|
108
|
+
'',
|
|
109
|
+
'# Documentation only: the port Edgegap exposes is the one on the app version.',
|
|
110
|
+
...expose,
|
|
111
|
+
'',
|
|
112
|
+
`CMD ["/bin/bash", "-c", "${command}"]`,
|
|
113
|
+
];
|
|
114
|
+
if (input.executable === undefined) {
|
|
115
|
+
assumptions.push('Assumed the server binary is named "ServerBuild". Unity names it after the build file you chose; check the build folder and pass executable if it differs.');
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
else if (engine === 'unreal') {
|
|
119
|
+
const isScript = executable.endsWith('.sh');
|
|
120
|
+
lines = [
|
|
121
|
+
`FROM ${base}`,
|
|
122
|
+
'',
|
|
123
|
+
'ARG DEBIAN_FRONTEND=noninteractive',
|
|
124
|
+
...APT,
|
|
125
|
+
'',
|
|
126
|
+
'# Unreal refuses to start as root.',
|
|
127
|
+
USER_SETUP,
|
|
128
|
+
'WORKDIR /app',
|
|
129
|
+
`COPY --chown=server:server ${buildPath} /app/`,
|
|
130
|
+
isScript
|
|
131
|
+
? `# Scripts saved on Windows carry CRLF endings, which break the shebang.\nRUN sed -i 's/\\r$//' /app/${executable} && chmod +x /app/${executable}`
|
|
132
|
+
: `RUN chmod +x /app/${executable}`,
|
|
133
|
+
'USER server',
|
|
134
|
+
'',
|
|
135
|
+
'# Documentation only: the port Edgegap exposes is the one on the app version.',
|
|
136
|
+
...expose,
|
|
137
|
+
'',
|
|
138
|
+
`CMD ${JSON.stringify([`/app/${executable}`, ...args])}`,
|
|
139
|
+
];
|
|
140
|
+
if (input.executable === undefined) {
|
|
141
|
+
assumptions.push('Assumed StartServer.sh, which the Edgegap Unreal plugin generates. Without the plugin, use the <Project>Server.sh from the packaged LinuxServer folder.');
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
// Godot and other engines: same shape as Unreal, minus the CRLF fix
|
|
146
|
+
// unless the entry point is a script.
|
|
147
|
+
const isScript = executable.endsWith('.sh');
|
|
148
|
+
const launch = engine === 'godot' ? [`/app/${executable}`, '--headless', ...args] : [`/app/${executable}`, ...args];
|
|
149
|
+
lines = [
|
|
150
|
+
`FROM ${base}`,
|
|
151
|
+
'',
|
|
152
|
+
'ARG DEBIAN_FRONTEND=noninteractive',
|
|
153
|
+
...APT,
|
|
154
|
+
'',
|
|
155
|
+
USER_SETUP,
|
|
156
|
+
'WORKDIR /app',
|
|
157
|
+
`COPY --chown=server:server ${buildPath} /app/`,
|
|
158
|
+
isScript
|
|
159
|
+
? `RUN sed -i 's/\\r$//' /app/${executable} && chmod +x /app/${executable}`
|
|
160
|
+
: `RUN chmod +x /app/${executable}`,
|
|
161
|
+
'USER server',
|
|
162
|
+
'',
|
|
163
|
+
'# Documentation only: the port Edgegap exposes is the one on the app version.',
|
|
164
|
+
...expose,
|
|
165
|
+
'',
|
|
166
|
+
`CMD ${JSON.stringify(launch)}`,
|
|
167
|
+
];
|
|
168
|
+
if (engine === 'godot') {
|
|
169
|
+
assumptions.push('Export with the Linux x86_64 preset. If the .pck is exported separately, keep it next to the binary in the build folder.');
|
|
170
|
+
if (input.executable === undefined) {
|
|
171
|
+
assumptions.push('Assumed the exported binary is named "server.x86_64"; pass executable if yours differs.');
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
assumptions.push(buildPath === '.'
|
|
176
|
+
? 'Run docker build from inside the server build folder (the folder itself is the build context).'
|
|
177
|
+
: `Run docker build from the folder that contains ${buildPath}.`);
|
|
178
|
+
return {
|
|
179
|
+
dockerfile: lines.join('\n') + '\n',
|
|
180
|
+
ports,
|
|
181
|
+
assumptions,
|
|
182
|
+
build_path: buildPath,
|
|
183
|
+
executable,
|
|
184
|
+
};
|
|
185
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
|
14
14
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
15
15
|
import { loadConfig, ConfigError } from './config.js';
|
|
16
16
|
import { EdgegapClient } from './client.js';
|
|
17
|
-
import { registerTools } from './tools.js';
|
|
17
|
+
import { registerTools, serverInstructions } from './tools.js';
|
|
18
18
|
import { TokenProvider, warnIfTokenInArgv } from './auth.js';
|
|
19
19
|
async function main() {
|
|
20
20
|
let config;
|
|
@@ -29,35 +29,7 @@ async function main() {
|
|
|
29
29
|
}
|
|
30
30
|
throw err;
|
|
31
31
|
}
|
|
32
|
-
const server = new McpServer({ name: 'edgegap', version: '0.2.
|
|
33
|
-
instructions: 'Host multiplayer games on Edgegap: dedicated servers, or relays for peer-to-peer.\n\n' +
|
|
34
|
-
'Pick the path first. Peer-to-peer and host-client games (common for co-op) need no ' +
|
|
35
|
-
"server image: call edgegap_create_relay_session with the players' public IPs and " +
|
|
36
|
-
'configure the relay transport with what it returns. Dedicated-server games follow ' +
|
|
37
|
-
'the golden path below.\n\n' +
|
|
38
|
-
'Golden path for a first dedicated-server deployment:\n' +
|
|
39
|
-
'1. edgegap_validate_server_config on the Dockerfile and ports, before building\n' +
|
|
40
|
-
'2. edgegap_get_registry_credentials, then docker build --platform linux/amd64 and push\n' +
|
|
41
|
-
'3. edgegap_list_registry_tags to confirm the push landed\n' +
|
|
42
|
-
'4. edgegap_list_apps, then edgegap_create_app if no suitable application exists\n' +
|
|
43
|
-
'5. edgegap_create_app_version to register the image\n' +
|
|
44
|
-
'6. edgegap_deploy to start an instance near the players\n' +
|
|
45
|
-
'7. edgegap_wait_for_deployment to get the connection address\n' +
|
|
46
|
-
'8. edgegap_stop_deployment when finished\n' +
|
|
47
|
-
'To match players into those servers, edgegap_build_matchmaker_config produces the ' +
|
|
48
|
-
'config the developer uploads in the dashboard.\n\n' +
|
|
49
|
-
'Deployments and relay sessions cost money while running. Tag test deployments, and ' +
|
|
50
|
-
'stop deployments and delete relay sessions you created before ending the task. If a ' +
|
|
51
|
-
'deployment errors, read the container logs before redeploying.\n\n' +
|
|
52
|
-
'Credentials: if no token was configured, the first tool call asks the ' +
|
|
53
|
-
'developer for one. That token is org-wide and cannot be scoped by ' +
|
|
54
|
-
'Edgegap, so it authorises far more than any single task needs. Treat it ' +
|
|
55
|
-
'as a supervised credential: do not use it for work the developer did ' +
|
|
56
|
-
'not ask for, do not enumerate or modify unrelated applications, and do ' +
|
|
57
|
-
'not repeat operations against it to explore what is possible. If the ' +
|
|
58
|
-
'developer declines to provide a token, stop and report which operation ' +
|
|
59
|
-
'needed it — do not retry.',
|
|
60
|
-
});
|
|
32
|
+
const server = new McpServer({ name: 'edgegap', version: '0.2.2' }, { instructions: serverInstructions('local') });
|
|
61
33
|
warnIfTokenInArgv();
|
|
62
34
|
const auth = new TokenProvider(config);
|
|
63
35
|
auth.attach(server.server);
|
package/dist/serverconfig.js
CHANGED
|
@@ -36,54 +36,10 @@ const NETCODE_PROTOCOL = {
|
|
|
36
36
|
'godot-websocket': 'WS',
|
|
37
37
|
};
|
|
38
38
|
export const NETCODE_NAMES = Object.keys(NETCODE_PROTOCOL);
|
|
39
|
-
/**
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
'FROM ubuntu:22.04',
|
|
44
|
-
'',
|
|
45
|
-
'ARG DEBIAN_FRONTEND=noninteractive',
|
|
46
|
-
'# Folder containing the Linux Dedicated Server build (ServerBuild, *_Data, UnityPlayer.so).',
|
|
47
|
-
'ARG SERVER_BUILD_PATH=Builds/EdgegapServer',
|
|
48
|
-
'',
|
|
49
|
-
'COPY ${SERVER_BUILD_PATH} /root/build/',
|
|
50
|
-
'WORKDIR /root/',
|
|
51
|
-
'RUN chmod +x /root/build/ServerBuild',
|
|
52
|
-
'',
|
|
53
|
-
'RUN apt-get update && \\',
|
|
54
|
-
' apt-get install -y ca-certificates && \\',
|
|
55
|
-
' apt-get clean && \\',
|
|
56
|
-
' update-ca-certificates',
|
|
57
|
-
'',
|
|
58
|
-
'# Documentation only; the port that matters is the one on the app version.',
|
|
59
|
-
'EXPOSE 7777/udp',
|
|
60
|
-
'',
|
|
61
|
-
'CMD ["/bin/bash", "-c", "env;/root/build/ServerBuild -batchmode -nographics $UNITY_COMMANDLINE_ARGS"]',
|
|
62
|
-
].join('\n'),
|
|
63
|
-
unreal: [
|
|
64
|
-
'FROM ubuntu:22.04',
|
|
65
|
-
'',
|
|
66
|
-
'RUN apt-get update && \\',
|
|
67
|
-
' apt-get install -y sudo jq curl && \\',
|
|
68
|
-
' apt-get clean && \\',
|
|
69
|
-
' rm -rf /var/lib/{apt,dpkg,cache,log}/',
|
|
70
|
-
'',
|
|
71
|
-
'# Unreal refuses to start as root, so run as an unprivileged user.',
|
|
72
|
-
'RUN useradd -rm -d /home/ubuntu -s /bin/bash -g root -G sudo -u 1000 m -o',
|
|
73
|
-
'',
|
|
74
|
-
'WORKDIR /app',
|
|
75
|
-
'# Contents of the packaged LinuxServer folder, plus StartServer.sh.',
|
|
76
|
-
'COPY --chown=m:sudo . /app',
|
|
77
|
-
'',
|
|
78
|
-
'# Scripts written on Windows carry CRLF endings, which break the shebang.',
|
|
79
|
-
"RUN sed -i 's/\\r$//' /app/StartServer.sh && chmod +x /app/StartServer.sh",
|
|
80
|
-
'',
|
|
81
|
-
'USER m',
|
|
82
|
-
'EXPOSE 7777/udp',
|
|
83
|
-
'',
|
|
84
|
-
'CMD ./StartServer.sh',
|
|
85
|
-
].join('\n'),
|
|
86
|
-
};
|
|
39
|
+
/** Protocol a netcode transport needs on the wire, or undefined if unknown. */
|
|
40
|
+
export function protocolForNetcode(netcode) {
|
|
41
|
+
return NETCODE_PROTOCOL[netcode.toLowerCase()];
|
|
42
|
+
}
|
|
87
43
|
/** Joins backslash continuations and drops comments, keeping the start line. */
|
|
88
44
|
function parseDockerfile(text) {
|
|
89
45
|
const out = [];
|
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
|
|
4
|
-
*
|
|
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,
|
|
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
|
|
325
|
-
'you specify.
|
|
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: {
|
|
@@ -504,6 +563,93 @@ export function registerTools(server, client, config, auth) {
|
|
|
504
563
|
});
|
|
505
564
|
}));
|
|
506
565
|
// ============================================= before the first deploy ====
|
|
566
|
+
// -------------------------------------------------------------- 11a ----
|
|
567
|
+
// Pure text generation: no token, no network, so it is always registered and
|
|
568
|
+
// never goes through guard().
|
|
569
|
+
server.registerTool('edgegap_generate_dockerfile', {
|
|
570
|
+
title: 'Generate a game server Dockerfile',
|
|
571
|
+
description: 'Write a Dockerfile for this project\'s headless game server build, ready for Edgegap: ' +
|
|
572
|
+
'linux/amd64 base, the build folder copied in, the binary made executable, the right ' +
|
|
573
|
+
'headless flags (Unity -batchmode -nographics, Godot --headless), a non-root user where ' +
|
|
574
|
+
'the engine needs it (Unreal refuses root), CRLF fixes for start scripts, and EXPOSE ' +
|
|
575
|
+
'lines matching the ports. Call this when the project has no Dockerfile, before ' +
|
|
576
|
+
'building anything. Look at the build output first so you can pass the real build ' +
|
|
577
|
+
'folder, binary name and port; anything you omit is assumed and listed under ' +
|
|
578
|
+
'assumptions, which you must confirm with the developer or the project files. Write the ' +
|
|
579
|
+
'result to Dockerfile, then build. The output is checked against ' +
|
|
580
|
+
'edgegap_validate_server_config before it is returned. Makes no API calls.',
|
|
581
|
+
inputSchema: {
|
|
582
|
+
engine: z.enum(['unity', 'unreal', 'godot', 'other']).describe('Game engine of the server build.'),
|
|
583
|
+
build_path: z
|
|
584
|
+
.string()
|
|
585
|
+
.optional()
|
|
586
|
+
.describe('Server build folder, relative to where docker build runs. Defaults: unity ' +
|
|
587
|
+
'"Builds/EdgegapServer", unreal "." (run from inside the packaged LinuxServer folder), godot "build".'),
|
|
588
|
+
executable: z
|
|
589
|
+
.string()
|
|
590
|
+
.optional()
|
|
591
|
+
.describe('File name of the server binary or start script inside build_path. Defaults: unity ' +
|
|
592
|
+
'"ServerBuild", unreal "StartServer.sh", godot "server.x86_64". Required for "other".'),
|
|
593
|
+
ports: z
|
|
594
|
+
.array(z.object({
|
|
595
|
+
port: z.number().int().min(1).max(59999),
|
|
596
|
+
protocol: z.enum(PROTOCOLS),
|
|
597
|
+
name: z.string().optional(),
|
|
598
|
+
}))
|
|
599
|
+
.optional()
|
|
600
|
+
.describe('Ports the server listens on. Default: 7777, with the protocol the netcode uses (UDP if unknown).'),
|
|
601
|
+
netcode: z
|
|
602
|
+
.string()
|
|
603
|
+
.optional()
|
|
604
|
+
.describe(`Networking transport, to pick the protocol. Known: ${NETCODE_NAMES.join(', ')}.`),
|
|
605
|
+
launch_args: z
|
|
606
|
+
.array(z.string())
|
|
607
|
+
.optional()
|
|
608
|
+
.describe('Extra server arguments, one per entry, e.g. ["-log", "-port=7777"].'),
|
|
609
|
+
base_image: z.string().optional().describe('Default "ubuntu:22.04".'),
|
|
610
|
+
},
|
|
611
|
+
annotations: { readOnlyHint: true, idempotentHint: true, openWorldHint: false },
|
|
612
|
+
}, async (args) => {
|
|
613
|
+
let generated;
|
|
614
|
+
try {
|
|
615
|
+
generated = generateDockerfile(args);
|
|
616
|
+
}
|
|
617
|
+
catch (err) {
|
|
618
|
+
if (err instanceof DockerfileInputError)
|
|
619
|
+
return fail(err.message);
|
|
620
|
+
throw err;
|
|
621
|
+
}
|
|
622
|
+
// Never hand back something our own validator would reject.
|
|
623
|
+
const check = validateServerConfig({
|
|
624
|
+
dockerfile: generated.dockerfile,
|
|
625
|
+
engine: args.engine,
|
|
626
|
+
netcode: args.netcode,
|
|
627
|
+
ports: generated.ports,
|
|
628
|
+
});
|
|
629
|
+
if (check.errors.length > 0) {
|
|
630
|
+
return fail('The generated Dockerfile failed validation, which means these inputs combine badly:\n- ' +
|
|
631
|
+
check.errors.map((e) => `${e.message} ${e.fix}`).join('\n- '));
|
|
632
|
+
}
|
|
633
|
+
const ref = '<image>:<unique-build-tag>';
|
|
634
|
+
const portFlags = generated.ports
|
|
635
|
+
.flatMap((p) => p.protocol === 'TCP/UDP'
|
|
636
|
+
? [`-p ${p.port}:${p.port}/udp`, `-p ${p.port}:${p.port}/tcp`]
|
|
637
|
+
: [`-p ${p.port}:${p.port}/${p.protocol === 'UDP' ? 'udp' : 'tcp'}`])
|
|
638
|
+
.join(' ');
|
|
639
|
+
return ok({
|
|
640
|
+
dockerfile: generated.dockerfile,
|
|
641
|
+
assumptions: generated.assumptions,
|
|
642
|
+
warnings: check.warnings.length ? check.warnings : undefined,
|
|
643
|
+
ports_for_create_app_version: generated.ports,
|
|
644
|
+
commands: {
|
|
645
|
+
build: `docker build --platform linux/amd64 -t ${ref} .`,
|
|
646
|
+
test_locally: `docker run --rm --platform linux/amd64 ${portFlags} ${ref}`,
|
|
647
|
+
},
|
|
648
|
+
next_step: 'Confirm every assumption, write this to Dockerfile, build it, and run it locally to check ' +
|
|
649
|
+
'the server starts and stays up. Then push it (edgegap_get_registry_credentials) and ' +
|
|
650
|
+
'register it with edgegap_create_app_version using ports_for_create_app_version.',
|
|
651
|
+
});
|
|
652
|
+
});
|
|
507
653
|
// --------------------------------------------------------------- 11 ----
|
|
508
654
|
// Pure text analysis: no token, no network, so it is always registered and
|
|
509
655
|
// never goes through guard().
|
|
@@ -515,8 +661,8 @@ export function registerTools(server, client, config, auth) {
|
|
|
515
661
|
'runs linux/amd64), Unreal running as root, missing Unity -batchmode -nographics, a ' +
|
|
516
662
|
'server bound to localhost, EXPOSE ports that do not match the version ports, a protocol ' +
|
|
517
663
|
'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).
|
|
519
|
-
'
|
|
664
|
+
'Pass the Dockerfile text (read it from disk first). If there is no Dockerfile yet, call ' +
|
|
665
|
+
'edgegap_generate_dockerfile instead. Makes no API calls.',
|
|
520
666
|
inputSchema: {
|
|
521
667
|
dockerfile: z.string().optional().describe('Full text of the Dockerfile.'),
|
|
522
668
|
engine: z
|
|
@@ -544,8 +690,11 @@ export function registerTools(server, client, config, auth) {
|
|
|
544
690
|
annotations: { readOnlyHint: true, idempotentHint: true, openWorldHint: false },
|
|
545
691
|
}, async (args) => {
|
|
546
692
|
const { engine, errors, warnings } = validateServerConfig(args);
|
|
547
|
-
|
|
548
|
-
|
|
693
|
+
// A known-good starting point when there is nothing to check, or what was
|
|
694
|
+
// checked is broken. Only for engines with a real default binary name.
|
|
695
|
+
const reference = engine !== 'other' && (args.dockerfile === undefined || errors.length > 0)
|
|
696
|
+
? generateDockerfile({ engine, ports: args.ports, netcode: args.netcode }).dockerfile
|
|
697
|
+
: undefined;
|
|
549
698
|
const verdict = errors.length > 0 ? 'fail' : warnings.length > 0 ? 'pass_with_warnings' : 'pass';
|
|
550
699
|
return ok({
|
|
551
700
|
verdict,
|
|
@@ -558,9 +707,10 @@ export function registerTools(server, client, config, auth) {
|
|
|
558
707
|
resources: args.cpu_units !== undefined || args.memory_mb !== undefined,
|
|
559
708
|
image: args.docker_tag !== undefined || args.docker_image !== undefined,
|
|
560
709
|
},
|
|
561
|
-
reference_dockerfile:
|
|
710
|
+
reference_dockerfile: reference,
|
|
562
711
|
next_step: verdict === 'fail'
|
|
563
|
-
? 'Fix every error and call this again before building. Do not build or push an image that
|
|
712
|
+
? 'Fix every error and call this again before building. Do not build or push an image that ' +
|
|
713
|
+
'fails here. edgegap_generate_dockerfile can write a correct one for this project.'
|
|
564
714
|
: 'Build with "docker build --platform linux/amd64 -t <image>:<unique-tag> ." and run it ' +
|
|
565
715
|
'locally with the same port mapping to confirm it starts. Then push it; ' +
|
|
566
716
|
'edgegap_get_registry_credentials gives you a registry and the exact commands.',
|
|
@@ -673,12 +823,17 @@ export function registerTools(server, client, config, auth) {
|
|
|
673
823
|
// --------------------------------------------------------------- 14 ----
|
|
674
824
|
if (mutating) {
|
|
675
825
|
server.registerTool('edgegap_create_relay_session', {
|
|
676
|
-
title: 'Create a relay session
|
|
677
|
-
description: '
|
|
678
|
-
'
|
|
679
|
-
'
|
|
680
|
-
'
|
|
681
|
-
'
|
|
826
|
+
title: 'Create a relay session (host-client games only)',
|
|
827
|
+
description: 'A relay is NOT a game server and is not the recommended default — for a multiplayer ' +
|
|
828
|
+
'match, deploy an authoritative dedicated server with edgegap_deploy instead. A relay ' +
|
|
829
|
+
'only forwards traffic between players while one player\'s game acts as host and owns ' +
|
|
830
|
+
'the game state: the host can cheat and has a latency advantage, the host\'s PC and ' +
|
|
831
|
+
'connection cap the match, and the match ends if the host quits. Only use this when the ' +
|
|
832
|
+
'developer has chosen peer-to-peer/host-client, or the netcode is already a listen ' +
|
|
833
|
+
'server and a dedicated server is not an option; if that has not been established, ask ' +
|
|
834
|
+
'first. Never pick it only because it needs no server image. ' +
|
|
835
|
+
'Creates an Edgegap relay session for every player\'s public IP, host first, waits until ' +
|
|
836
|
+
'it is ready, and returns the relay address plus per-player authorization tokens for the ' +
|
|
682
837
|
'relay transport. Relay sessions are billed while open: delete test sessions with ' +
|
|
683
838
|
'edgegap_delete_relay_session when finished.',
|
|
684
839
|
inputSchema: {
|
|
@@ -776,8 +931,8 @@ export function registerTools(server, client, config, auth) {
|
|
|
776
931
|
'longer a player waits. Checks the referenced application version exists and has ports. ' +
|
|
777
932
|
'Edgegap has no API for creating a matchmaker, so this tool does NOT create one: save the ' +
|
|
778
933
|
'returned config to a file (e.g. matchmaker-config.json) and have the developer upload it ' +
|
|
779
|
-
'on the Matchmaker page of the dashboard.
|
|
780
|
-
'
|
|
934
|
+
'on the Matchmaker page of the dashboard. The matchmaker starts an authoritative dedicated ' +
|
|
935
|
+
'server for each match, which is the recommended setup for multiplayer games.',
|
|
781
936
|
inputSchema: {
|
|
782
937
|
profile_name: z.string().describe('Profile clients will queue into, e.g. "casual-2v2".'),
|
|
783
938
|
application: z.string().describe('Application the matchmaker deploys.'),
|
|
@@ -875,5 +1030,8 @@ function compactRelay(s) {
|
|
|
875
1030
|
'token, and each player\'s own authorization token. The host connects on server_port; ' +
|
|
876
1031
|
'every other player connects on client_port.'
|
|
877
1032
|
: undefined,
|
|
1033
|
+
architecture_note: 'This is a relay, not a game server: the host player\'s game owns the match. If the ' +
|
|
1034
|
+
'developer has not explicitly chosen host-client, tell them about the trade-offs. ' +
|
|
1035
|
+
ARCHITECTURE_GUIDANCE,
|
|
878
1036
|
};
|
|
879
1037
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@edgegap/mcp",
|
|
3
3
|
"mcpName": "dev.edgegap/mcp",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.2",
|
|
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",
|