@edgegap/mcp 0.3.2 → 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 +47 -12
- package/dist/auth.js +2 -1
- package/dist/client.js +61 -2
- package/dist/config.js +53 -4
- package/dist/dockerfile.js +24 -6
- package/dist/hosted.js +3 -1
- package/dist/http.js +7 -3
- package/dist/index.js +6 -2
- package/dist/matchmaker.js +10 -0
- package/dist/serverconfig.js +12 -0
- package/dist/tools.js +436 -68
- package/dist/version.js +6 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -82,9 +82,24 @@ claude mcp add --transport http edgegap https://mcp.edgegap.dev/mcp \
|
|
|
82
82
|
codex mcp add edgegap --url https://mcp.edgegap.dev/mcp
|
|
83
83
|
```
|
|
84
84
|
|
|
85
|
-
#### claude.ai
|
|
85
|
+
#### Claude Desktop and claude.ai
|
|
86
86
|
|
|
87
|
-
|
|
87
|
+
Custom connectors in claude.ai and Claude Desktop cannot send an `Authorization` header, so the hosted endpoint never receives your token from them: the connector shows as connected, but every tool call fails. Use the [Local Server](#local-server) instead.
|
|
88
|
+
|
|
89
|
+
In Claude Desktop, open **Settings → Developer → Edit Config** and add the local server to `claude_desktop_config.json`:
|
|
90
|
+
|
|
91
|
+
```json
|
|
92
|
+
{
|
|
93
|
+
"mcpServers": {
|
|
94
|
+
"edgegap": {
|
|
95
|
+
"command": "npx",
|
|
96
|
+
"args": ["-y", "@edgegap/mcp"]
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Leave the token out and you're asked for it on first use. claude.ai in the browser can't run a local server, so it can't use Edgegap MCP until the hosted endpoint supports OAuth.
|
|
88
103
|
|
|
89
104
|
#### mcp.json
|
|
90
105
|
|
|
@@ -142,7 +157,7 @@ To keep your API token on your own machine, run the server locally instead. Leav
|
|
|
142
157
|
}
|
|
143
158
|
```
|
|
144
159
|
|
|
145
|
-
Needs Node 18+. Pin a version in production (`@edgegap/mcp@0.
|
|
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`.
|
|
146
161
|
|
|
147
162
|
The local server can also limit what an agent can do. These variables have no effect on the hosted endpoint at `mcp.edgegap.dev`:
|
|
148
163
|
|
|
@@ -150,13 +165,17 @@ The local server can also limit what an agent can do. These variables have no ef
|
|
|
150
165
|
| --- | --- | --- |
|
|
151
166
|
| `EDGEGAP_API_TOKEN` | *(prompted)* | API token. Optional: omit it and you're asked at first use. The `token ` prefix is added for you. Never pass it as a command-line argument. |
|
|
152
167
|
| `EDGEGAP_READ_ONLY` | `0` | Set to `1` and the eight mutating tools are never registered, so the agent cannot be talked into calling them. |
|
|
153
|
-
| `EDGEGAP_APP_ALLOWLIST` | *(empty)* | Comma-separated application names. Limits what the agent can create and deploy into
|
|
168
|
+
| `EDGEGAP_APP_ALLOWLIST` | *(empty)* | Comma-separated application names. Limits what the agent can create and deploy into. Reading (listing apps and versions) is not limited, and neither is touching deployments once running. See [DESIGN.md](DESIGN.md#scope-of-the-allowlist). |
|
|
154
169
|
| `EDGEGAP_MAX_DURATION_MINUTES` | `60` | Ceiling on `max_duration` the agent may set on a version. |
|
|
155
170
|
| `EDGEGAP_TIMEOUT_MS` | `30000` | Per-request HTTP timeout. |
|
|
156
171
|
|
|
157
172
|
## 🧰 Tools
|
|
158
173
|
|
|
159
|
-
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. |
|
|
160
179
|
|
|
161
180
|
### Before Your First Deployment
|
|
162
181
|
|
|
@@ -173,20 +192,20 @@ Your agent picks the right tool from your request. You don't need to name them,
|
|
|
173
192
|
| --- | --- |
|
|
174
193
|
| `edgegap_list_apps` | Lists your applications. |
|
|
175
194
|
| `edgegap_create_app` ● | Creates an application. |
|
|
176
|
-
| `edgegap_list_app_versions` | Lists versions with their image, resources, and
|
|
177
|
-
| `edgegap_create_app_version` ● | Registers a container image as a deployable version. |
|
|
178
|
-
| `edgegap_deploy` ● | Deploys an authoritative dedicated server close to your players. |
|
|
195
|
+
| `edgegap_list_app_versions` | Lists versions with their image, resources, ports (with TLS Upgrade), and whether a registry login is set. |
|
|
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://`. |
|
|
197
|
+
| `edgegap_deploy` ● | Deploys an authoritative dedicated server close to your players. Always tagged `edgegap-mcp`, and reports when Edgegap will stop it. |
|
|
179
198
|
| `edgegap_wait_for_deployment` | Waits until the server is ready and returns the connection address. |
|
|
180
199
|
| `edgegap_get_deployment` | Reads a deployment's status. |
|
|
181
|
-
| `edgegap_list_deployments` | Lists running deployments, filtered by application, version, status, tags and more, and sorted by age. Finds servers left running. See [Filter Deployments](https://docs.edgegap.com/learn/orchestration/deployments#filter-deployments). |
|
|
182
|
-
| `edgegap_get_deployment_logs` | Reads container logs and crash details. |
|
|
183
|
-
| `edgegap_stop_deployment` ● | Stops one deployment. |
|
|
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). |
|
|
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. |
|
|
202
|
+
| `edgegap_stop_deployment` ● | Stops one deployment, by its exact request ID. No bulk stop. |
|
|
184
203
|
|
|
185
204
|
### Matchmaking
|
|
186
205
|
|
|
187
206
|
| Tool | What it does |
|
|
188
207
|
| --- | --- |
|
|
189
|
-
| `edgegap_build_matchmaker_config` | Generates a matchmaker configuration (teams, team size, optional latency rules and expansions) and checks that the version it deploys exists. Upload the result in the dashboard to create your matchmaker, which starts a dedicated server for each match. |
|
|
208
|
+
| `edgegap_build_matchmaker_config` | Generates a matchmaker configuration (teams, team size, optional latency rules and expansions) and checks that the version it deploys exists. Set `allowed_cors_origins` for browser (WebGL) clients. Upload the result in the dashboard to create your matchmaker, which starts a dedicated server for each match. |
|
|
190
209
|
|
|
191
210
|
Learn more about the configuration in [Matchmaking](https://docs.edgegap.com/learn/matchmaking).
|
|
192
211
|
|
|
@@ -212,6 +231,22 @@ A relay is not a game server: it forwards traffic while one player's game hosts
|
|
|
212
231
|
* *"My deployment failed. Read the logs and tell me why."*
|
|
213
232
|
* *"My game uses host-client networking. Set up an Edgegap relay for two players."*
|
|
214
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
|
+
|
|
215
250
|
## 🚨 Troubleshooting
|
|
216
251
|
|
|
217
252
|
Review common error codes and learn how to unlock your integration.
|
package/dist/auth.js
CHANGED
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
* The real fix is scoped, revocable, deploy-only credentials issued by Edgegap.
|
|
38
38
|
* Until those exist, this file is a workaround and should be labelled as one.
|
|
39
39
|
*/
|
|
40
|
+
import { stripTokenPrefix } from './config.js';
|
|
40
41
|
export class TokenUnavailableError extends Error {
|
|
41
42
|
}
|
|
42
43
|
/** Shown to the developer at the moment they are asked to hand over a token. */
|
|
@@ -181,7 +182,7 @@ export class TokenProvider {
|
|
|
181
182
|
'organization with EDGEGAP_READ_ONLY=1.');
|
|
182
183
|
}
|
|
183
184
|
const raw = String(result.content.api_token ?? '').trim();
|
|
184
|
-
const token = raw
|
|
185
|
+
const token = stripTokenPrefix(raw);
|
|
185
186
|
if (!token) {
|
|
186
187
|
throw new TokenUnavailableError('An empty token was submitted. Nothing was stored.');
|
|
187
188
|
}
|
package/dist/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
|
-
|
|
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':
|
|
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) {
|
|
@@ -26,12 +62,13 @@ export function loadConfig(env = process.env) {
|
|
|
26
62
|
// anything works" step that loses people during onboarding.
|
|
27
63
|
const raw = env.EDGEGAP_API_TOKEN?.trim();
|
|
28
64
|
// Tokens are pasted by hand often enough that it is worth catching the
|
|
29
|
-
// common mistake of including the "token " prefix
|
|
30
|
-
const envToken = raw ? raw
|
|
65
|
+
// common mistake of including the "token " prefix, once or more.
|
|
66
|
+
const envToken = raw ? stripTokenPrefix(raw) || undefined : undefined;
|
|
31
67
|
return {
|
|
32
68
|
envToken,
|
|
33
|
-
baseUrlV1: env.EDGEGAP_BASE_URL
|
|
34
|
-
baseUrlV2: (env.EDGEGAP_BASE_URL
|
|
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),
|
|
@@ -52,6 +89,18 @@ export function assertAppAllowed(config, appName) {
|
|
|
52
89
|
`allowlist rather than trying another application name.`);
|
|
53
90
|
}
|
|
54
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* Removes any run of "Bearer " / "token " prefixes from a pasted credential.
|
|
94
|
+
*
|
|
95
|
+
* The prefix gets doubled easily: the dashboard shows the header form
|
|
96
|
+
* ("token <uuid>"), so an EDGEGAP_API_TOKEN that already carries it, dropped
|
|
97
|
+
* into a config that adds "token " again, sends "token token <uuid>". Stripping
|
|
98
|
+
* only one left "token <uuid>", which the hosted server then mistook for a
|
|
99
|
+
* foreign credential and refused with a misleading message.
|
|
100
|
+
*/
|
|
101
|
+
export function stripTokenPrefix(value) {
|
|
102
|
+
return value.trim().replace(/^(?:(?:bearer|token)\s+)+/i, '').trim();
|
|
103
|
+
}
|
|
55
104
|
/**
|
|
56
105
|
* Strips the live token out of text before it reaches the model.
|
|
57
106
|
* Error strings from HTTP layers sometimes echo request headers back.
|
package/dist/dockerfile.js
CHANGED
|
@@ -72,17 +72,31 @@ export function generateDockerfile(input) {
|
|
|
72
72
|
throw new DockerfileInputError(`base_image "${base}" is not a valid image reference.`);
|
|
73
73
|
}
|
|
74
74
|
// ------------------------------------------------------------- ports ----
|
|
75
|
+
// A WebSocket transport means browser (WebGL) clients, which need wss://:
|
|
76
|
+
// Edgegap's TLS Upgrade on the WS port.
|
|
77
|
+
const browserNetcode = input.netcode !== undefined && protocolForNetcode(input.netcode) === 'WS';
|
|
78
|
+
let autoTls = false; // set when TLS was turned on without being asked for
|
|
75
79
|
let ports;
|
|
76
80
|
if (input.ports && input.ports.length > 0) {
|
|
77
|
-
ports = input.ports.map((p, i) =>
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
81
|
+
ports = input.ports.map((p, i) => {
|
|
82
|
+
const protocol = p.protocol.toUpperCase();
|
|
83
|
+
let tls = p.tls_upgrade;
|
|
84
|
+
if (tls === undefined && browserNetcode && protocol === 'WS') {
|
|
85
|
+
tls = true;
|
|
86
|
+
autoTls = true;
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
port: p.port,
|
|
90
|
+
protocol,
|
|
91
|
+
name: p.name ?? (i === 0 ? 'gameport' : `port${i + 1}`),
|
|
92
|
+
...(tls !== undefined ? { tls_upgrade: tls } : {}),
|
|
93
|
+
};
|
|
94
|
+
});
|
|
82
95
|
}
|
|
83
96
|
else {
|
|
84
97
|
const protocol = (input.netcode && protocolForNetcode(input.netcode)) || 'UDP';
|
|
85
|
-
ports = [{ port: 7777, protocol, name: 'gameport' }];
|
|
98
|
+
ports = [{ port: 7777, protocol, name: 'gameport', ...(browserNetcode ? { tls_upgrade: true } : {}) }];
|
|
99
|
+
autoTls = browserNetcode;
|
|
86
100
|
assumptions.push(`Assumed the server listens on 7777/${protocol}${input.netcode ? ` (the protocol ${input.netcode} uses)` : ''}. ` +
|
|
87
101
|
'Confirm the port in the server\'s network/transport settings and pass ports if it differs.');
|
|
88
102
|
}
|
|
@@ -172,6 +186,10 @@ export function generateDockerfile(input) {
|
|
|
172
186
|
}
|
|
173
187
|
}
|
|
174
188
|
}
|
|
189
|
+
if (autoTls) {
|
|
190
|
+
assumptions.push('Turned on tls_upgrade for the WebSocket port, because WebSocket transports usually mean ' +
|
|
191
|
+
'browser (WebGL) clients, which need wss://. Set tls_upgrade: false if no client runs in a browser.');
|
|
192
|
+
}
|
|
175
193
|
assumptions.push(buildPath === '.'
|
|
176
194
|
? 'Run docker build from inside the server build folder (the folder itself is the build context).'
|
|
177
195
|
: `Run docker build from the folder that contains ${buildPath}.`);
|
package/dist/hosted.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* Edgegap token in its Authorization header, and it is used for that request
|
|
7
7
|
* and discarded. See worker/DECISION.md.
|
|
8
8
|
*/
|
|
9
|
+
import { stripTokenPrefix } from './config.js';
|
|
9
10
|
const TOKEN_URL = 'https://app.edgegap.com/user-settings?tab=tokens';
|
|
10
11
|
/**
|
|
11
12
|
* Edgegap API tokens are UUIDs. The strict form is the real test; the loose
|
|
@@ -27,7 +28,8 @@ function looksLikeEdgegapToken(value) {
|
|
|
27
28
|
export function extractToken(header) {
|
|
28
29
|
if (!header)
|
|
29
30
|
return { token: undefined, problem: 'absent' };
|
|
30
|
-
|
|
31
|
+
// Any run of "Bearer "/"token ", so "token token <uuid>" still works.
|
|
32
|
+
const value = stripTokenPrefix(header);
|
|
31
33
|
if (!value)
|
|
32
34
|
return { token: undefined, problem: 'absent' };
|
|
33
35
|
if (!looksLikeEdgegapToken(value))
|
package/dist/http.js
CHANGED
|
@@ -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:
|
|
95
|
-
|
|
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:
|
|
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
|
-
|
|
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/matchmaker.js
CHANGED
|
@@ -83,10 +83,20 @@ export function buildMatchmakerConfig(input) {
|
|
|
83
83
|
if (input.team_count * input.min_team_size === 1) {
|
|
84
84
|
cautions.push('A match of one player starts a server per ticket. Fine for testing, costly in production.');
|
|
85
85
|
}
|
|
86
|
+
// Browser (WebGL) clients call the matchmaker directly, so their page's
|
|
87
|
+
// origin must be allowed. An origin is scheme + host (+ port), nothing more:
|
|
88
|
+
// a path or trailing slash never matches a browser's Origin header.
|
|
89
|
+
const origins = input.allowed_cors_origins ?? [];
|
|
90
|
+
for (const o of origins) {
|
|
91
|
+
if (!/^https?:\/\/[^/\s?#]+$/.test(o)) {
|
|
92
|
+
problems.push(`allowed_cors_origins entry "${o}" is not an origin. Use scheme and host only, e.g. "https://mygame.example.com" or "http://localhost:8080", with no path or trailing slash.`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
86
95
|
const config = {
|
|
87
96
|
version: input.config_version ?? MATCHMAKER_CONFIG_VERSION,
|
|
88
97
|
inspect: input.inspect ?? true,
|
|
89
98
|
max_deployment_retry_count: 3,
|
|
99
|
+
...(origins.length ? { allowed_cors_origins: origins } : {}),
|
|
90
100
|
profiles: {
|
|
91
101
|
[input.profile_name]: {
|
|
92
102
|
ticket_expiration_period: expiration,
|
package/dist/serverconfig.js
CHANGED
|
@@ -196,6 +196,9 @@ export function validateServerConfig(input) {
|
|
|
196
196
|
err('duplicate-port-name', `Port name "${name}" is used twice. Deployment ports are keyed by name, so one would hide the other.`, 'Give every port a distinct name, e.g. "gameport" and "webport".');
|
|
197
197
|
}
|
|
198
198
|
seenNames.add(name);
|
|
199
|
+
if (p.tls_upgrade && proto !== 'WS' && proto !== 'HTTP') {
|
|
200
|
+
err('tls-wrong-protocol', `ports[${idx}] has tls_upgrade on a ${p.protocol} port. Edgegap only offers TLS Upgrade on WS and HTTP ports.`, 'Use protocol "WS" for a WebSocket server, or drop tls_upgrade.');
|
|
201
|
+
}
|
|
199
202
|
});
|
|
200
203
|
if (input.netcode) {
|
|
201
204
|
const expected = NETCODE_PROTOCOL[input.netcode.toLowerCase()];
|
|
@@ -208,6 +211,15 @@ export function validateServerConfig(input) {
|
|
|
208
211
|
})) {
|
|
209
212
|
err('netcode-protocol', `${input.netcode} speaks ${expected}, but no configured port uses ${expected}. Clients will time out connecting.`, `Set the game port's protocol to ${expected}.`);
|
|
210
213
|
}
|
|
214
|
+
else if (expected === 'WS') {
|
|
215
|
+
// WebSocket transports are what browser (WebGL) builds use, and a
|
|
216
|
+
// browser on an https page refuses plain ws://.
|
|
217
|
+
for (const p of ports) {
|
|
218
|
+
if (p.protocol.toUpperCase() === 'WS' && !p.tls_upgrade) {
|
|
219
|
+
warn('ws-no-tls', `Port ${p.port} is WebSocket without tls_upgrade. Browser (WebGL) clients need wss://, which needs Edgegap's TLS Upgrade.`, 'Set tls_upgrade: true on this port in edgegap_create_app_version, unless no client runs in a browser.');
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
211
223
|
}
|
|
212
224
|
// Cross-check EXPOSE against the version ports. EXPOSE is documentation,
|
|
213
225
|
// so a mismatch is not fatal on its own, but it is the best signal we have
|