@ant0/mcp 0.0.0-stage → 0.3.22-beta.2

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.
Files changed (52) hide show
  1. package/LICENSE +28 -0
  2. package/README.md +95 -2
  3. package/THIRD_PARTY_NOTICES +311 -0
  4. package/dist/api/generated/schema.d.ts +3856 -0
  5. package/dist/api/generated/schema.js +6 -0
  6. package/dist/api/index.d.ts +171 -0
  7. package/dist/api/index.js +332 -0
  8. package/dist/bin.d.ts +3 -0
  9. package/dist/bin.js +59 -0
  10. package/dist/call-permits.d.ts +10 -0
  11. package/dist/call-permits.js +67 -0
  12. package/dist/connection.d.ts +20 -0
  13. package/dist/connection.js +157 -0
  14. package/dist/credential-file.d.ts +33 -0
  15. package/dist/credential-file.js +773 -0
  16. package/dist/daemon.d.ts +7 -0
  17. package/dist/daemon.js +260 -0
  18. package/dist/errors.d.ts +69 -0
  19. package/dist/errors.js +78 -0
  20. package/dist/export-files.d.ts +37 -0
  21. package/dist/export-files.js +167 -0
  22. package/dist/grant.d.ts +5 -0
  23. package/dist/grant.js +11 -0
  24. package/dist/http.d.ts +59 -0
  25. package/dist/http.js +556 -0
  26. package/dist/index.d.ts +19 -0
  27. package/dist/index.js +85 -0
  28. package/dist/key-contract.d.ts +325 -0
  29. package/dist/key-contract.js +241 -0
  30. package/dist/limits.d.ts +22 -0
  31. package/dist/limits.js +22 -0
  32. package/dist/local-routes.d.ts +26 -0
  33. package/dist/local-routes.js +146 -0
  34. package/dist/output-descriptor.d.ts +3 -0
  35. package/dist/output-descriptor.js +19 -0
  36. package/dist/output-worker-body.d.ts +3 -0
  37. package/dist/output-worker-body.js +77 -0
  38. package/dist/output-worker.d.ts +2 -0
  39. package/dist/output-worker.js +4 -0
  40. package/dist/output-writer.d.ts +39 -0
  41. package/dist/output-writer.js +199 -0
  42. package/dist/peer-watchdog.d.ts +4 -0
  43. package/dist/peer-watchdog.js +55 -0
  44. package/dist/server.d.ts +28 -0
  45. package/dist/server.js +33 -0
  46. package/dist/text-budget.d.ts +13 -0
  47. package/dist/text-budget.js +42 -0
  48. package/dist/tools.d.ts +38 -0
  49. package/dist/tools.js +1284 -0
  50. package/dist/transport.d.ts +45 -0
  51. package/dist/transport.js +313 -0
  52. package/package.json +66 -4
@@ -0,0 +1,45 @@
1
+ import type { Readable, Writable } from "node:stream";
2
+ import { type JSONRPCMessage, type Transport } from "@modelcontextprotocol/server";
3
+ import { McpFailure, type FailureCode } from "./errors.js";
4
+ import { type OutputWorkerCommand } from "./output-writer.js";
5
+ /** The only revision a request envelope may name; this adapter serves no other per-request one. */
6
+ export declare const MODERN_VERSIONS: readonly ["2026-07-28"];
7
+ /** SDK transport with byte-bounded framing and writes. The SDK owns protocol and cancellation. */
8
+ export declare class BoundedStdioTransport implements Transport {
9
+ private readonly input;
10
+ private readonly output;
11
+ private readonly outputWorkerCommand?;
12
+ onclose?: () => void;
13
+ onerror?: (error: Error) => void;
14
+ onmessage?: NonNullable<Transport["onmessage"]>;
15
+ readonly done: Promise<McpFailure | undefined>;
16
+ /** Aborted the moment the transport shuts down (EOF, failure or close), before `done` settles. */
17
+ readonly closedSignal: AbortSignal;
18
+ private readonly closeController;
19
+ private finish;
20
+ private closed;
21
+ private started;
22
+ private frame;
23
+ private size;
24
+ private pending;
25
+ private sdkRequests;
26
+ private nextRequestId;
27
+ private writes;
28
+ private outputBytes;
29
+ private writer;
30
+ private closing;
31
+ constructor(input: Readable, output: Writable, outputWorkerCommand?: OutputWorkerCommand | undefined);
32
+ start(): Promise<void>;
33
+ private onData;
34
+ private onEnd;
35
+ private onInputError;
36
+ private onOutputError;
37
+ private onOutputClose;
38
+ send(message: JSONRPCMessage): Promise<void>;
39
+ private writeMessage;
40
+ fail(code: FailureCode): void;
41
+ private finishRequest;
42
+ close(): Promise<void>;
43
+ private shutdown;
44
+ }
45
+ //# sourceMappingURL=transport.d.ts.map
@@ -0,0 +1,313 @@
1
+ import { deserializeMessage, isJSONRPCRequest, serializeMessage, } from "@modelcontextprotocol/server";
2
+ import { McpFailure } from "./errors.js";
3
+ import { LIMITS } from "./limits.js";
4
+ import { OutputWriter } from "./output-writer.js";
5
+ /** The two fields of `notifications/cancelled` that this transport reads; anything else throws. */
6
+ function cancelledNotification(message) {
7
+ const params = "params" in message ? message.params : undefined;
8
+ if (!params || typeof params !== "object" || Array.isArray(params))
9
+ throw new Error("frame");
10
+ const { requestId, reason } = params;
11
+ if (requestId !== undefined && typeof requestId !== "string" && typeof requestId !== "number")
12
+ throw new Error("frame");
13
+ if (reason !== undefined && typeof reason !== "string")
14
+ throw new Error("frame");
15
+ return { jsonrpc: "2.0", method: "notifications/cancelled", params: params };
16
+ }
17
+ /** Request `_meta` key that carries the per-request protocol revision (2026-07-28). */
18
+ const PROTOCOL_VERSION_KEY = "io.modelcontextprotocol/protocolVersion";
19
+ /** The only revision a request envelope may name; this adapter serves no other per-request one. */
20
+ export const MODERN_VERSIONS = ["2026-07-28"];
21
+ /** The protocol revision a request envelope claims, if it claims one. */
22
+ function claimedVersion(message) {
23
+ const params = "params" in message ? message.params : undefined;
24
+ if (!params || typeof params !== "object")
25
+ return undefined;
26
+ const meta = params._meta;
27
+ if (!meta || typeof meta !== "object")
28
+ return undefined;
29
+ return meta[PROTOCOL_VERSION_KEY];
30
+ }
31
+ /** SDK transport with byte-bounded framing and writes. The SDK owns protocol and cancellation. */
32
+ export class BoundedStdioTransport {
33
+ input;
34
+ output;
35
+ outputWorkerCommand;
36
+ onclose;
37
+ onerror;
38
+ onmessage;
39
+ done;
40
+ /** Aborted the moment the transport shuts down (EOF, failure or close), before `done` settles. */
41
+ closedSignal;
42
+ closeController = new AbortController();
43
+ finish;
44
+ closed = false;
45
+ started = false;
46
+ frame = Buffer.allocUnsafe(LIMITS.frameBytes);
47
+ size = 0;
48
+ pending = new Map();
49
+ sdkRequests = new Map();
50
+ nextRequestId = 0;
51
+ writes = new Set();
52
+ outputBytes = 0;
53
+ writer;
54
+ closing;
55
+ constructor(input, output, outputWorkerCommand) {
56
+ this.input = input;
57
+ this.output = output;
58
+ this.outputWorkerCommand = outputWorkerCommand;
59
+ this.closedSignal = this.closeController.signal;
60
+ this.done = new Promise((resolve) => {
61
+ this.finish = resolve;
62
+ });
63
+ }
64
+ async start() {
65
+ if (this.started || this.closed)
66
+ throw new McpFailure("input");
67
+ this.started = true;
68
+ if (this.output === process.stdout) {
69
+ this.writer = new OutputWriter(process.stdout.fd, (code) => this.fail(code), this.outputWorkerCommand);
70
+ await this.writer.start();
71
+ }
72
+ if (this.closed)
73
+ return;
74
+ this.input.on("data", this.onData);
75
+ this.input.on("error", this.onInputError);
76
+ this.input.on("end", this.onEnd);
77
+ this.input.on("close", this.onEnd);
78
+ this.output.on("error", this.onOutputError);
79
+ this.output.on("close", this.onOutputClose);
80
+ if (this.input.readableEnded || this.input.destroyed)
81
+ this.onEnd();
82
+ else if (this.output.destroyed || this.output.writableEnded)
83
+ this.fail("output");
84
+ }
85
+ onData = (data) => {
86
+ const chunk = typeof data === "string" ? Buffer.from(data) : data;
87
+ let start = 0;
88
+ while (!this.closed && start < chunk.length) {
89
+ const newline = chunk.indexOf(10, start);
90
+ const end = newline === -1 ? chunk.length : newline;
91
+ const length = end - start;
92
+ if (this.size + length > LIMITS.frameBytes)
93
+ return this.fail("frame_limit");
94
+ chunk.copy(this.frame, this.size, start, end);
95
+ this.size += length;
96
+ if (newline === -1)
97
+ return;
98
+ try {
99
+ const text = new TextDecoder("utf-8", { fatal: true }).decode(this.frame.subarray(0, this.size));
100
+ const message = deserializeMessage(text);
101
+ this.size = 0;
102
+ // The SDK schema already validates wire IDs, including 0 and the empty string. Keep
103
+ // every valid ID within the frame bound; strings and numbers occupy distinct map keys.
104
+ if ("method" in message && message.method.length > 128)
105
+ return this.fail("frame");
106
+ if (isJSONRPCRequest(message)) {
107
+ if (this.pending.has(message.id))
108
+ return this.fail("frame");
109
+ // SDK 2.4.0 stops checking the revision once a connection is pinned to 2026-07-28
110
+ // (an issue in the MCP SDK). Reject an envelope naming any other revision, on every
111
+ // request, with the answer the SDK gives on the first one.
112
+ const claimed = claimedVersion(message);
113
+ if (claimed !== undefined && !MODERN_VERSIONS.includes(claimed)) {
114
+ void this.writeMessage({
115
+ jsonrpc: "2.0",
116
+ id: message.id,
117
+ error: {
118
+ code: -32022,
119
+ message: "Unsupported protocol version",
120
+ data: { supported: [...MODERN_VERSIONS] },
121
+ },
122
+ }).catch(() => { });
123
+ start = end + 1;
124
+ continue;
125
+ }
126
+ if ([...this.pending.values()].filter((entry) => !entry.responseQueued).length >=
127
+ LIMITS.concurrentCalls) {
128
+ void this.writeMessage({
129
+ jsonrpc: "2.0",
130
+ id: message.id,
131
+ error: { code: -32000, message: "Too many concurrent calls" },
132
+ }).catch(() => { });
133
+ }
134
+ else {
135
+ if (this.nextRequestId === Number.MAX_SAFE_INTEGER)
136
+ return this.fail("input");
137
+ const entry = {
138
+ wireId: message.id,
139
+ sdkId: `ant0/in/${++this.nextRequestId}`,
140
+ responseQueued: false,
141
+ };
142
+ this.pending.set(entry.wireId, entry);
143
+ this.sdkRequests.set(entry.sdkId, entry);
144
+ // Distinct, truthy IDs also avoid SDK 1.30.0's falsy-ID cancellation bug. Generations
145
+ // are never reused, even when the caller immediately reuses a cancelled wire ID.
146
+ this.onmessage?.({ ...message, id: entry.sdkId });
147
+ }
148
+ }
149
+ else if ("method" in message && message.method === "notifications/cancelled") {
150
+ const cancelled = cancelledNotification(message);
151
+ const wireId = cancelled.params.requestId;
152
+ const entry = wireId === undefined ? undefined : this.pending.get(wireId);
153
+ if (entry) {
154
+ // Release at the protocol boundary for ALL methods, including SDK validation and
155
+ // pre-handler cancellation. Late responses/write callbacks only know the old entry.
156
+ this.finishRequest(entry);
157
+ this.onmessage?.({
158
+ jsonrpc: "2.0",
159
+ method: cancelled.method,
160
+ params: { ...cancelled.params, requestId: entry.sdkId },
161
+ });
162
+ }
163
+ }
164
+ else
165
+ this.onmessage?.(message);
166
+ }
167
+ catch {
168
+ return this.fail("frame");
169
+ }
170
+ start = end + 1;
171
+ }
172
+ };
173
+ onEnd = () => {
174
+ if (this.size)
175
+ this.fail("frame");
176
+ else
177
+ void this.close();
178
+ };
179
+ onInputError = () => this.fail("input");
180
+ onOutputError = () => this.fail("output");
181
+ onOutputClose = () => this.fail("output");
182
+ async send(message) {
183
+ if (this.closed)
184
+ throw new McpFailure("output");
185
+ if (!("method" in message) && "id" in message) {
186
+ const entry = typeof message.id === "string" ? this.sdkRequests.get(message.id) : undefined;
187
+ // The SDK can complete an old request after cancellation/reuse. Never deliver that result
188
+ // under a replacement request's wire ID, nor let its callback free the replacement slot.
189
+ if (!entry || entry.responseQueued)
190
+ return;
191
+ await this.writeMessage({ ...message, id: entry.wireId }, entry);
192
+ }
193
+ else {
194
+ // Server-originated pings and their cancellation notifications have an independent ID
195
+ // namespace. Inbound responses likewise go straight to the SDK, not through this map.
196
+ await this.writeMessage(message);
197
+ }
198
+ }
199
+ async writeMessage(message, entry) {
200
+ if (this.closed)
201
+ throw new McpFailure("output");
202
+ // SDK validation errors can contain caller data; neither those messages nor data escape.
203
+ if ("error" in message) {
204
+ const code = [
205
+ -32700, -32600, -32601, -32602, -32603, -32000, -32020, -32021, -32022,
206
+ ].includes(message.error.code)
207
+ ? message.error.code
208
+ : -32603;
209
+ message = {
210
+ jsonrpc: "2.0",
211
+ id: message.id,
212
+ error: {
213
+ code,
214
+ message: code === -32000 ? "Too many concurrent calls" : "MCP request rejected",
215
+ // 2026-07-28 negotiation: a modern client needs the supported list to pick a revision.
216
+ // Only this fixed, non-caller-derived list is ever forwarded.
217
+ ...(code === -32022 ? { data: { supported: [...MODERN_VERSIONS] } } : {}),
218
+ },
219
+ };
220
+ }
221
+ const text = serializeMessage(message);
222
+ const bytes = Buffer.byteLength(text);
223
+ if (
224
+ // Tool results retain their independent 256 KiB limit. The envelope may also echo a
225
+ // caller ID up to the input frame bound; it is never included in a tool result itself.
226
+ bytes > LIMITS.envelopeBytes ||
227
+ this.outputBytes + bytes > LIMITS.outputBytes ||
228
+ this.writes.size >= LIMITS.outputWrites) {
229
+ this.fail("backpressure");
230
+ throw new McpFailure("backpressure");
231
+ }
232
+ this.outputBytes += bytes;
233
+ await new Promise((resolve, reject) => {
234
+ const timer = setTimeout(() => this.fail("backpressure"), LIMITS.outputMs);
235
+ const finish = (error) => {
236
+ if (!this.writes.delete(finish))
237
+ return;
238
+ clearTimeout(timer);
239
+ this.outputBytes -= bytes;
240
+ if (entry)
241
+ this.finishRequest(entry);
242
+ if (error)
243
+ reject(error);
244
+ else
245
+ resolve();
246
+ };
247
+ this.writes.add(finish);
248
+ // The peer can receive this terminal response before the writer's IPC ack reaches us.
249
+ // It no longer occupies admission capacity, but its ID/generation and output budget stay
250
+ // owned until ack/cancellation. Queued records remain bounded by the output queue limits.
251
+ if (entry)
252
+ entry.responseQueued = true;
253
+ try {
254
+ // Callback means the bytes were handed off, unlike write()'s boolean. A stalled pipe is
255
+ // bounded by both aggregate queued bytes and a deadline, including when write() is true.
256
+ const written = (error) => {
257
+ if (error)
258
+ this.fail("output");
259
+ else
260
+ finish();
261
+ };
262
+ if (this.writer)
263
+ this.writer.write(text, written);
264
+ else
265
+ this.output.write(text, written); // Only explicitly injected asynchronous streams.
266
+ }
267
+ catch {
268
+ this.fail("output");
269
+ }
270
+ });
271
+ }
272
+ fail(code) {
273
+ this.shutdown(new McpFailure(code));
274
+ }
275
+ finishRequest(entry) {
276
+ if (this.pending.get(entry.wireId) === entry)
277
+ this.pending.delete(entry.wireId);
278
+ if (this.sdkRequests.get(entry.sdkId) === entry)
279
+ this.sdkRequests.delete(entry.sdkId);
280
+ }
281
+ async close() {
282
+ this.shutdown();
283
+ await this.closing;
284
+ }
285
+ shutdown(failure) {
286
+ if (this.closed)
287
+ return;
288
+ this.closed = true;
289
+ this.closeController.abort();
290
+ this.input.off("data", this.onData);
291
+ this.input.off("end", this.onEnd);
292
+ this.input.off("close", this.onEnd);
293
+ this.input.pause();
294
+ this.input.destroy();
295
+ // Keep the fixed error handlers until stream destruction completes (late EPIPE is possible).
296
+ this.output.off("close", this.onOutputClose);
297
+ this.frame = Buffer.alloc(0);
298
+ this.pending.clear();
299
+ this.sdkRequests.clear();
300
+ for (const finish of this.writes)
301
+ finish(failure ?? new McpFailure("cancelled"));
302
+ this.closing = this.writer?.close() ?? Promise.resolve();
303
+ // Parent stdout has never been written. No Socket _destroy override or blocking flush is
304
+ // needed; only the child's inherited fd performs writes, on both Windows and Linux.
305
+ if (this.output !== process.stdout)
306
+ this.output.destroy();
307
+ else
308
+ this.output.unref?.();
309
+ this.onclose?.();
310
+ void this.closing.then(() => this.finish(failure));
311
+ }
312
+ }
313
+ //# sourceMappingURL=transport.js.map
package/package.json CHANGED
@@ -1,6 +1,68 @@
1
1
  {
2
2
  "name": "@ant0/mcp",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.3.22-beta.2",
4
+ "description": "MCP server for Ant0, a browser for automation and agents. Pre-release.",
5
+ "license": "BSD-3-Clause",
6
+ "type": "module",
7
+ "private": false,
8
+ "homepage": "https://ant0.link",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/Ant0-Browser/ant0-mcp.git"
12
+ },
13
+ "engines": {
14
+ "node": ">=24",
15
+ "pnpm": ">=10"
16
+ },
17
+ "packageManager": "pnpm@11.25.0",
18
+ "bin": {
19
+ "ant0-mcp": "./dist/bin.js"
20
+ },
21
+ "exports": {
22
+ ".": {
23
+ "types": "./dist/index.d.ts",
24
+ "import": "./dist/index.js"
25
+ },
26
+ "./credentials": {
27
+ "types": "./dist/credential-file.d.ts",
28
+ "import": "./dist/credential-file.js"
29
+ }
30
+ },
31
+ "files": [
32
+ "dist",
33
+ "!dist/**/*.map",
34
+ "LICENSE",
35
+ "README.md",
36
+ "THIRD_PARTY_NOTICES"
37
+ ],
38
+ "publishConfig": {
39
+ "access": "public"
40
+ },
41
+ "scripts": {
42
+ "build": "tsc -p tsconfig.json",
43
+ "typecheck": "tsc -p tsconfig.json --noEmit",
44
+ "test": "vitest run",
45
+ "lint": "prettier --check .",
46
+ "format": "prettier --write .",
47
+ "clean": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\"",
48
+ "generate:api": "node scripts/generate-api.mjs",
49
+ "bundle": "node scripts/build-mcpb.mjs",
50
+ "generate:notices": "node scripts/generate-notices.mjs"
51
+ },
52
+ "dependencies": {
53
+ "@modelcontextprotocol/server": "2.4.0",
54
+ "jose": "6.2.15",
55
+ "openapi-fetch": "0.17.0",
56
+ "zod": "4.6.7"
57
+ },
58
+ "devDependencies": {
59
+ "@anthropic-ai/mcpb": "2.1.2",
60
+ "@modelcontextprotocol/client": "2.4.0",
61
+ "@types/node": "^24.13.3",
62
+ "esbuild": "0.28.2",
63
+ "openapi-typescript": "^7.13.0",
64
+ "prettier": "^3.9.6",
65
+ "typescript": "^5.9.3",
66
+ "vitest": "^4.1.12"
67
+ }
68
+ }