@agentproto/collect 0.0.0 → 0.1.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 +599 -2
- package/dist/chunk-FQLYZIVI.mjs +405 -0
- package/dist/chunk-FQLYZIVI.mjs.map +1 -0
- package/dist/chunk-SOLT3HJH.mjs +213 -0
- package/dist/chunk-SOLT3HJH.mjs.map +1 -0
- package/dist/chunk-SYTQ6RN6.mjs +98 -0
- package/dist/chunk-SYTQ6RN6.mjs.map +1 -0
- package/dist/connector-DUNy3vSU.d.ts +981 -0
- package/dist/connectors.d.ts +104 -0
- package/dist/connectors.mjs +1197 -0
- package/dist/connectors.mjs.map +1 -0
- package/dist/engine-BRXHKg5A.d.ts +384 -0
- package/dist/index.d.ts +88 -583
- package/dist/index.mjs +1463 -317
- package/dist/index.mjs.map +1 -1
- package/dist/node.d.ts +526 -0
- package/dist/node.mjs +2322 -0
- package/dist/node.mjs.map +1 -0
- package/package.json +13 -2
package/dist/node.d.ts
ADDED
|
@@ -0,0 +1,526 @@
|
|
|
1
|
+
import { C as CollectStore, a as Clock } from './engine-BRXHKg5A.js';
|
|
2
|
+
import { D as HttpTransport, b as SecretsPort, l as BrowserTransport, B as BrowserPage } from './connector-DUNy3vSU.js';
|
|
3
|
+
import 'zod';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Rewrites the store at `root` from schema version N to N + 1. It runs under
|
|
7
|
+
* the store lock but may be interrupted (crash, kill) and run again on the
|
|
8
|
+
* same store: write it so that running it twice is safe (idempotent).
|
|
9
|
+
*/
|
|
10
|
+
type StoreMigration = (ctx: {
|
|
11
|
+
root: string;
|
|
12
|
+
}) => Promise<void>;
|
|
13
|
+
interface OpenStoreOptions {
|
|
14
|
+
/** Migrations keyed by the version they start from: `{ 0: v0ToV1 }` moves a v0 store to v1. Chained up to the current version, under the store lock. */
|
|
15
|
+
migrations?: Record<number, StoreMigration>;
|
|
16
|
+
/** Clock used for run and lock timestamps. */
|
|
17
|
+
now?: () => string;
|
|
18
|
+
/** Tells whether a process id is alive; used to detect a stale lock. Defaults to `process.kill(pid, 0)`. */
|
|
19
|
+
pidAlive?: (pid: number) => boolean;
|
|
20
|
+
}
|
|
21
|
+
declare class StoreNotFoundError extends Error {
|
|
22
|
+
readonly path: string;
|
|
23
|
+
readonly code = "STORE_NOT_FOUND";
|
|
24
|
+
constructor(path: string);
|
|
25
|
+
}
|
|
26
|
+
declare class StoreMigrationError extends Error {
|
|
27
|
+
readonly code = "STORE_MIGRATION";
|
|
28
|
+
constructor(message: string);
|
|
29
|
+
}
|
|
30
|
+
/** Create a store at `path`, or open it when it already exists. Safe to call concurrently. */
|
|
31
|
+
declare function initStore(path: string, options?: OpenStoreOptions): Promise<CollectStore>;
|
|
32
|
+
/**
|
|
33
|
+
* Open an existing store. A store with a newer schema version is refused with
|
|
34
|
+
* `StoreVersionError`. A store with an older one is migrated through
|
|
35
|
+
* `options.migrations`, under the store lock (so it throws `StoreLockedError`
|
|
36
|
+
* when another writer holds it); the version is read again once the lock is
|
|
37
|
+
* held, and `collect.json` is rewritten after each step.
|
|
38
|
+
*/
|
|
39
|
+
declare function openStore(path: string, options?: OpenStoreOptions): Promise<CollectStore>;
|
|
40
|
+
|
|
41
|
+
interface HttpTransportOptions {
|
|
42
|
+
/** Per-request timeout, covering connect, headers and body. Default 30000. A request's own `timeoutMs` wins. */
|
|
43
|
+
timeoutMs?: number;
|
|
44
|
+
/** Attempts per request, first one included. Default 3. */
|
|
45
|
+
maxAttempts?: number;
|
|
46
|
+
/** First backoff step. Default 500. Step n waits between half and all of `min(base * 2^(n-1), maxBackoffMs)`. */
|
|
47
|
+
baseDelayMs?: number;
|
|
48
|
+
/** Ceiling of one backoff step. Default 10000. */
|
|
49
|
+
maxBackoffMs?: number;
|
|
50
|
+
/**
|
|
51
|
+
* Longest `Retry-After` honoured. A longer one makes the request give up at
|
|
52
|
+
* once with cause `http` and the response status (429 or 503). Default 30000.
|
|
53
|
+
* Only a 429 then falls back in the engine; a 503 is a final `http` failure.
|
|
54
|
+
*/
|
|
55
|
+
maxRetryAfterMs?: number;
|
|
56
|
+
/**
|
|
57
|
+
* Minimum gap between two sends to the same host. Default 1000, 0 turns the
|
|
58
|
+
* limiter off. This is the one pacing point at the send boundary: it paces
|
|
59
|
+
* the first send, every retry and every redirect hop. The collect engine
|
|
60
|
+
* has its own per-host gate (the connector's `pace.delayMs`) that paces the
|
|
61
|
+
* start of each task, so the first send of a task is paced by both; the two
|
|
62
|
+
* overlap (the later deadline wins) and do not add up. Retries and redirect
|
|
63
|
+
* hops never go back through the engine, so only this limiter paces them:
|
|
64
|
+
* inside the engine, set it to the gap you want between those extra sends
|
|
65
|
+
* (0 leaves them unpaced). A wait in its queue ends when the request is
|
|
66
|
+
* aborted.
|
|
67
|
+
*/
|
|
68
|
+
minIntervalMs?: number;
|
|
69
|
+
/** Value of `User-Agent` unless the request sets one. Default `agentproto-collect`. */
|
|
70
|
+
userAgent?: string;
|
|
71
|
+
/** Response size cap in bytes. Default 10 MiB. See `createHttpTransport`. */
|
|
72
|
+
maxBytes?: number;
|
|
73
|
+
/** Redirect hops followed per request. Default 10. */
|
|
74
|
+
maxRedirects?: number;
|
|
75
|
+
/** Also retry POST and PATCH on network errors and 5xx. Default false. */
|
|
76
|
+
retryUnsafeMethods?: boolean;
|
|
77
|
+
/** Injectable for tests: `[0, 1)`. Default `Math.random`. */
|
|
78
|
+
random?: () => number;
|
|
79
|
+
/** Injectable for tests: time and sleep. Default system time. */
|
|
80
|
+
clock?: Clock;
|
|
81
|
+
/** Injectable for tests. Default global `fetch`. */
|
|
82
|
+
fetch?: typeof fetch;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* `Retry-After` in milliseconds, relative to `now`. Accepts a non-negative
|
|
86
|
+
* integer number of seconds, or an HTTP date in IMF-fixdate, RFC 850 or
|
|
87
|
+
* asctime form (GMT). Anything else is ignored (`undefined`).
|
|
88
|
+
*/
|
|
89
|
+
declare function parseRetryAfter(value: string | undefined, now: number): number | undefined;
|
|
90
|
+
/**
|
|
91
|
+
* Real HTTP transport on Node's global `fetch`.
|
|
92
|
+
*
|
|
93
|
+
* - **Timeout**: one deadline per attempt (connect, headers, body). Exceeding
|
|
94
|
+
* it is a `network` error, unless the status line already arrived: then the
|
|
95
|
+
* status decides (see below).
|
|
96
|
+
* - **Retries**: network errors, 429 and 5xx are retried up to `maxAttempts`
|
|
97
|
+
* with exponential backoff and jitter. 429 and 503 wait for `Retry-After`
|
|
98
|
+
* (seconds or date) instead, unless it exceeds `maxRetryAfterMs`, in which
|
|
99
|
+
* case the request gives up at once. A challenge page is never retried.
|
|
100
|
+
* POST and PATCH are not retried unless `retryUnsafeMethods`.
|
|
101
|
+
* - **Redirects** are followed by hand (so the limiter and credential
|
|
102
|
+
* stripping apply to each hop); the returned `url` is the final one.
|
|
103
|
+
* Credential headers (`Authorization`, `Cookie`, `Proxy-Authorization` and
|
|
104
|
+
* the request's `credentialHeaders`) are dropped when a hop changes origin;
|
|
105
|
+
* a request with `urlCredential` refuses such a hop with a `blocked` error.
|
|
106
|
+
* A 301/302 on POST and any 303 become a GET without the body headers.
|
|
107
|
+
* - **Size cap**: a 2xx body larger than `maxBytes` (declared by
|
|
108
|
+
* `Content-Length` or counted while streaming) aborts the transfer and
|
|
109
|
+
* fails with cause `http` and the response status, never retried. The body
|
|
110
|
+
* of a non-2xx response is truncated to the cap, not failed.
|
|
111
|
+
* - **Errors**, all `TransportError`: 401/403 `blocked`; a verification page
|
|
112
|
+
* `challenge` (see `looksLikeChallenge` rules in the README); 429 or 5xx once
|
|
113
|
+
* retries are used up and any other non-2xx `http` with the status; an empty
|
|
114
|
+
* 2xx body `empty`; DNS, reset, TLS, timeout, abort `network`. Once the
|
|
115
|
+
* headers of an error response arrived, its status and `Retry-After` are
|
|
116
|
+
* kept: a body that stalls or resets is cut short and the response still
|
|
117
|
+
* classifies by status. A caller cancellation always wins.
|
|
118
|
+
* - **Limiter**: one pacing point at the send boundary, first send, retries and
|
|
119
|
+
* redirect hops alike; see `minIntervalMs`. Waits in its queue are abortable.
|
|
120
|
+
*
|
|
121
|
+
* Options are validated: a non-finite, negative or out-of-range value throws
|
|
122
|
+
* a `RangeError`. No third-party dependency, no logging.
|
|
123
|
+
*/
|
|
124
|
+
declare function createHttpTransport(options?: HttpTransportOptions): HttpTransport;
|
|
125
|
+
|
|
126
|
+
/** How the secret is sent. */
|
|
127
|
+
type ApiAuth = {
|
|
128
|
+
type: "bearer";
|
|
129
|
+
secret: string;
|
|
130
|
+
}
|
|
131
|
+
/** `value` is `prefix + secret`; `prefix` defaults to nothing. */
|
|
132
|
+
| {
|
|
133
|
+
type: "header";
|
|
134
|
+
name: string;
|
|
135
|
+
secret: string;
|
|
136
|
+
prefix?: string;
|
|
137
|
+
} | {
|
|
138
|
+
type: "query";
|
|
139
|
+
name: string;
|
|
140
|
+
secret: string;
|
|
141
|
+
};
|
|
142
|
+
interface ApiTransportOptions {
|
|
143
|
+
/** Transport the requests go through (usually `createHttpTransport()`). */
|
|
144
|
+
http: HttpTransport;
|
|
145
|
+
secrets: SecretsPort;
|
|
146
|
+
auth: ApiAuth;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* `api` transport: adds the auth header (or query parameter) read from the
|
|
150
|
+
* `SecretsPort` on every request, then delegates to `http`.
|
|
151
|
+
*
|
|
152
|
+
* - A query-parameter secret marks the request `urlCredential`: the HTTP
|
|
153
|
+
* transport refuses a redirect to another origin.
|
|
154
|
+
* - A missing or empty secret throws `MissingSecretError` before any request;
|
|
155
|
+
* the engine records the task as `skipped`.
|
|
156
|
+
* - The secret value never leaves this function. Successful responses and
|
|
157
|
+
* errors are rebuilt with every occurrence of the value (raw, percent-encoded
|
|
158
|
+
* and form-encoded) replaced by `[redacted]` in the body bytes, the response
|
|
159
|
+
* headers, the message and the URL; the underlying error object is dropped
|
|
160
|
+
* and a query-parameter secret is removed from the returned `url`.
|
|
161
|
+
* - A header secret is marked as a credential header, so the HTTP transport
|
|
162
|
+
* drops it if a redirect leaves the origin.
|
|
163
|
+
*/
|
|
164
|
+
declare function createApiTransport(options: ApiTransportOptions): HttpTransport;
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Minimal MCP client over streamable HTTP, Node built-ins only.
|
|
168
|
+
*
|
|
169
|
+
* - `initialize`, `notifications/initialized`, `tools/list`, `tools/call`.
|
|
170
|
+
* - Replies are plain JSON or `text/event-stream`. An event stream is read
|
|
171
|
+
* incrementally: complete frames are consumed once, CR, LF and CRLF line
|
|
172
|
+
* ends are accepted, and only the JSON-RPC response whose id matches the
|
|
173
|
+
* request counts. Notifications and anything else are ignored.
|
|
174
|
+
* - The session id and the negotiated protocol version are taken from a
|
|
175
|
+
* successful `initialize` only, and sent back afterwards. A server that
|
|
176
|
+
* gives no session id is used statelessly. A 404 on a live session starts
|
|
177
|
+
* one serialised re-initialisation.
|
|
178
|
+
* - Every call has a timeout and honours an `AbortSignal`.
|
|
179
|
+
* - Remote text is scrubbed of the configured header values before it leaves
|
|
180
|
+
* the client, field by field: text content, structured string values, error
|
|
181
|
+
* messages, error data and causes. Protocol control fields (`isError`,
|
|
182
|
+
* `type`, the shape of the result) are never touched. A text that carries a
|
|
183
|
+
* value in a wrapped form (percent-encoded in either case, `\uXXXX` or
|
|
184
|
+
* other JSON escapes, double-encoded), or split across result blocks, is
|
|
185
|
+
* dropped whole and replaced by a fixed notice: it cannot be classified safely.
|
|
186
|
+
*/
|
|
187
|
+
type McpErrorKind = "http" | "rpc" | "protocol" | "timeout" | "aborted" | "network";
|
|
188
|
+
declare class McpError extends Error {
|
|
189
|
+
readonly kind: McpErrorKind;
|
|
190
|
+
/** JSON-RPC error code, when the failure is a JSON-RPC error. */
|
|
191
|
+
readonly code: number | undefined;
|
|
192
|
+
/** HTTP status of the response the failure came with, when there was one. */
|
|
193
|
+
readonly status: number | undefined;
|
|
194
|
+
readonly data: unknown;
|
|
195
|
+
constructor(kind: McpErrorKind, message: string, options?: {
|
|
196
|
+
code?: number;
|
|
197
|
+
status?: number;
|
|
198
|
+
data?: unknown;
|
|
199
|
+
origin?: unknown;
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
interface McpTool {
|
|
203
|
+
name: string;
|
|
204
|
+
description?: string;
|
|
205
|
+
inputSchema?: unknown;
|
|
206
|
+
}
|
|
207
|
+
interface McpContentBlock {
|
|
208
|
+
type: string;
|
|
209
|
+
text?: string;
|
|
210
|
+
[key: string]: unknown;
|
|
211
|
+
}
|
|
212
|
+
interface McpToolResult {
|
|
213
|
+
content?: McpContentBlock[];
|
|
214
|
+
structuredContent?: unknown;
|
|
215
|
+
isError?: boolean;
|
|
216
|
+
}
|
|
217
|
+
interface McpCallOptions {
|
|
218
|
+
signal?: AbortSignal;
|
|
219
|
+
timeoutMs?: number;
|
|
220
|
+
/**
|
|
221
|
+
* Ignore the client-wide signal: the call has only its own timeout (and
|
|
222
|
+
* `signal`). Cleanup calls use it, so a cancelled run can still close its tabs.
|
|
223
|
+
*/
|
|
224
|
+
detached?: boolean;
|
|
225
|
+
/**
|
|
226
|
+
* `callTool` only. Default true: the result's remote text is scrubbed as it
|
|
227
|
+
* comes. A caller that unwraps or decodes the payload itself (a proxy wrapper,
|
|
228
|
+
* a JSON text) passes false, decodes first, and then scrubs only the payload
|
|
229
|
+
* fields with `scrubResult` or `scrubValue`.
|
|
230
|
+
*/
|
|
231
|
+
scrub?: boolean;
|
|
232
|
+
}
|
|
233
|
+
interface McpClientOptions {
|
|
234
|
+
/** Streamable-HTTP endpoint, e.g. `http://127.0.0.1:3000/mcp`. */
|
|
235
|
+
endpoint: string;
|
|
236
|
+
/** Extra headers on every request (authentication). Never logged; their values are scrubbed from every remote message. */
|
|
237
|
+
headers?: Record<string, string>;
|
|
238
|
+
/** More values to scrub from remote messages. */
|
|
239
|
+
redact?: string[];
|
|
240
|
+
/** Defaults to `2025-06-18`. */
|
|
241
|
+
protocolVersion?: string;
|
|
242
|
+
/** Per request; defaults to 30 000 ms. */
|
|
243
|
+
timeoutMs?: number;
|
|
244
|
+
/** Aborts every request of this client, except detached calls. */
|
|
245
|
+
signal?: AbortSignal;
|
|
246
|
+
clientInfo?: {
|
|
247
|
+
name: string;
|
|
248
|
+
version: string;
|
|
249
|
+
};
|
|
250
|
+
/** Replaces the global `fetch` (tests, proxies). */
|
|
251
|
+
fetch?: typeof fetch;
|
|
252
|
+
}
|
|
253
|
+
interface McpClient {
|
|
254
|
+
/** Handshake. Called by the other methods when needed; calling it twice is harmless. */
|
|
255
|
+
initialize(options?: McpCallOptions): Promise<void>;
|
|
256
|
+
listTools(options?: McpCallOptions): Promise<McpTool[]>;
|
|
257
|
+
callTool(name: string, args?: Record<string, unknown>, options?: McpCallOptions): Promise<McpToolResult>;
|
|
258
|
+
/** Ends the session when the server gave one. Best effort, never throws. */
|
|
259
|
+
close(): Promise<void>;
|
|
260
|
+
/** Session id the server assigned, if any. */
|
|
261
|
+
readonly sessionId: string | undefined;
|
|
262
|
+
/** Protocol version in use (the server's answer to `initialize`, else the requested one). */
|
|
263
|
+
readonly protocolVersion: string;
|
|
264
|
+
/** The same scrubbing the client applies to remote text. */
|
|
265
|
+
scrub(text: string): string;
|
|
266
|
+
/** Scrub a tool result's payload fields (never `isError`, `type` or the shape). */
|
|
267
|
+
scrubResult(result: McpToolResult): McpToolResult;
|
|
268
|
+
/** Scrub the string values of decoded data (keys are kept unless `keys` is true). */
|
|
269
|
+
scrubValue<T>(value: T, keys?: boolean): T;
|
|
270
|
+
}
|
|
271
|
+
declare const DEFAULT_PROTOCOL_VERSION = "2025-06-18";
|
|
272
|
+
/** Shown in place of a remote text that carried a credential in a form that cannot be cut out safely. */
|
|
273
|
+
declare const REDACTED_NOTICE = "[redacted: the remote text carried a credential]";
|
|
274
|
+
interface Scrubber {
|
|
275
|
+
/** Text with every raw occurrence replaced; whole text replaced by the notice when a wrapped form remains. */
|
|
276
|
+
text(text: string): string;
|
|
277
|
+
/** Text blocks scrubbed one by one, then as their concatenation: a value split across blocks drops them all. */
|
|
278
|
+
blocks(texts: string[]): string[];
|
|
279
|
+
/** Every string value (and key, when `keys`) of a JSON-like value; the structure is untouched. Returns a copy. */
|
|
280
|
+
values<T>(value: T, keys?: boolean): T;
|
|
281
|
+
/** A tool descriptor: its name and the keywords and property names of its schema are protocol and stay; its human text is scrubbed. */
|
|
282
|
+
tool<T extends {
|
|
283
|
+
name: string;
|
|
284
|
+
}>(tool: T): T;
|
|
285
|
+
/** Does the text carry a value, in any supported form. */
|
|
286
|
+
carries(text: string): boolean;
|
|
287
|
+
}
|
|
288
|
+
/** Values of any length count; empty ones do not. */
|
|
289
|
+
declare function createScrubber(values: string[]): Scrubber;
|
|
290
|
+
/** Kept for callers that only need text scrubbing. */
|
|
291
|
+
declare function createRedactor(values: string[]): (text: string) => string;
|
|
292
|
+
interface RpcMessage {
|
|
293
|
+
jsonrpc?: string;
|
|
294
|
+
id?: number | string | null;
|
|
295
|
+
result?: unknown;
|
|
296
|
+
error?: {
|
|
297
|
+
code?: number;
|
|
298
|
+
message?: string;
|
|
299
|
+
data?: unknown;
|
|
300
|
+
};
|
|
301
|
+
method?: string;
|
|
302
|
+
}
|
|
303
|
+
interface SseEvent {
|
|
304
|
+
event: string;
|
|
305
|
+
data: string;
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Incremental Server-Sent Events parser. Feed it chunks as they arrive; it
|
|
309
|
+
* returns each event once, when its frame is complete. A bare CR, a bare LF and
|
|
310
|
+
* CRLF each end a line (a CRLF cut between two chunks too), and multi-byte
|
|
311
|
+
* characters split across chunks are decoded whole.
|
|
312
|
+
*/
|
|
313
|
+
declare class SseParser {
|
|
314
|
+
private readonly decoder;
|
|
315
|
+
private line;
|
|
316
|
+
private skipLf;
|
|
317
|
+
private data;
|
|
318
|
+
private event;
|
|
319
|
+
push(chunk: Uint8Array | string): SseEvent[];
|
|
320
|
+
}
|
|
321
|
+
/** JSON payloads of the `message` events in a complete SSE text. */
|
|
322
|
+
declare function parseSseMessages(text: string): RpcMessage[];
|
|
323
|
+
declare function createMcpClient(options: McpClientOptions): McpClient;
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* Browser transport over an MCP client.
|
|
327
|
+
*
|
|
328
|
+
* It drives an already-connected browser through a tool profile (the names of
|
|
329
|
+
* the tools and the shape of their arguments and results), optionally behind a
|
|
330
|
+
* proxy tool that takes `{ alias, toolName, args }`.
|
|
331
|
+
*
|
|
332
|
+
* Rules, all enforced here:
|
|
333
|
+
* - read-only: there is no click, type or form operation, and `fetchInPage`
|
|
334
|
+
* only sends GET or HEAD. Connectors must never open a compose or publish
|
|
335
|
+
* field;
|
|
336
|
+
* - one new background tab per `open`, closed by `close` (or `closeAll`);
|
|
337
|
+
* a tab this transport did not open is never touched;
|
|
338
|
+
* - slow, irregular pace between page actions, and a cap on pages per run;
|
|
339
|
+
* - a verification or challenge page raises a `challenge` error, which the
|
|
340
|
+
* engine turns into a hard stop of the connector. It is never bypassed.
|
|
341
|
+
*/
|
|
342
|
+
|
|
343
|
+
/** Tool names a profile uses. Each is configurable. */
|
|
344
|
+
interface BrowserToolNames {
|
|
345
|
+
/** Opens a new background tab. Required: the transport never reuses a tab it did not open. */
|
|
346
|
+
newTab: string;
|
|
347
|
+
navigate: string;
|
|
348
|
+
evaluate: string;
|
|
349
|
+
closeTab: string;
|
|
350
|
+
/** Makes a tab the current one, for browsers where tools act on the selected tab. */
|
|
351
|
+
selectTab?: string;
|
|
352
|
+
/** Lists the tabs with their URLs. Used to find tabs this transport opened and could not track (a create that timed out), and to check the selected page. */
|
|
353
|
+
listTabs?: string;
|
|
354
|
+
}
|
|
355
|
+
/** A tab as a listing shows it. */
|
|
356
|
+
interface ListedTab {
|
|
357
|
+
id: string;
|
|
358
|
+
url: string;
|
|
359
|
+
selected?: boolean;
|
|
360
|
+
}
|
|
361
|
+
interface BrowserToolProfile {
|
|
362
|
+
name: string;
|
|
363
|
+
tools: BrowserToolNames;
|
|
364
|
+
/** How `evaluate` receives code: an `expression` to run, or a `function` to call. */
|
|
365
|
+
script: "expression" | "function";
|
|
366
|
+
/**
|
|
367
|
+
* `explicit`: every call names its tab. `selected`: calls act on the browser's
|
|
368
|
+
* selected page, so the transport selects its own page and checks, before each
|
|
369
|
+
* call, that the selected page is still the one it opened. That profile needs
|
|
370
|
+
* a browser session no other client drives.
|
|
371
|
+
*/
|
|
372
|
+
addressing: "explicit" | "selected";
|
|
373
|
+
/** Arguments of each tool. `instance` is the fixed browser instance, when one is set. */
|
|
374
|
+
args: {
|
|
375
|
+
/** `url` is a unique marker URL (`data:text/html,collect-...`) the transport can find the tab by. */
|
|
376
|
+
newTab(url: string, instance?: string): Record<string, unknown>;
|
|
377
|
+
navigate(tab: string, url: string, instance?: string): Record<string, unknown>;
|
|
378
|
+
evaluate(tab: string, code: string, instance?: string): Record<string, unknown>;
|
|
379
|
+
closeTab(tab: string, instance?: string): Record<string, unknown>;
|
|
380
|
+
selectTab?(tab: string, instance?: string): Record<string, unknown>;
|
|
381
|
+
listTabs?(instance?: string): Record<string, unknown>;
|
|
382
|
+
};
|
|
383
|
+
/** The tab id a `newTab` result carries. */
|
|
384
|
+
tabId(result: McpToolResult): string | undefined;
|
|
385
|
+
/** The tabs a `listTabs` result carries. */
|
|
386
|
+
tabs?(result: McpToolResult): ListedTab[];
|
|
387
|
+
/** The JSON value an `evaluate` result carries. Throws a `TransportError` on a truncated or unreadable result. */
|
|
388
|
+
value(result: McpToolResult): unknown;
|
|
389
|
+
/**
|
|
390
|
+
* The server is supposed to route each call to the page the call names, but
|
|
391
|
+
* can be started with routing off (it then acts on the selected page). When
|
|
392
|
+
* set, the transport checks right after a create that a script run on the page
|
|
393
|
+
* it addressed really ran there, and fails closed otherwise.
|
|
394
|
+
*/
|
|
395
|
+
verifyRouting?: boolean;
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* `tab-tools`: `browser_new_tab`, `browser_navigate`,
|
|
399
|
+
* `browser_evaluate { expression, tabId, instance }`, `browser_close_tab`, and
|
|
400
|
+
* `browser_list_owned_tabs` (optional: used to find tabs left by a create that
|
|
401
|
+
* timed out). The evaluate result is JSON text `{ value, truncated }` in
|
|
402
|
+
* `content[0].text`. Every call names its tab.
|
|
403
|
+
*/
|
|
404
|
+
declare const TAB_TOOLS_PROFILE: BrowserToolProfile;
|
|
405
|
+
/**
|
|
406
|
+
* `chrome-devtools` (chrome-devtools-mcp v1.14 and later): every page tool takes
|
|
407
|
+
* the page's stable numeric `pageId` (`select_page`, `close_page`,
|
|
408
|
+
* `navigate_page`, `evaluate_script`), the ids come from `list_pages` and are
|
|
409
|
+
* never reused, so ownership is by id. `new_page` is created on a marker URL
|
|
410
|
+
* and its id is the listed page carrying that exact URL. The transport never
|
|
411
|
+
* changes the browser's selection. If the server runs with page-id routing off
|
|
412
|
+
* it would act on the selected page: the transport checks right after a create
|
|
413
|
+
* that its script ran on the page it addressed, and fails closed otherwise.
|
|
414
|
+
*/
|
|
415
|
+
declare const CHROME_DEVTOOLS_PROFILE: BrowserToolProfile;
|
|
416
|
+
/**
|
|
417
|
+
* `chrome-devtools-index`: the older chrome-devtools-mcp tools, which name pages
|
|
418
|
+
* by index (`pageIdx`) and act on the selected page. Index mode is only a
|
|
419
|
+
* fallback, for servers that return no page id, and it works in exclusive mode:
|
|
420
|
+
* a browser session no other client drives. The transport selects its own page,
|
|
421
|
+
* and before each call lists the pages and checks, by continuity, that the
|
|
422
|
+
* selected page is still its own; it fails closed (typed `blocked`, nothing
|
|
423
|
+
* done) when it cannot re-establish ownership.
|
|
424
|
+
*/
|
|
425
|
+
declare const CHROME_DEVTOOLS_INDEX_PROFILE: BrowserToolProfile;
|
|
426
|
+
declare function browserProfile(name: string): BrowserToolProfile;
|
|
427
|
+
/** Every call goes through one tool taking `{ alias, toolName, args }`. */
|
|
428
|
+
interface BrowserProxy {
|
|
429
|
+
tool: string;
|
|
430
|
+
alias: string;
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* Tool names a profile needs, as the browser names them: the four basic tools,
|
|
434
|
+
* the select tool when the profile has one, and the list tool when the profile
|
|
435
|
+
* must check the selected page.
|
|
436
|
+
*/
|
|
437
|
+
declare function requiredTools(profile: BrowserToolProfile, overrides?: Partial<BrowserToolNames>): string[];
|
|
438
|
+
/**
|
|
439
|
+
* Function body run in the page after a navigation or a page transition.
|
|
440
|
+
* Returns `{ challenge, marker?, url }`. Markers are generic signs of a bot-check
|
|
441
|
+
* interstitial:
|
|
442
|
+
* - elements: a challenge form or running-check container; and, on a short
|
|
443
|
+
* page only (under 3 000 characters of text), a turnstile, captcha or
|
|
444
|
+
* bot-check iframe or widget, since a normal article can carry a captcha
|
|
445
|
+
* badge;
|
|
446
|
+
* - a short page (under 3 000 characters of text) whose text asks to verify
|
|
447
|
+
* the visitor is human, says the browser is being checked, or denies access;
|
|
448
|
+
* - a title such as "Just a moment..." or "Attention Required".
|
|
449
|
+
* Long pages are never judged on text alone, so an article that talks about
|
|
450
|
+
* captchas is not a challenge.
|
|
451
|
+
*/
|
|
452
|
+
declare const CHALLENGE_SCRIPT = "\nconst __check = () => {\nconst body = document.body ? String(document.body.innerText || \"\") : \"\";\n// Containers only a verification page has.\nconst strong = [\"#challenge-form\", \"#cf-challenge-running\", \"#challenge-running\", \"#px-captcha\", \"#sec-if-cpt-container\", \"#captcha-form\", 'form[action*=\"captcha\" i]'];\n// Widgets a normal page can carry too (a reCAPTCHA badge, a turnstile on a sign-up form): they only count on a short page.\nconst widgets = [\".cf-turnstile\", 'iframe[src*=\"challenges.cloudflare.com\"]', 'iframe[src*=\"hcaptcha.com\"]', 'iframe[src*=\"recaptcha\"]', \".g-recaptcha\", \".h-captcha\"];\nfor (const s of body.length < 3000 ? strong.concat(widgets) : strong) {\n let el = null;\n try { el = document.querySelector(s); } catch (e) {}\n if (el) return { challenge: true, marker: s };\n}\nconst title = String(document.title || \"\").toLowerCase();\nfor (const t of [\"just a moment\", \"attention required\", \"access denied\", \"are you a robot\", \"security check\", \"verify you are human\"]) {\n if (title.includes(t)) return { challenge: true, marker: \"title: \" + t };\n}\nif (body.length < 3000) {\n const text = body.toLowerCase();\n for (const t of [\"verify you are human\", \"verifying you are human\", \"checking your browser\", \"checking if the site connection is secure\", \"unusual traffic from your computer\", \"are you a robot\", \"press & hold\", \"please enable javascript and cookies to continue\", \"complete the security check\", \"captcha\"]) {\n if (text.includes(t)) return { challenge: true, marker: \"text: \" + t };\n }\n}\nreturn { challenge: false };\n};\nconst __r = __check();\n__r.url = String(location.href);\nreturn __r;\n";
|
|
453
|
+
/** Same markers as `CHALLENGE_SCRIPT`, applied to a fetched response body. Returns the marker, or undefined. */
|
|
454
|
+
declare function detectChallengeInBody(status: number, contentType: string | undefined, body: string): string | undefined;
|
|
455
|
+
/** Response headers that say a verification is being demanded. */
|
|
456
|
+
declare function challengeInHeaders(headers: Record<string, string> | undefined): string | undefined;
|
|
457
|
+
interface BrowserClock {
|
|
458
|
+
now(): number;
|
|
459
|
+
sleep(ms: number, signal?: AbortSignal): Promise<void>;
|
|
460
|
+
}
|
|
461
|
+
interface BrowserPace {
|
|
462
|
+
/** Shortest wait between two page actions. Default 2 000 ms. */
|
|
463
|
+
minMs?: number;
|
|
464
|
+
/** Longest wait between two page actions. Default 6 000 ms. */
|
|
465
|
+
maxMs?: number;
|
|
466
|
+
/** Shortest wait between two polls of `waitFor`. Default 500 ms. */
|
|
467
|
+
pollMinMs?: number;
|
|
468
|
+
/** Longest wait between two polls of `waitFor`. Default 1 500 ms. */
|
|
469
|
+
pollMaxMs?: number;
|
|
470
|
+
/** Source of randomness in [0, 1). Default `Math.random`. */
|
|
471
|
+
random?: () => number;
|
|
472
|
+
clock?: BrowserClock;
|
|
473
|
+
}
|
|
474
|
+
interface BrowserTransportOptions {
|
|
475
|
+
client: McpClient;
|
|
476
|
+
profile: BrowserToolProfile;
|
|
477
|
+
/** Fixed browser instance, sent as `instance` when the profile supports it. */
|
|
478
|
+
instance?: string;
|
|
479
|
+
/** Reach every tool through one proxy tool. */
|
|
480
|
+
proxy?: BrowserProxy;
|
|
481
|
+
/** Overrides the profile's tool names. */
|
|
482
|
+
tools?: Partial<BrowserToolNames>;
|
|
483
|
+
pace?: BrowserPace;
|
|
484
|
+
/** Most pages (tabs opened, navigations and page transitions) one transport serves. Default 100. */
|
|
485
|
+
maxPages?: number;
|
|
486
|
+
/** Timeout of one navigation. Default 60 000 ms. */
|
|
487
|
+
navigationTimeoutMs?: number;
|
|
488
|
+
/** Timeout of one script. Default 30 000 ms. */
|
|
489
|
+
evaluateTimeoutMs?: number;
|
|
490
|
+
/** Own deadline of each cleanup call (close a tab, list tabs). It does not depend on `signal`. Default 5 000 ms. */
|
|
491
|
+
cleanupTimeoutMs?: number;
|
|
492
|
+
/**
|
|
493
|
+
* How long `closeAll` waits for a create that gave up (timed out or was
|
|
494
|
+
* cancelled) to land, before its final sweep. Only used when such a create
|
|
495
|
+
* left a tab unaccounted for. Default 3 000 ms.
|
|
496
|
+
*/
|
|
497
|
+
lateCreateGraceMs?: number;
|
|
498
|
+
/** Largest body `fetchInPage` returns, in characters. Default 5 000 000. */
|
|
499
|
+
maxBodyChars?: number;
|
|
500
|
+
/** The run's signal: stops paced waits and the calls of an action. Cleanup ignores it. */
|
|
501
|
+
signal?: AbortSignal;
|
|
502
|
+
}
|
|
503
|
+
interface BrowserTransportHandle extends BrowserTransport {
|
|
504
|
+
/**
|
|
505
|
+
* Close every tab this transport opened and has not closed yet, then every
|
|
506
|
+
* tab still carrying one of its markers (a create that timed out and landed
|
|
507
|
+
* late). Uses its own deadline, so it works after a cancellation. Never throws.
|
|
508
|
+
*/
|
|
509
|
+
closeAll(): Promise<void>;
|
|
510
|
+
/** Tabs currently open (opened by this transport, not closed yet). */
|
|
511
|
+
openPages(): BrowserPage[];
|
|
512
|
+
/** Pages used so far against the cap. */
|
|
513
|
+
pagesUsed(): number;
|
|
514
|
+
/** Tabs that were not closed because index-based cleanup could not take the ownership lock in time. They are still open in the browser. */
|
|
515
|
+
leftOpen(): BrowserPage[];
|
|
516
|
+
/** Can this transport list tabs? Without it, a tab whose creation timed out cannot be found afterwards. */
|
|
517
|
+
canList(): Promise<boolean>;
|
|
518
|
+
/**
|
|
519
|
+
* Health probe for `doctor`: open a blank tab, navigate it to a safe `data:`
|
|
520
|
+
* URL, evaluate `1+1` in it, close it. Returns the evaluated value.
|
|
521
|
+
*/
|
|
522
|
+
probe(): Promise<number>;
|
|
523
|
+
}
|
|
524
|
+
declare function createBrowserTransport(options: BrowserTransportOptions): BrowserTransportHandle;
|
|
525
|
+
|
|
526
|
+
export { type ApiAuth, type ApiTransportOptions, type BrowserClock, type BrowserPace, type BrowserProxy, type BrowserToolNames, type BrowserToolProfile, type BrowserTransportHandle, type BrowserTransportOptions, CHALLENGE_SCRIPT, CHROME_DEVTOOLS_INDEX_PROFILE, CHROME_DEVTOOLS_PROFILE, DEFAULT_PROTOCOL_VERSION, type HttpTransportOptions, type ListedTab, type McpCallOptions, type McpClient, type McpClientOptions, type McpContentBlock, McpError, type McpErrorKind, type McpTool, type McpToolResult, type OpenStoreOptions, REDACTED_NOTICE, type Scrubber, type SseEvent, SseParser, type StoreMigration, StoreMigrationError, StoreNotFoundError, TAB_TOOLS_PROFILE, browserProfile, challengeInHeaders, createApiTransport, createBrowserTransport, createHttpTransport, createMcpClient, createRedactor, createScrubber, detectChallengeInBody, initStore, openStore, parseRetryAfter, parseSseMessages, requiredTools };
|