@edgegap/mcp 0.15.9 → 0.16.1
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 +1 -1
- package/dist/client.js +62 -5
- package/dist/skills.generated.js +158 -37
- package/dist/tools.js +28 -3
- package/dist/version.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -213,7 +213,7 @@ To keep your API token on your own machine, run the server locally instead. Leav
|
|
|
213
213
|
}
|
|
214
214
|
```
|
|
215
215
|
|
|
216
|
-
Needs Node 18+. Pin a version in production (`@edgegap/mcp@0.
|
|
216
|
+
Needs Node 18+. Pin a version in production (`@edgegap/mcp@0.16.1`) rather than floating on latest. Registered in the official MCP registry as `dev.edgegap/mcp`.
|
|
217
217
|
|
|
218
218
|
The local server can also limit what an agent can do. These variables have no effect on the hosted endpoint at `mcp.edgegap.dev`:
|
|
219
219
|
|
package/dist/client.js
CHANGED
|
@@ -40,6 +40,34 @@ export class EdgegapApiError extends Error {
|
|
|
40
40
|
this.details = details;
|
|
41
41
|
this.name = 'EdgegapApiError';
|
|
42
42
|
}
|
|
43
|
+
/** From the response's Retry-After header, when it had one. */
|
|
44
|
+
retryAfterMs;
|
|
45
|
+
}
|
|
46
|
+
const RETRY_STATUSES = new Set([429, 502, 503, 504]);
|
|
47
|
+
const RETRY_DELAY_MS = 1000;
|
|
48
|
+
const MAX_RETRY_DELAY_MS = 5000;
|
|
49
|
+
function transient(err) {
|
|
50
|
+
return Object.assign(err, { transient: true });
|
|
51
|
+
}
|
|
52
|
+
function parseRetryAfter(value) {
|
|
53
|
+
if (!value)
|
|
54
|
+
return undefined;
|
|
55
|
+
const seconds = Number(value);
|
|
56
|
+
if (Number.isFinite(seconds))
|
|
57
|
+
return Math.max(0, seconds * 1000);
|
|
58
|
+
const at = Date.parse(value);
|
|
59
|
+
return Number.isNaN(at) ? undefined : Math.max(0, at - Date.now());
|
|
60
|
+
}
|
|
61
|
+
/** How long to wait before retrying a failed read, or undefined when it should not be retried. */
|
|
62
|
+
export function retryDelayMs(err) {
|
|
63
|
+
if (err instanceof EdgegapApiError) {
|
|
64
|
+
if (!RETRY_STATUSES.has(err.status))
|
|
65
|
+
return undefined;
|
|
66
|
+
return Math.min(err.retryAfterMs ?? RETRY_DELAY_MS, MAX_RETRY_DELAY_MS);
|
|
67
|
+
}
|
|
68
|
+
if (err instanceof Error && err.transient)
|
|
69
|
+
return RETRY_DELAY_MS;
|
|
70
|
+
return undefined;
|
|
43
71
|
}
|
|
44
72
|
export class EdgegapClient {
|
|
45
73
|
config;
|
|
@@ -74,7 +102,28 @@ export class EdgegapClient {
|
|
|
74
102
|
const client = this.options.clientName?.();
|
|
75
103
|
return `edgegap-mcp/${VERSION}${client ? ` (${client.replace(/[^\w .\-/]/g, '')})` : ''}`;
|
|
76
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* Reads (GET) are retried once after a timeout, a network error, 429 or a
|
|
107
|
+
* 502/503/504: the hosted relay saw single GETs time out or get rate
|
|
108
|
+
* limited mid-session, and failing the tool call there sends agents into
|
|
109
|
+
* their own retry loops. Writes are never retried: a POST that timed out
|
|
110
|
+
* may have created the deployment or version anyway.
|
|
111
|
+
*/
|
|
77
112
|
async request(method, version, path, options = {}) {
|
|
113
|
+
if (method !== 'GET' || this.options.recorder)
|
|
114
|
+
return this.send(method, version, path, options);
|
|
115
|
+
try {
|
|
116
|
+
return await this.send(method, version, path, options);
|
|
117
|
+
}
|
|
118
|
+
catch (err) {
|
|
119
|
+
const delay = retryDelayMs(err);
|
|
120
|
+
if (delay === undefined)
|
|
121
|
+
throw err;
|
|
122
|
+
await new Promise((r) => setTimeout(r, delay));
|
|
123
|
+
return this.send(method, version, path, options);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
async send(method, version, path, options = {}) {
|
|
78
127
|
const base = version === 'v2' ? this.config.baseUrlV2 : this.config.baseUrlV1;
|
|
79
128
|
const url = new URL(base + path);
|
|
80
129
|
for (const [key, value] of Object.entries(options.query ?? {})) {
|
|
@@ -117,10 +166,10 @@ export class EdgegapClient {
|
|
|
117
166
|
catch (err) {
|
|
118
167
|
if (err instanceof Error && err.name === 'AbortError') {
|
|
119
168
|
this.upstream.push('timeout');
|
|
120
|
-
throw new Error(`Request to ${method} ${path} timed out after ${this.config.requestTimeoutMs}ms.`);
|
|
169
|
+
throw transient(new Error(`Request to ${method} ${path} timed out after ${this.config.requestTimeoutMs}ms.`));
|
|
121
170
|
}
|
|
122
171
|
this.upstream.push('network');
|
|
123
|
-
throw new Error(redact(`Network error calling ${method} ${path}: ${err.message}`, token));
|
|
172
|
+
throw transient(new Error(redact(`Network error calling ${method} ${path}: ${err.message}`, token)));
|
|
124
173
|
}
|
|
125
174
|
finally {
|
|
126
175
|
clearTimeout(timer);
|
|
@@ -142,7 +191,9 @@ export class EdgegapClient {
|
|
|
142
191
|
if (response.status === 401)
|
|
143
192
|
this.auth.invalidate();
|
|
144
193
|
const body = (parsed ?? {});
|
|
145
|
-
|
|
194
|
+
const apiError = new EdgegapApiError(response.status, redact(body.message ?? response.statusText, token), body.details);
|
|
195
|
+
apiError.retryAfterMs = parseRetryAfter(response.headers.get('retry-after'));
|
|
196
|
+
throw apiError;
|
|
146
197
|
}
|
|
147
198
|
return (parsed ?? {});
|
|
148
199
|
}
|
|
@@ -229,8 +280,14 @@ export class EdgegapClient {
|
|
|
229
280
|
return this.request(method, 'v1', `/v1/storage/endpoint/${encodeURIComponent(endpointName)}/pull-profile/${encodeURIComponent(profileName)}` +
|
|
230
281
|
`/app/${encodeURIComponent(appName)}/version/${encodeURIComponent(versionName)}`);
|
|
231
282
|
}
|
|
232
|
-
getDeployment(requestId) {
|
|
233
|
-
|
|
283
|
+
async getDeployment(requestId) {
|
|
284
|
+
const status = await this.request('GET', 'v1', `/v1/status/${encodeURIComponent(requestId)}`);
|
|
285
|
+
// The API answers "Status.READY", "Status.TERMINATED"... (a Python enum's
|
|
286
|
+
// repr). Agents and people read "READY".
|
|
287
|
+
if (typeof status.current_status === 'string') {
|
|
288
|
+
status.current_status = status.current_status.replace(/^Status\./, '');
|
|
289
|
+
}
|
|
290
|
+
return status;
|
|
234
291
|
}
|
|
235
292
|
listDeployments(query = {}) {
|
|
236
293
|
return this.request('GET', 'v1', '/v1/deployments', { query });
|