@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/LICENSE +201 -201
- package/README.md +211 -237
- package/dist/dockerfile.js +185 -0
- package/dist/hosted.js +61 -0
- package/dist/http.js +122 -0
- package/dist/index.js +2 -30
- package/dist/serverconfig.js +4 -48
- package/dist/tools.js +214 -26
- package/package.json +6 -4
|
@@ -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/hosted.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-request token handling shared by the two hosted transports: the
|
|
3
|
+
* Cloudflare Worker (worker/worker.ts) and the Node HTTP server (src/http.ts).
|
|
4
|
+
*
|
|
5
|
+
* Neither has an ambient credential. Each request carries the developer's own
|
|
6
|
+
* Edgegap token in its Authorization header, and it is used for that request
|
|
7
|
+
* and discarded. See worker/DECISION.md.
|
|
8
|
+
*/
|
|
9
|
+
const TOKEN_URL = 'https://app.edgegap.com/user-settings?tab=tokens';
|
|
10
|
+
/**
|
|
11
|
+
* Edgegap API tokens are UUIDs. The strict form is the real test; the loose
|
|
12
|
+
* form exists so a future token format does not silently stop working here.
|
|
13
|
+
*
|
|
14
|
+
* The point of this check is NOT security — an invalid token fails upstream
|
|
15
|
+
* anyway. It is to tell a foreign credential apart from an Edgegap one BEFORE
|
|
16
|
+
* relaying it, so the developer gets "your client sent its own token" instead
|
|
17
|
+
* of Edgegap's generic 401. JWTs are the common case: they are what MCP clients
|
|
18
|
+
* mint for themselves, and they always carry dots, which a UUID never does.
|
|
19
|
+
*/
|
|
20
|
+
const STRICT_UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
21
|
+
const LOOSE_OPAQUE = /^[A-Za-z0-9_-]{16,200}$/;
|
|
22
|
+
function looksLikeEdgegapToken(value) {
|
|
23
|
+
if (STRICT_UUID.test(value))
|
|
24
|
+
return true;
|
|
25
|
+
return LOOSE_OPAQUE.test(value);
|
|
26
|
+
}
|
|
27
|
+
export function extractToken(header) {
|
|
28
|
+
if (!header)
|
|
29
|
+
return { token: undefined, problem: 'absent' };
|
|
30
|
+
const value = header.replace(/^Bearer\s+/i, '').replace(/^token\s+/i, '').trim();
|
|
31
|
+
if (!value)
|
|
32
|
+
return { token: undefined, problem: 'absent' };
|
|
33
|
+
if (!looksLikeEdgegapToken(value))
|
|
34
|
+
return { token: undefined, problem: 'foreign' };
|
|
35
|
+
return { token: value };
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The message an agent sees when it calls a tool without a usable credential.
|
|
39
|
+
* It is the only place the developer is told what to do, so it says it in full
|
|
40
|
+
* rather than pointing at docs.
|
|
41
|
+
*/
|
|
42
|
+
export function unavailableMessage(problem) {
|
|
43
|
+
const common = `Get a token at ${TOKEN_URL}. It is used for the request and discarded — ` +
|
|
44
|
+
'never stored. Edgegap tokens are organization-wide and cannot be scoped, ' +
|
|
45
|
+
'so prefer the local server (npx -y @edgegap/mcp), which keeps the token ' +
|
|
46
|
+
'on your own machine and never sends it through Edgegap infrastructure.';
|
|
47
|
+
if (problem === 'foreign') {
|
|
48
|
+
return ('The Authorization header on this connection does not contain an Edgegap ' +
|
|
49
|
+
'API token — it looks like a credential your MCP client issued for ' +
|
|
50
|
+
'itself. That happens with clients that connect by URL alone and have no ' +
|
|
51
|
+
'field for a custom header. This server was not going to relay it to the ' +
|
|
52
|
+
'Edgegap API, because the only thing that produces is a confusing 401.\n\n' +
|
|
53
|
+
'If your client cannot attach your own Edgegap token to the connection, ' +
|
|
54
|
+
'it cannot use this hosted server: run the local one instead ' +
|
|
55
|
+
'(npx -y @edgegap/mcp).\n\n' +
|
|
56
|
+
common);
|
|
57
|
+
}
|
|
58
|
+
return ('No Edgegap API token on this request. Send it as an Authorization header ' +
|
|
59
|
+
'on the MCP connection.\n\n' +
|
|
60
|
+
common);
|
|
61
|
+
}
|
package/dist/http.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Edgegap MCP server over Streamable HTTP, for self-hosting (Docker, a VM).
|
|
4
|
+
*
|
|
5
|
+
* The same stateless design as the Cloudflare Worker: no ambient credential,
|
|
6
|
+
* the developer's token comes in on each request's Authorization header and is
|
|
7
|
+
* discarded with it, and discovery (initialize, tools/list) works without one.
|
|
8
|
+
* Read worker/DECISION.md before exposing this beyond a private network.
|
|
9
|
+
*
|
|
10
|
+
* Environment: PORT (default 8080), HOST (default 0.0.0.0), plus the same
|
|
11
|
+
* EDGEGAP_* variables as the local server. EDGEGAP_API_TOKEN is ignored here.
|
|
12
|
+
*/
|
|
13
|
+
import { createServer } from 'node:http';
|
|
14
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
15
|
+
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
|
16
|
+
import { loadConfig, ConfigError } from './config.js';
|
|
17
|
+
import { EdgegapClient } from './client.js';
|
|
18
|
+
import { registerTools, serverInstructions } from './tools.js';
|
|
19
|
+
import { StaticTokenProvider } from './auth.js';
|
|
20
|
+
import { extractToken, unavailableMessage } from './hosted.js';
|
|
21
|
+
const MAX_BODY_BYTES = 1_000_000;
|
|
22
|
+
function readBody(req) {
|
|
23
|
+
return new Promise((resolve, reject) => {
|
|
24
|
+
let size = 0;
|
|
25
|
+
const chunks = [];
|
|
26
|
+
req.on('data', (chunk) => {
|
|
27
|
+
size += chunk.length;
|
|
28
|
+
if (size > MAX_BODY_BYTES) {
|
|
29
|
+
reject(new Error('request body too large'));
|
|
30
|
+
req.destroy();
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
chunks.push(chunk);
|
|
34
|
+
});
|
|
35
|
+
req.on('end', () => {
|
|
36
|
+
const raw = Buffer.concat(chunks).toString('utf8');
|
|
37
|
+
try {
|
|
38
|
+
resolve(raw ? JSON.parse(raw) : undefined);
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
reject(new Error('request body is not valid JSON'));
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
req.on('error', reject);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
function sendJsonRpcError(res, status, message) {
|
|
48
|
+
res.writeHead(status, { 'Content-Type': 'application/json' });
|
|
49
|
+
res.end(JSON.stringify({ jsonrpc: '2.0', error: { code: -32000, message }, id: null }));
|
|
50
|
+
}
|
|
51
|
+
function main() {
|
|
52
|
+
let config;
|
|
53
|
+
try {
|
|
54
|
+
// No ambient credential, by design: every token comes from the request.
|
|
55
|
+
config = { ...loadConfig(), envToken: undefined };
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
if (err instanceof ConfigError) {
|
|
59
|
+
process.stderr.write(`[edgegap-mcp] ${err.message}\n`);
|
|
60
|
+
process.exit(1);
|
|
61
|
+
}
|
|
62
|
+
throw err;
|
|
63
|
+
}
|
|
64
|
+
const port = Number.parseInt(process.env.PORT ?? '8080', 10);
|
|
65
|
+
const host = process.env.HOST ?? '0.0.0.0';
|
|
66
|
+
const httpServer = createServer(async (req, res) => {
|
|
67
|
+
const { pathname } = new URL(req.url ?? '/', 'http://localhost');
|
|
68
|
+
// Token-free, so health checks need no credential.
|
|
69
|
+
if (pathname === '/health') {
|
|
70
|
+
res.writeHead(200, { 'Content-Type': 'text/plain' }).end('ok');
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
// startsWith, not strict equality: Streamable HTTP uses subpaths.
|
|
74
|
+
if (!pathname.startsWith('/mcp')) {
|
|
75
|
+
res.writeHead(404, { 'Content-Type': 'text/plain' }).end('Not found');
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
// Stateless: no sessions, so the GET stream and DELETE have nothing to attach to.
|
|
79
|
+
if (req.method !== 'POST') {
|
|
80
|
+
res.setHeader('Allow', 'POST');
|
|
81
|
+
sendJsonRpcError(res, 405, 'Method not allowed. This server is stateless; use POST.');
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
let body;
|
|
85
|
+
try {
|
|
86
|
+
body = await readBody(req);
|
|
87
|
+
}
|
|
88
|
+
catch (err) {
|
|
89
|
+
sendJsonRpcError(res, 400, err.message);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const { token, problem } = extractToken(req.headers.authorization);
|
|
93
|
+
const auth = new StaticTokenProvider(token, problem ? unavailableMessage(problem) : undefined);
|
|
94
|
+
const server = new McpServer({ name: 'edgegap', version: '0.3.0' }, { instructions: serverInstructions('hosted') });
|
|
95
|
+
registerTools(server, new EdgegapClient(config, auth), config, auth);
|
|
96
|
+
const transport = new StreamableHTTPServerTransport({
|
|
97
|
+
sessionIdGenerator: undefined,
|
|
98
|
+
enableJsonResponse: true,
|
|
99
|
+
});
|
|
100
|
+
res.on('close', () => {
|
|
101
|
+
void transport.close();
|
|
102
|
+
void server.close();
|
|
103
|
+
});
|
|
104
|
+
try {
|
|
105
|
+
await server.connect(transport);
|
|
106
|
+
await transport.handleRequest(req, res, body);
|
|
107
|
+
}
|
|
108
|
+
catch (err) {
|
|
109
|
+
// Never echo the error: HTTP layers sometimes include request headers.
|
|
110
|
+
process.stderr.write(`[edgegap-mcp] request failed: ${err.name}\n`);
|
|
111
|
+
if (!res.headersSent)
|
|
112
|
+
sendJsonRpcError(res, 500, 'Internal server error');
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
httpServer.listen(port, host, () => {
|
|
116
|
+
process.stderr.write(`[edgegap-mcp] listening on http://${host}:${port}/mcp\n`);
|
|
117
|
+
});
|
|
118
|
+
const shutdown = () => httpServer.close(() => process.exit(0));
|
|
119
|
+
process.on('SIGTERM', shutdown);
|
|
120
|
+
process.on('SIGINT', shutdown);
|
|
121
|
+
}
|
|
122
|
+
main();
|
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.
|
|
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.3.0' }, { 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 = [];
|