@ant0/mcp 0.3.22-beta.2 → 0.3.22-beta.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/generated/schema.d.ts +3914 -430
- package/dist/connection.js +1 -1
- package/dist/daemon.js +55 -9
- package/dist/errors.d.ts +24 -1
- package/dist/errors.js +23 -0
- package/dist/http-local.d.ts +38 -0
- package/dist/http-local.js +324 -0
- package/dist/http.d.ts +7 -0
- package/dist/http.js +4 -4
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/key-contract.d.ts +4 -4
- package/dist/limits.d.ts +1 -1
- package/dist/limits.js +1 -1
- package/dist/local-routes.d.ts +5 -1
- package/dist/local-routes.js +85 -0
- package/dist/output-descriptor.js +1 -1
- package/dist/server.js +1 -1
- package/dist/tools.d.ts +1 -0
- package/dist/tools.js +648 -39
- package/dist/transport.js +1 -1
- package/package.json +2 -2
package/dist/connection.js
CHANGED
|
@@ -47,7 +47,7 @@ function localFile(file, mustBePrivate = false, env = process.env) {
|
|
|
47
47
|
throw error;
|
|
48
48
|
}
|
|
49
49
|
// The token file only: owned by this user, no group or other access (not checked on Windows,
|
|
50
|
-
// as in
|
|
50
|
+
// as in api-client). The ino/dev comparison below ties the opened file to this lstat.
|
|
51
51
|
const problem = mustBePrivate ? privateTokenProblem(stat) : undefined;
|
|
52
52
|
if (problem !== undefined) {
|
|
53
53
|
// The path and the fix go to stderr (never the protocol stream); the token is never read here.
|
package/dist/daemon.js
CHANGED
|
@@ -5,17 +5,29 @@ import { McpFailure } from "./errors.js";
|
|
|
5
5
|
import { LIMITS } from "./limits.js";
|
|
6
6
|
import { assertCredentialUnchangedAsync } from "./credential-file.js";
|
|
7
7
|
import { localRequestAllowed, mapDaemonError, matchLocalRoute } from "./local-routes.js";
|
|
8
|
-
// Profile path segments:
|
|
8
|
+
// Profile path segments: the run, stop and status tools and the CLI pass a UUID or an exact name.
|
|
9
9
|
const UUID = "[0-9a-f-]{36}";
|
|
10
10
|
const PROFILE_REF = "[^/]+";
|
|
11
|
-
const LOCAL_READ_PATH = new RegExp(`^/v1/(health|licence|automation/status|profiles/${UUID}|inventory/(?:proxies|profiles(?:/${
|
|
12
|
-
/**
|
|
11
|
+
const LOCAL_READ_PATH = new RegExp(`^/v1/(health|licence|automation/status|profiles/${UUID}|inventory/(?:proxies|profiles(?:/${PROFILE_REF})?))$`);
|
|
12
|
+
/** Unchanged v0.25 delegated inventory reads. */
|
|
13
13
|
const KEY_READ_PATH = new RegExp(`^/v1/(automation/status|inventory/(?:proxies|profiles(?:/${PROFILE_REF})?))$`);
|
|
14
14
|
/** The CLI additionally inspects the endpoint-free lifecycle of a run it could not confirm. */
|
|
15
15
|
const CLI_READ_PATH = new RegExp(`^/v1/(automation/status|inventory/(?:proxies|profiles(?:/${PROFILE_REF})?)|profiles/${PROFILE_REF}/run)$`);
|
|
16
|
-
/**
|
|
17
|
-
const MCP_OPERATION_PATH = new RegExp(`^/v1/profiles/${
|
|
16
|
+
/** §17.4 operations. MCP drives one saved profile; CDP start and bulk stay explicit CLI actions. */
|
|
17
|
+
const MCP_OPERATION_PATH = new RegExp(`^/v1/profiles/${PROFILE_REF}/(?:run|stop)$`);
|
|
18
18
|
const CLI_OPERATION_PATH = new RegExp(`^/v1/profiles/(?:${PROFILE_REF}/(?:run|start|stop)|bulk-(?:start|stop))$`);
|
|
19
|
+
/** Only the daemon's error code is read from a name-resolution conflict; nothing else crosses. */
|
|
20
|
+
function isAmbiguousName(body) {
|
|
21
|
+
try {
|
|
22
|
+
const parsed = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(body));
|
|
23
|
+
return (parsed !== null &&
|
|
24
|
+
typeof parsed === "object" &&
|
|
25
|
+
parsed.error === "profile.ambiguous_name");
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
19
31
|
function parsedBody(text) {
|
|
20
32
|
try {
|
|
21
33
|
const value = JSON.parse(text);
|
|
@@ -50,6 +62,16 @@ export function requestTimeoutMs(method, path, body) {
|
|
|
50
62
|
: 0;
|
|
51
63
|
return seconds === 0 ? LIMITS.httpMs : seconds * 1_000 + 10_000;
|
|
52
64
|
}
|
|
65
|
+
if (/^\/v1\/(?:profiles\/[^/]+\/human|human\/[^/]+\/wait)$/.test(path)) {
|
|
66
|
+
// A hand-off hold: the daemon waits wait_s (default 40, at most 50), then answers.
|
|
67
|
+
const wait = value?.wait_s;
|
|
68
|
+
const seconds = wait === undefined
|
|
69
|
+
? 40
|
|
70
|
+
: typeof wait === "number" && Number.isInteger(wait) && wait >= 1 && wait <= 50
|
|
71
|
+
? wait
|
|
72
|
+
: 0;
|
|
73
|
+
return seconds === 0 ? LIMITS.httpMs : seconds * 1_000 + 10_000;
|
|
74
|
+
}
|
|
53
75
|
return 70_000;
|
|
54
76
|
}
|
|
55
77
|
/** Typed API client with a direct, non-proxying HTTP transport and no redirects or retries. */
|
|
@@ -93,7 +115,9 @@ export function daemonClient(connection, lifetime, consumer = "mcp") {
|
|
|
93
115
|
throw new McpFailure("configuration");
|
|
94
116
|
// Raw PNG bytes (screenshots) get their own cap; every other body keeps 1 MiB.
|
|
95
117
|
const bodyLimit = local?.binary ? LIMITS.screenshotBytes : LIMITS.bodyBytes;
|
|
96
|
-
const timeout = local
|
|
118
|
+
const timeout = local && !local.human
|
|
119
|
+
? 70_000
|
|
120
|
+
: requestTimeoutMs(method, url.pathname, body.toString("utf8"));
|
|
97
121
|
const deadline = AbortSignal.timeout(timeout);
|
|
98
122
|
const signal = AbortSignal.any([lifetime, input.signal, deadline]);
|
|
99
123
|
const credentialCheck = async () => {
|
|
@@ -157,7 +181,8 @@ export function daemonClient(connection, lifetime, consumer = "mcp") {
|
|
|
157
181
|
accept: "application/json",
|
|
158
182
|
"accept-encoding": "identity",
|
|
159
183
|
...(body.length > 0 ? { "content-type": "application/json" } : {}),
|
|
160
|
-
|
|
184
|
+
// The daemon reads this header only for API keys; with the local token it is ignored.
|
|
185
|
+
"x-ant0-consumer": consumer,
|
|
161
186
|
},
|
|
162
187
|
});
|
|
163
188
|
// Keep the handler's permit until the local request has closed, not merely until destroy()
|
|
@@ -176,7 +201,7 @@ export function daemonClient(connection, lifetime, consumer = "mcp") {
|
|
|
176
201
|
status === 409 ||
|
|
177
202
|
status === 422 ||
|
|
178
203
|
status === 423 ||
|
|
179
|
-
(local.page && (status === 408 || status === 403)))) {
|
|
204
|
+
(local.page && (status === 408 || status === 403 || status === 404)))) {
|
|
180
205
|
// Read only the daemon's error `code`; no message, details or other field is kept.
|
|
181
206
|
const chunks = [];
|
|
182
207
|
let size = 0;
|
|
@@ -186,7 +211,28 @@ export function daemonClient(connection, lifetime, consumer = "mcp") {
|
|
|
186
211
|
return finish("upstream");
|
|
187
212
|
chunks.push(chunk);
|
|
188
213
|
});
|
|
189
|
-
res.on("end", () =>
|
|
214
|
+
res.on("end", () => {
|
|
215
|
+
const kind = mapDaemonError(status, Buffer.concat(chunks, size), local.page === true);
|
|
216
|
+
// A 404 without a page code of its own stays the generic "not found".
|
|
217
|
+
finish(status === 404 && kind === "upstream" ? "not_found" : kind);
|
|
218
|
+
});
|
|
219
|
+
res.on("close", () => {
|
|
220
|
+
if (!res.complete)
|
|
221
|
+
finish("upstream");
|
|
222
|
+
});
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
if (!local && status === 409) {
|
|
226
|
+
// Run, stop and status accept an exact name: a name shared by profiles is a fixed failure.
|
|
227
|
+
const chunks = [];
|
|
228
|
+
let size = 0;
|
|
229
|
+
res.on("data", (chunk) => {
|
|
230
|
+
size += chunk.length;
|
|
231
|
+
if (size > LIMITS.bodyBytes)
|
|
232
|
+
return finish("upstream");
|
|
233
|
+
chunks.push(chunk);
|
|
234
|
+
});
|
|
235
|
+
res.on("end", () => finish(isAmbiguousName(Buffer.concat(chunks, size)) ? "ambiguous_name" : "upstream"));
|
|
190
236
|
res.on("close", () => {
|
|
191
237
|
if (!res.complete)
|
|
192
238
|
finish("upstream");
|
package/dist/errors.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ declare const MESSAGES: {
|
|
|
15
15
|
readonly invalid_request: "The daemon rejected the input.";
|
|
16
16
|
readonly profile_running: "Stop the profile first.";
|
|
17
17
|
readonly profile_synced: "This profile syncs with the cloud; remove it in the Ant0 app.";
|
|
18
|
+
readonly ambiguous_name: "Several profiles have that name; call ant0_profiles_list and pass the UUID.";
|
|
18
19
|
readonly conflict: "The daemon reported a conflict; check the profile and retry.";
|
|
19
20
|
readonly ref_stale: "The ref is stale; take a new snapshot and use a ref from it.";
|
|
20
21
|
readonly not_running: "The profile is not running; start it with ant0_profile_run first.";
|
|
@@ -29,6 +30,28 @@ declare const MESSAGES: {
|
|
|
29
30
|
readonly destination_blocked: "This URL points to a local or private-network address, which the page tools refuse. Use a public http(s) URL.";
|
|
30
31
|
readonly page_timeout: "The wait did not finish in time.";
|
|
31
32
|
readonly no_history: "There is no history entry in that direction.";
|
|
33
|
+
readonly dialog_pending: "A JavaScript dialog is open on this tab and blocks it: call ant0_page_dialog with action list, then accept or dismiss it.";
|
|
34
|
+
readonly no_dialog: "No dialog is open on this tab.";
|
|
35
|
+
readonly value_rejected: "The input did not take this value; use the format the field expects.";
|
|
36
|
+
readonly download_not_found: "That download is not known; call ant0_page_downloads with action list.";
|
|
37
|
+
readonly download_not_ready: "The download did not finish in time or did not complete.";
|
|
38
|
+
readonly url_not_allowed: "This tab shows a browser-internal page, which the page tools do not drive: open a web page with ant0_tabs new, or navigate a blank tab.";
|
|
39
|
+
readonly save_exists: "A file already exists at that path; choose a new path.";
|
|
40
|
+
readonly human_pending: "A hand-off or approval request is already open for this profile: call ant0_human_wait with the request id you already have.";
|
|
41
|
+
readonly human_headless: "This profile runs headless, so nobody can act in it: stop it and start it again with headless false.";
|
|
42
|
+
readonly human_no_approver: "The Ant0 app is not running, so nobody can take the hand-off: ask the user to open the Ant0 app.";
|
|
43
|
+
readonly page_human_pending: "A person is handling a hand-off request on this profile, so input is refused: call ant0_human_wait with the request id until it is no longer pending.";
|
|
44
|
+
readonly rules_active: "This profile has approval rules (or they cannot be read), and this tool would bypass them, so it is refused. Use the ant0_page_* tools, or ask the user to clear the rules in the Ant0 app.";
|
|
45
|
+
readonly approval_required: "A person has to approve this action first, and this tool cannot ask: ask the user to change the profile's approval rules in the Ant0 app, or use a tool that takes approval_id.";
|
|
46
|
+
readonly approval_stale: "The approval no longer fits this action (it was used, it ran out after 120 s, or the request changed): repeat the action without approval_id to ask again.";
|
|
47
|
+
readonly approval_denied: "The person denied this action: do not retry it; ask the user what to do instead.";
|
|
48
|
+
readonly approval_unavailable: "Nobody can approve right now because the Ant0 app is not running: ask the user to open the Ant0 app.";
|
|
49
|
+
readonly approval_target_mismatch: "The key would land on another element than the ref you named: pass the ref of the control itself.";
|
|
50
|
+
readonly blocked_domain: "This profile blocks that site, so the page tools will not read or act on it: ask the user to change the profile's rules in the Ant0 app.";
|
|
51
|
+
readonly blocked_frame: "A frame of a blocked site is on this page, so this action is refused: ask the user to change the profile's rules in the Ant0 app.";
|
|
52
|
+
readonly ref_required: "This profile has approval rules: pass the element's ref.";
|
|
53
|
+
readonly frame_target: "The key would land on a frame: pass the ref of an element inside the frame.";
|
|
54
|
+
readonly rules_unreadable: "The profile's rules cannot be read, so page actions are refused: ask the user to check them in the Ant0 app.";
|
|
32
55
|
readonly arguments: "invalid tool arguments";
|
|
33
56
|
readonly unknown_tool: "unknown tool";
|
|
34
57
|
readonly busy: "too many concurrent calls";
|
|
@@ -54,7 +77,7 @@ export declare const FAILURE_OUTPUT_SCHEMA: {
|
|
|
54
77
|
const: string;
|
|
55
78
|
};
|
|
56
79
|
message: {
|
|
57
|
-
const: "invalid local daemon configuration" | "the local daemon token file is not private; the path and the fix are in the error output of ant0 mcp serve" | "local daemon unavailable" | "local daemon authorization required" | "local daemon denied this request" | "item not found" | "local daemon request failed" | "invalid local daemon response" | "local daemon response exceeds limit" | "tool result exceeds limit; request fewer items" | "local daemon request timed out" | "request cancelled" | "operation outcome is unknown; check the current state before retrying" | "The daemon rejected the input." | "Stop the profile first." | "This profile syncs with the cloud; remove it in the Ant0 app." | "The daemon reported a conflict; check the profile and retry." | "The ref is stale; take a new snapshot and use a ref from it." | "The profile is not running; start it with ant0_profile_run first." | "This control cannot be driven by typing or pointer input." | "The field is disabled or read-only." | "The select did not take the requested option." | "The target is outside the viewport or has no box." | "The target was not (or no longer) the focused element, so typing stopped; earlier characters or fields may already have been entered, and with submit the form may already have been submitted. Take a new snapshot, check the page state before retrying, and retry only what is missing. If its tab is in the background select it with ant0_tabs first." | "Another element covers the target, so that click was not sent (earlier fields of a fill may already have been entered); close the overlay or scroll and retry." | "The tab is in the background (or went there mid-action; earlier characters or fields may already have been entered): call ant0_tabs with action select for it first (this changes the tab the user sees), check the page state, then retry." | "Several tabs are open: call ant0_tabs to list them and pass the tab id as tab." | "This URL points to a local or private-network address, which the page tools refuse. Use a public http(s) URL." | "The wait did not finish in time." | "There is no history entry in that direction." | "invalid tool arguments" | "unknown tool" | "too many concurrent calls" | "invalid MCP input frame" | "MCP input frame exceeds limit" | "MCP input failed" | "MCP output failed" | "MCP requires pipe or socket stdout" | "MCP peer did not answer ping" | "MCP output stalled" | "MCP adapter failed";
|
|
80
|
+
const: "invalid local daemon configuration" | "the local daemon token file is not private; the path and the fix are in the error output of ant0 mcp serve" | "local daemon unavailable" | "local daemon authorization required" | "local daemon denied this request" | "item not found" | "local daemon request failed" | "invalid local daemon response" | "local daemon response exceeds limit" | "tool result exceeds limit; request fewer items" | "local daemon request timed out" | "request cancelled" | "operation outcome is unknown; check the current state before retrying" | "The daemon rejected the input." | "Stop the profile first." | "This profile syncs with the cloud; remove it in the Ant0 app." | "Several profiles have that name; call ant0_profiles_list and pass the UUID." | "The daemon reported a conflict; check the profile and retry." | "The ref is stale; take a new snapshot and use a ref from it." | "The profile is not running; start it with ant0_profile_run first." | "This control cannot be driven by typing or pointer input." | "The field is disabled or read-only." | "The select did not take the requested option." | "The target is outside the viewport or has no box." | "The target was not (or no longer) the focused element, so typing stopped; earlier characters or fields may already have been entered, and with submit the form may already have been submitted. Take a new snapshot, check the page state before retrying, and retry only what is missing. If its tab is in the background select it with ant0_tabs first." | "Another element covers the target, so that click was not sent (earlier fields of a fill may already have been entered); close the overlay or scroll and retry." | "The tab is in the background (or went there mid-action; earlier characters or fields may already have been entered): call ant0_tabs with action select for it first (this changes the tab the user sees), check the page state, then retry." | "Several tabs are open: call ant0_tabs to list them and pass the tab id as tab." | "This URL points to a local or private-network address, which the page tools refuse. Use a public http(s) URL." | "The wait did not finish in time." | "There is no history entry in that direction." | "A JavaScript dialog is open on this tab and blocks it: call ant0_page_dialog with action list, then accept or dismiss it." | "No dialog is open on this tab." | "The input did not take this value; use the format the field expects." | "That download is not known; call ant0_page_downloads with action list." | "The download did not finish in time or did not complete." | "This tab shows a browser-internal page, which the page tools do not drive: open a web page with ant0_tabs new, or navigate a blank tab." | "A file already exists at that path; choose a new path." | "A hand-off or approval request is already open for this profile: call ant0_human_wait with the request id you already have." | "This profile runs headless, so nobody can act in it: stop it and start it again with headless false." | "The Ant0 app is not running, so nobody can take the hand-off: ask the user to open the Ant0 app." | "A person is handling a hand-off request on this profile, so input is refused: call ant0_human_wait with the request id until it is no longer pending." | "This profile has approval rules (or they cannot be read), and this tool would bypass them, so it is refused. Use the ant0_page_* tools, or ask the user to clear the rules in the Ant0 app." | "A person has to approve this action first, and this tool cannot ask: ask the user to change the profile's approval rules in the Ant0 app, or use a tool that takes approval_id." | "The approval no longer fits this action (it was used, it ran out after 120 s, or the request changed): repeat the action without approval_id to ask again." | "The person denied this action: do not retry it; ask the user what to do instead." | "Nobody can approve right now because the Ant0 app is not running: ask the user to open the Ant0 app." | "The key would land on another element than the ref you named: pass the ref of the control itself." | "This profile blocks that site, so the page tools will not read or act on it: ask the user to change the profile's rules in the Ant0 app." | "A frame of a blocked site is on this page, so this action is refused: ask the user to change the profile's rules in the Ant0 app." | "This profile has approval rules: pass the element's ref." | "The key would land on a frame: pass the ref of an element inside the frame." | "The profile's rules cannot be read, so page actions are refused: ask the user to check them in the Ant0 app." | "invalid tool arguments" | "unknown tool" | "too many concurrent calls" | "invalid MCP input frame" | "MCP input frame exceeds limit" | "MCP input failed" | "MCP output failed" | "MCP requires pipe or socket stdout" | "MCP peer did not answer ping" | "MCP output stalled" | "MCP adapter failed";
|
|
58
81
|
};
|
|
59
82
|
};
|
|
60
83
|
}[];
|
package/dist/errors.js
CHANGED
|
@@ -17,6 +17,7 @@ const MESSAGES = {
|
|
|
17
17
|
invalid_request: "The daemon rejected the input.",
|
|
18
18
|
profile_running: "Stop the profile first.",
|
|
19
19
|
profile_synced: "This profile syncs with the cloud; remove it in the Ant0 app.",
|
|
20
|
+
ambiguous_name: "Several profiles have that name; call ant0_profiles_list and pass the UUID.",
|
|
20
21
|
conflict: "The daemon reported a conflict; check the profile and retry.",
|
|
21
22
|
ref_stale: "The ref is stale; take a new snapshot and use a ref from it.",
|
|
22
23
|
not_running: "The profile is not running; start it with ant0_profile_run first.",
|
|
@@ -31,6 +32,28 @@ const MESSAGES = {
|
|
|
31
32
|
destination_blocked: "This URL points to a local or private-network address, which the page tools refuse. Use a public http(s) URL.",
|
|
32
33
|
page_timeout: "The wait did not finish in time.",
|
|
33
34
|
no_history: "There is no history entry in that direction.",
|
|
35
|
+
dialog_pending: "A JavaScript dialog is open on this tab and blocks it: call ant0_page_dialog with action list, then accept or dismiss it.",
|
|
36
|
+
no_dialog: "No dialog is open on this tab.",
|
|
37
|
+
value_rejected: "The input did not take this value; use the format the field expects.",
|
|
38
|
+
download_not_found: "That download is not known; call ant0_page_downloads with action list.",
|
|
39
|
+
download_not_ready: "The download did not finish in time or did not complete.",
|
|
40
|
+
url_not_allowed: "This tab shows a browser-internal page, which the page tools do not drive: open a web page with ant0_tabs new, or navigate a blank tab.",
|
|
41
|
+
save_exists: "A file already exists at that path; choose a new path.",
|
|
42
|
+
human_pending: "A hand-off or approval request is already open for this profile: call ant0_human_wait with the request id you already have.",
|
|
43
|
+
human_headless: "This profile runs headless, so nobody can act in it: stop it and start it again with headless false.",
|
|
44
|
+
human_no_approver: "The Ant0 app is not running, so nobody can take the hand-off: ask the user to open the Ant0 app.",
|
|
45
|
+
page_human_pending: "A person is handling a hand-off request on this profile, so input is refused: call ant0_human_wait with the request id until it is no longer pending.",
|
|
46
|
+
rules_active: "This profile has approval rules (or they cannot be read), and this tool would bypass them, so it is refused. Use the ant0_page_* tools, or ask the user to clear the rules in the Ant0 app.",
|
|
47
|
+
approval_required: "A person has to approve this action first, and this tool cannot ask: ask the user to change the profile's approval rules in the Ant0 app, or use a tool that takes approval_id.",
|
|
48
|
+
approval_stale: "The approval no longer fits this action (it was used, it ran out after 120 s, or the request changed): repeat the action without approval_id to ask again.",
|
|
49
|
+
approval_denied: "The person denied this action: do not retry it; ask the user what to do instead.",
|
|
50
|
+
approval_unavailable: "Nobody can approve right now because the Ant0 app is not running: ask the user to open the Ant0 app.",
|
|
51
|
+
approval_target_mismatch: "The key would land on another element than the ref you named: pass the ref of the control itself.",
|
|
52
|
+
blocked_domain: "This profile blocks that site, so the page tools will not read or act on it: ask the user to change the profile's rules in the Ant0 app.",
|
|
53
|
+
blocked_frame: "A frame of a blocked site is on this page, so this action is refused: ask the user to change the profile's rules in the Ant0 app.",
|
|
54
|
+
ref_required: "This profile has approval rules: pass the element's ref.",
|
|
55
|
+
frame_target: "The key would land on a frame: pass the ref of an element inside the frame.",
|
|
56
|
+
rules_unreadable: "The profile's rules cannot be read, so page actions are refused: ask the user to check them in the Ant0 app.",
|
|
34
57
|
arguments: "invalid tool arguments",
|
|
35
58
|
unknown_tool: "unknown tool",
|
|
36
59
|
busy: "too many concurrent calls",
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Readable } from "node:stream";
|
|
2
|
+
import { type DiscoveryOptions } from "./connection.js";
|
|
3
|
+
import { McpFailure } from "./errors.js";
|
|
4
|
+
/** `ant0_mcp_v1_` then 32 random bytes as unpadded base64url (43 characters). */
|
|
5
|
+
export declare const DESKTOP_TOKEN_PATTERN: RegExp;
|
|
6
|
+
/** The listen port is taken. Fixed text only; the caller reports it and does not retry. */
|
|
7
|
+
export declare class PortInUseFailure extends McpFailure {
|
|
8
|
+
readonly reason: "port_in_use";
|
|
9
|
+
constructor();
|
|
10
|
+
}
|
|
11
|
+
export interface DesktopLocalOptions extends Pick<DiscoveryOptions, "home" | "env"> {
|
|
12
|
+
/** The bearer token clients must present. Must match DESKTOP_TOKEN_PATTERN. */
|
|
13
|
+
token: string;
|
|
14
|
+
/** 1024-65535, never the daemon's port. 0 (a free port) is for programmatic use and tests. */
|
|
15
|
+
listenPort: number;
|
|
16
|
+
/** Largest accepted request body in bytes. Default 1 MiB. */
|
|
17
|
+
maxBodyBytes?: number;
|
|
18
|
+
signal?: AbortSignal;
|
|
19
|
+
}
|
|
20
|
+
export interface DesktopLocalHandle {
|
|
21
|
+
readonly url: string;
|
|
22
|
+
readonly port: number;
|
|
23
|
+
close(): Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
/** Constant-time bearer check: both sides are hashed first, so lengths never leak. */
|
|
26
|
+
export declare function bearerMatches(expected: string, presented: string): boolean;
|
|
27
|
+
/** Serve the desktop-local endpoint on 127.0.0.1. See the file comment for the contract. */
|
|
28
|
+
export declare function serveDesktopLocalHttp(options: DesktopLocalOptions): Promise<DesktopLocalHandle>;
|
|
29
|
+
/**
|
|
30
|
+
* Reads the token line from `stdin`, serves, and resolves once the server is closed: on stdin
|
|
31
|
+
* EOF/close/error (the parent is gone), or when `signal` aborts. The token line must end in a
|
|
32
|
+
* newline and is at most 256 bytes; anything after it is discarded.
|
|
33
|
+
*/
|
|
34
|
+
export declare function serveDesktopLocalFromStdin(stdin: Readable, options: Omit<DesktopLocalOptions, "token"> & {
|
|
35
|
+
/** How long to wait for the token line. Default 10 s; no token means a fixed refusal. */
|
|
36
|
+
tokenDeadlineMs?: number;
|
|
37
|
+
}, onListening?: (handle: DesktopLocalHandle) => void): Promise<void>;
|
|
38
|
+
//# sourceMappingURL=http-local.d.ts.map
|
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* "Desktop-local" Streamable HTTP mode: a separate mode from the OAuth resource server in
|
|
3
|
+
* `http.ts`, started by the Ant0 desktop app as a supervised child:
|
|
4
|
+
*
|
|
5
|
+
* ant0 mcp serve --http --port <N> --token-stdin
|
|
6
|
+
*
|
|
7
|
+
* Contract with the parent (the Rust shell):
|
|
8
|
+
* - It writes the MCP bearer token plus a newline to this process's stdin and then KEEPS stdin
|
|
9
|
+
* open. The token is never passed in argv, env or a query string.
|
|
10
|
+
* - Stdin EOF (or close) means "the parent is gone": the server closes and the process exits.
|
|
11
|
+
* - Port in use gives a fixed failure (PortInUseFailure) and no other port is tried.
|
|
12
|
+
*
|
|
13
|
+
* Auth is one static bearer (`ant0_mcp_v1_` + 256 random bits, base64url), compared in constant
|
|
14
|
+
* time. The adapter then talks to ant0d with the LOCAL daemon token, so every local tool
|
|
15
|
+
* (identity and page tools included) is listed. That lift exists only here: the OAuth mode in
|
|
16
|
+
* `http.ts` still refuses the local token.
|
|
17
|
+
*
|
|
18
|
+
* Network rules: 127.0.0.1 only (no host setting); the Host header must be exactly
|
|
19
|
+
* `127.0.0.1:<port>` or `localhost:<port>`; any Origin header at all is refused with 403. Host
|
|
20
|
+
* and Origin are checked before auth on every route, including 404 and 405. No CORS headers,
|
|
21
|
+
* no OAuth metadata route (404), and a 401 challenge without `resource_metadata`.
|
|
22
|
+
*/
|
|
23
|
+
import { createHash, timingSafeEqual } from "node:crypto";
|
|
24
|
+
import { createServer } from "node:http";
|
|
25
|
+
import { createMcpHandler } from "@modelcontextprotocol/server";
|
|
26
|
+
import { resolveHome } from "./api/index.js";
|
|
27
|
+
import { CallPermits } from "./call-permits.js";
|
|
28
|
+
import { discoverConnection, keyMode } from "./connection.js";
|
|
29
|
+
import { daemonClient } from "./daemon.js";
|
|
30
|
+
import { McpFailure, safeFailure } from "./errors.js";
|
|
31
|
+
import { startExportSweeper } from "./export-files.js";
|
|
32
|
+
import { MAX_TOKEN_CHARS, boundedBody, sanitizeResponse, webHeaders } from "./http.js";
|
|
33
|
+
import { buildServer } from "./server.js";
|
|
34
|
+
import { toolsForCredential } from "./tools.js";
|
|
35
|
+
/** `ant0_mcp_v1_` then 32 random bytes as unpadded base64url (43 characters). */
|
|
36
|
+
export const DESKTOP_TOKEN_PATTERN = /^ant0_mcp_v1_[A-Za-z0-9_-]{43}$/;
|
|
37
|
+
const ENDPOINT_PATH = "/mcp";
|
|
38
|
+
const HOST = "127.0.0.1";
|
|
39
|
+
const TOKEN_LINE_MAX = 256;
|
|
40
|
+
const TOKEN_DEADLINE_MS = 10_000;
|
|
41
|
+
/** The listen port is taken. Fixed text only; the caller reports it and does not retry. */
|
|
42
|
+
export class PortInUseFailure extends McpFailure {
|
|
43
|
+
reason = "port_in_use";
|
|
44
|
+
constructor() {
|
|
45
|
+
super("configuration");
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function refuse(reason) {
|
|
49
|
+
process.stderr.write(`ant0-mcp: ${reason}\n`);
|
|
50
|
+
throw new McpFailure("configuration");
|
|
51
|
+
}
|
|
52
|
+
const digest = (value) => createHash("sha256").update(value, "utf8").digest();
|
|
53
|
+
/** Constant-time bearer check: both sides are hashed first, so lengths never leak. */
|
|
54
|
+
export function bearerMatches(expected, presented) {
|
|
55
|
+
if (presented.length > MAX_TOKEN_CHARS)
|
|
56
|
+
return false;
|
|
57
|
+
return timingSafeEqual(digest(expected), digest(presented));
|
|
58
|
+
}
|
|
59
|
+
/** The bearer from a header value, or undefined unless it is exactly `Bearer <token>`. */
|
|
60
|
+
function bearerFrom(header) {
|
|
61
|
+
if (typeof header !== "string" || header.length > MAX_TOKEN_CHARS + 7)
|
|
62
|
+
return undefined;
|
|
63
|
+
const match = /^Bearer ([!-~]+)$/i.exec(header);
|
|
64
|
+
return match?.[1];
|
|
65
|
+
}
|
|
66
|
+
/** Serve the desktop-local endpoint on 127.0.0.1. See the file comment for the contract. */
|
|
67
|
+
export async function serveDesktopLocalHttp(options) {
|
|
68
|
+
if (!DESKTOP_TOKEN_PATTERN.test(options.token))
|
|
69
|
+
refuse("the MCP token has an invalid format");
|
|
70
|
+
const { listenPort } = options;
|
|
71
|
+
if (!Number.isInteger(listenPort) ||
|
|
72
|
+
(listenPort !== 0 && (listenPort < 1024 || listenPort > 65535)))
|
|
73
|
+
refuse("the MCP port must be 1024-65535");
|
|
74
|
+
const maxBody = options.maxBodyBytes ?? 1024 * 1024;
|
|
75
|
+
const expected = options.token;
|
|
76
|
+
const lifetime = new AbortController();
|
|
77
|
+
const permits = new CallPermits();
|
|
78
|
+
let stopSweeper;
|
|
79
|
+
let server;
|
|
80
|
+
let handler;
|
|
81
|
+
let boundPort = -1;
|
|
82
|
+
const closeAll = async () => {
|
|
83
|
+
lifetime.abort();
|
|
84
|
+
stopSweeper?.();
|
|
85
|
+
await handler?.close().catch(() => { });
|
|
86
|
+
if (server?.listening)
|
|
87
|
+
await new Promise((resolve) => {
|
|
88
|
+
server.close(() => resolve());
|
|
89
|
+
server.closeAllConnections();
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
try {
|
|
93
|
+
// Never pass a port, credential file or API key: this mode always uses the local token.
|
|
94
|
+
const connection = discoverConnection({
|
|
95
|
+
...(options.home !== undefined ? { home: options.home } : {}),
|
|
96
|
+
...(options.env !== undefined ? { env: options.env } : {}),
|
|
97
|
+
});
|
|
98
|
+
if (keyMode(connection))
|
|
99
|
+
refuse("desktop-local mode uses the local daemon token; unset ANT0_API_KEY");
|
|
100
|
+
if (listenPort !== 0 && new URL(connection.origin).port === String(listenPort))
|
|
101
|
+
refuse("the MCP port must not be the daemon's port");
|
|
102
|
+
const home = resolveHome({
|
|
103
|
+
...(options.home !== undefined ? { home: options.home } : {}),
|
|
104
|
+
env: options.env ?? process.env,
|
|
105
|
+
});
|
|
106
|
+
stopSweeper = startExportSweeper(home);
|
|
107
|
+
const client = daemonClient(connection, lifetime.signal);
|
|
108
|
+
const tools = toolsForCredential(undefined);
|
|
109
|
+
handler = createMcpHandler(() => buildServer({
|
|
110
|
+
client,
|
|
111
|
+
tools,
|
|
112
|
+
grant: undefined,
|
|
113
|
+
home,
|
|
114
|
+
permits,
|
|
115
|
+
lifetime: lifetime.signal,
|
|
116
|
+
}), { maxRequestBodySize: maxBody, legacy: "stateless" });
|
|
117
|
+
const mcp = handler;
|
|
118
|
+
server = createServer({
|
|
119
|
+
maxHeaderSize: 16 * 1024,
|
|
120
|
+
requestTimeout: 30_000,
|
|
121
|
+
headersTimeout: 10_000,
|
|
122
|
+
keepAliveTimeout: 5_000,
|
|
123
|
+
}, (req, res) => {
|
|
124
|
+
void (async () => {
|
|
125
|
+
const send = async (response) => {
|
|
126
|
+
res.statusCode = response.status;
|
|
127
|
+
response.headers.forEach((value, name) => res.setHeader(name, value));
|
|
128
|
+
res.setHeader("Cache-Control", "no-store");
|
|
129
|
+
res.setHeader("X-Content-Type-Options", "nosniff");
|
|
130
|
+
if (!response.body)
|
|
131
|
+
return void res.end();
|
|
132
|
+
const reader = response.body.getReader();
|
|
133
|
+
res.on("close", () => void reader.cancel().catch(() => { }));
|
|
134
|
+
try {
|
|
135
|
+
for (;;) {
|
|
136
|
+
const { done, value } = await reader.read();
|
|
137
|
+
if (done)
|
|
138
|
+
break;
|
|
139
|
+
if (!res.write(value))
|
|
140
|
+
await new Promise((resolve) => res.once("drain", resolve));
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
// The peer went away; the SDK cancels the exchange from the aborted signal.
|
|
145
|
+
}
|
|
146
|
+
res.end();
|
|
147
|
+
};
|
|
148
|
+
const status = (code, headers = {}) => send(new Response(null, { status: code, headers }));
|
|
149
|
+
// DNS-rebinding and cross-site defences first, on every route and method.
|
|
150
|
+
const authority = req.headers.host?.toLowerCase();
|
|
151
|
+
if (authority !== `127.0.0.1:${boundPort}` && authority !== `localhost:${boundPort}`)
|
|
152
|
+
return void (await status(403));
|
|
153
|
+
if (req.headers.origin !== undefined)
|
|
154
|
+
return void (await status(403));
|
|
155
|
+
let url;
|
|
156
|
+
try {
|
|
157
|
+
url = new URL(req.url ?? "/", `http://127.0.0.1:${boundPort}`);
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
return void (await status(400));
|
|
161
|
+
}
|
|
162
|
+
if (url.pathname !== ENDPOINT_PATH)
|
|
163
|
+
return void (await status(404));
|
|
164
|
+
// The 2026-07-28 endpoint is POST only: no GET stream, no DELETE session.
|
|
165
|
+
if (req.method !== "POST")
|
|
166
|
+
return void (await status(405, { Allow: "POST" }));
|
|
167
|
+
const presented = bearerFrom(req.headers.authorization);
|
|
168
|
+
if (presented === undefined || !bearerMatches(expected, presented))
|
|
169
|
+
return void (await status(401, { "WWW-Authenticate": 'Bearer error="invalid_token"' }));
|
|
170
|
+
const body = await boundedBody(req, maxBody);
|
|
171
|
+
if (body === undefined)
|
|
172
|
+
return void (await status(413));
|
|
173
|
+
let peeked;
|
|
174
|
+
try {
|
|
175
|
+
const parsed = JSON.parse(body.toString("utf8"));
|
|
176
|
+
if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed))
|
|
177
|
+
peeked = parsed;
|
|
178
|
+
}
|
|
179
|
+
catch {
|
|
180
|
+
// Not JSON: the SDK answers it.
|
|
181
|
+
}
|
|
182
|
+
// No listChanged capability is advertised; a listen stream would only pin a slot.
|
|
183
|
+
if (peeked?.method === "subscriptions/listen")
|
|
184
|
+
return void (await send(Response.json({
|
|
185
|
+
jsonrpc: "2.0",
|
|
186
|
+
id: typeof peeked.id === "string" || typeof peeked.id === "number"
|
|
187
|
+
? peeked.id
|
|
188
|
+
: null,
|
|
189
|
+
error: { code: -32601, message: "MCP request rejected" },
|
|
190
|
+
}, { status: 200 })));
|
|
191
|
+
const abort = new AbortController();
|
|
192
|
+
res.on("close", () => abort.abort());
|
|
193
|
+
const headers = webHeaders(req);
|
|
194
|
+
// No token passthrough: the bearer is not visible to the MCP layer's request.
|
|
195
|
+
headers.delete("authorization");
|
|
196
|
+
// Fixed base origin plus path and query only: an absolute-form request target
|
|
197
|
+
// (POST http://evil.test/mcp) can never change the URL the SDK sees.
|
|
198
|
+
const request = new Request(`http://${HOST}:${boundPort}${url.pathname}${url.search}`, {
|
|
199
|
+
method: "POST",
|
|
200
|
+
headers,
|
|
201
|
+
body: new Uint8Array(body),
|
|
202
|
+
signal: abort.signal,
|
|
203
|
+
});
|
|
204
|
+
let response;
|
|
205
|
+
try {
|
|
206
|
+
response = await mcp.fetch(request, {
|
|
207
|
+
authInfo: {
|
|
208
|
+
token: "",
|
|
209
|
+
clientId: "desktop-local",
|
|
210
|
+
scopes: ["ant0.read", "ant0.run"],
|
|
211
|
+
expiresAt: Math.floor(Date.now() / 1000) + 3600,
|
|
212
|
+
},
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
catch {
|
|
216
|
+
response = Response.json({
|
|
217
|
+
jsonrpc: "2.0",
|
|
218
|
+
id: null,
|
|
219
|
+
error: { code: -32603, message: "MCP request rejected" },
|
|
220
|
+
}, { status: 500 });
|
|
221
|
+
}
|
|
222
|
+
await send(await sanitizeResponse(response));
|
|
223
|
+
})().catch(() => {
|
|
224
|
+
if (!res.headersSent)
|
|
225
|
+
res.statusCode = 500;
|
|
226
|
+
res.end();
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
server.maxConnections = 64;
|
|
230
|
+
await new Promise((resolve, reject) => {
|
|
231
|
+
server.once("error", reject);
|
|
232
|
+
// No `exclusive: false`, no host choice and no port fallback.
|
|
233
|
+
server.listen(listenPort, HOST, () => resolve());
|
|
234
|
+
}).catch((error) => {
|
|
235
|
+
if (error?.code === "EADDRINUSE")
|
|
236
|
+
throw new PortInUseFailure();
|
|
237
|
+
throw error;
|
|
238
|
+
});
|
|
239
|
+
boundPort = server.address().port;
|
|
240
|
+
if (listenPort === 0 && String(boundPort) === new URL(connection.origin).port)
|
|
241
|
+
refuse("the MCP port must not be the daemon's port");
|
|
242
|
+
options.signal?.addEventListener("abort", () => void closeAll(), { once: true });
|
|
243
|
+
if (options.signal?.aborted)
|
|
244
|
+
void closeAll();
|
|
245
|
+
return {
|
|
246
|
+
url: `http://${HOST}:${boundPort}${ENDPOINT_PATH}`,
|
|
247
|
+
port: boundPort,
|
|
248
|
+
close: closeAll,
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
catch (error) {
|
|
252
|
+
await closeAll();
|
|
253
|
+
throw error instanceof McpFailure ? error : safeFailure(error);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Reads the token line from `stdin`, serves, and resolves once the server is closed: on stdin
|
|
258
|
+
* EOF/close/error (the parent is gone), or when `signal` aborts. The token line must end in a
|
|
259
|
+
* newline and is at most 256 bytes; anything after it is discarded.
|
|
260
|
+
*/
|
|
261
|
+
export async function serveDesktopLocalFromStdin(stdin, options, onListening) {
|
|
262
|
+
let ended = false;
|
|
263
|
+
const endedPromise = new Promise((resolve) => {
|
|
264
|
+
const done = () => {
|
|
265
|
+
ended = true;
|
|
266
|
+
resolve();
|
|
267
|
+
};
|
|
268
|
+
stdin.once("end", done);
|
|
269
|
+
stdin.once("close", done);
|
|
270
|
+
stdin.once("error", done);
|
|
271
|
+
});
|
|
272
|
+
const { tokenDeadlineMs = TOKEN_DEADLINE_MS, ...serveOptions } = options;
|
|
273
|
+
const token = await new Promise((resolve) => {
|
|
274
|
+
let text = "";
|
|
275
|
+
const timer = setTimeout(() => onStop(), tokenDeadlineMs);
|
|
276
|
+
const onData = (chunk) => {
|
|
277
|
+
text += typeof chunk === "string" ? chunk : chunk.toString("latin1");
|
|
278
|
+
const nl = text.indexOf("\n");
|
|
279
|
+
if (nl !== -1 || text.length > TOKEN_LINE_MAX) {
|
|
280
|
+
cleanup();
|
|
281
|
+
resolve(nl !== -1 && nl <= TOKEN_LINE_MAX ? text.slice(0, nl).replace(/\r$/, "") : undefined);
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
const onStop = () => {
|
|
285
|
+
cleanup();
|
|
286
|
+
resolve(undefined);
|
|
287
|
+
};
|
|
288
|
+
const cleanup = () => {
|
|
289
|
+
clearTimeout(timer);
|
|
290
|
+
stdin.off("data", onData);
|
|
291
|
+
stdin.off("end", onStop);
|
|
292
|
+
stdin.off("close", onStop);
|
|
293
|
+
stdin.off("error", onStop);
|
|
294
|
+
};
|
|
295
|
+
stdin.on("data", onData);
|
|
296
|
+
stdin.once("end", onStop);
|
|
297
|
+
stdin.once("close", onStop);
|
|
298
|
+
stdin.once("error", onStop);
|
|
299
|
+
});
|
|
300
|
+
const drain = () => { };
|
|
301
|
+
try {
|
|
302
|
+
if (token === undefined)
|
|
303
|
+
refuse("the MCP token was not received on stdin");
|
|
304
|
+
// Keep draining so EOF is observed, but never keep anything after the token line.
|
|
305
|
+
stdin.on("data", drain);
|
|
306
|
+
if (ended)
|
|
307
|
+
refuse("stdin closed before the server started");
|
|
308
|
+
const handle = await serveDesktopLocalHttp({ ...serveOptions, token });
|
|
309
|
+
onListening?.(handle);
|
|
310
|
+
const aborted = new Promise((resolve) => {
|
|
311
|
+
if (serveOptions.signal?.aborted)
|
|
312
|
+
return resolve();
|
|
313
|
+
serveOptions.signal?.addEventListener("abort", () => resolve(), { once: true });
|
|
314
|
+
});
|
|
315
|
+
await Promise.race([endedPromise, aborted]);
|
|
316
|
+
await handle.close();
|
|
317
|
+
}
|
|
318
|
+
finally {
|
|
319
|
+
// A failed start must not leave an open stdin keeping the process alive.
|
|
320
|
+
stdin.off("data", drain);
|
|
321
|
+
stdin.pause();
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
//# sourceMappingURL=http-local.js.map
|
package/dist/http.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type IncomingMessage } from "node:http";
|
|
1
2
|
import { type DiscoveryOptions } from "./connection.js";
|
|
2
3
|
/** OAuth scopes this resource server understands. Nothing else widens or changes the tool set. */
|
|
3
4
|
export declare const HTTP_SCOPE_READ = "ant0.read";
|
|
@@ -42,6 +43,7 @@ export interface HttpServerHandle {
|
|
|
42
43
|
readonly port: number;
|
|
43
44
|
close(): Promise<void>;
|
|
44
45
|
}
|
|
46
|
+
export declare const MAX_TOKEN_CHARS = 8192;
|
|
45
47
|
/**
|
|
46
48
|
* HTTP options from the environment, or undefined unless `ANT0_MCP_HTTP=1`.
|
|
47
49
|
* ANT0_MCP_HTTP_HOST / ANT0_MCP_HTTP_PORT (default 127.0.0.1:27180),
|
|
@@ -50,6 +52,11 @@ export interface HttpServerHandle {
|
|
|
50
52
|
* position), ANT0_MCP_ALLOWED_ORIGINS (comma list of full origins, e.g. https://app.example.test).
|
|
51
53
|
*/
|
|
52
54
|
export declare function httpOptionsFromEnv(env?: Record<string, string | undefined>): HttpOptions | undefined;
|
|
55
|
+
/** Rewrites every JSON-RPC error in a JSON or SSE response; results and other bodies pass. */
|
|
56
|
+
export declare function sanitizeResponse(response: Response): Promise<Response>;
|
|
57
|
+
/** Read a body of at most `limit` bytes, or undefined when it is larger (or the client aborts). */
|
|
58
|
+
export declare function boundedBody(req: IncomingMessage, limit: number): Promise<Buffer | undefined>;
|
|
59
|
+
export declare function webHeaders(req: IncomingMessage): Headers;
|
|
53
60
|
/**
|
|
54
61
|
* Serve the Streamable HTTP endpoint as an OAuth resource server. Opt-in only; it refuses to
|
|
55
62
|
* start without a delegated API key credential, a canonical resource URL and at least one
|
package/dist/http.js
CHANGED
|
@@ -34,7 +34,7 @@ export function toolsForHttpScope(scope) {
|
|
|
34
34
|
});
|
|
35
35
|
}
|
|
36
36
|
const DEFAULT_PORT = 27180;
|
|
37
|
-
const MAX_TOKEN_CHARS = 8192;
|
|
37
|
+
export const MAX_TOKEN_CHARS = 8192;
|
|
38
38
|
const ALGORITHMS = [
|
|
39
39
|
"RS256",
|
|
40
40
|
"RS384",
|
|
@@ -150,7 +150,7 @@ function sanitizeJsonText(text) {
|
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
152
|
/** Rewrites every JSON-RPC error in a JSON or SSE response; results and other bodies pass. */
|
|
153
|
-
async function sanitizeResponse(response) {
|
|
153
|
+
export async function sanitizeResponse(response) {
|
|
154
154
|
const type = response.headers.get("content-type") ?? "";
|
|
155
155
|
const headers = new Headers(response.headers);
|
|
156
156
|
headers.delete("content-length");
|
|
@@ -279,7 +279,7 @@ function authInfo(payload, resource) {
|
|
|
279
279
|
};
|
|
280
280
|
}
|
|
281
281
|
/** Read a body of at most `limit` bytes, or undefined when it is larger (or the client aborts). */
|
|
282
|
-
async function boundedBody(req, limit) {
|
|
282
|
+
export async function boundedBody(req, limit) {
|
|
283
283
|
const declared = req.headers["content-length"];
|
|
284
284
|
if (declared !== undefined && (!/^\d+$/.test(declared) || Number(declared) > limit))
|
|
285
285
|
return undefined;
|
|
@@ -293,7 +293,7 @@ async function boundedBody(req, limit) {
|
|
|
293
293
|
}
|
|
294
294
|
return Buffer.concat(chunks);
|
|
295
295
|
}
|
|
296
|
-
function webHeaders(req) {
|
|
296
|
+
export function webHeaders(req) {
|
|
297
297
|
const headers = new Headers();
|
|
298
298
|
for (const [name, value] of Object.entries(req.headers)) {
|
|
299
299
|
if (value === undefined)
|