@extension-use/mcp 0.0.0-stage → 0.2.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ahmed Gamal and Extension-use contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,19 @@
1
- # Temporary Holding Version
1
+ # @extension-use/mcp
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ MCP server that lets AI agents use your real browser. Tools come from the browser itself, so your extension's own actions show up too, and every call still goes through the extension's permissions, site policy and kill switch.
4
+
5
+ With no relay: click **Connect an agent** in the extension's control panel and paste the instructions into your agent. They boil down to:
6
+
7
+ ```bash
8
+ claude mcp add browser -e EXTENSION_USE_AGENT_KEY=eu_agent_… -- npx -y @extension-use/mcp
9
+ ```
10
+
11
+ Through a relay:
12
+
13
+ ```bash
14
+ claude mcp add extension-use -e EXTENSION_USE_TOKEN=eu_ctl_… -- npx -y @extension-use/mcp --relay http://127.0.0.1:7777
15
+ ```
16
+
17
+ See the agents guide in the Extension-use docs.
18
+
19
+ License: MIT
@@ -0,0 +1,379 @@
1
+ // src/index.ts
2
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
3
+ import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
4
+ import { ExtensionUseError as ExtensionUseError2 } from "@extension-use/protocol";
5
+
6
+ // src/local.ts
7
+ import { createServer } from "http";
8
+ import { WebSocketServer, WebSocket } from "ws";
9
+ import { ExtensionUseError, isEnvelope, randomId } from "@extension-use/protocol";
10
+ import { AGENT_PATH, AGENT_PORTS, agentKeyId, agentNonce, agentProof, isDeviceFrame, sameProof } from "@extension-use/protocol/remote";
11
+ function allowedOrigin(req) {
12
+ const origin = req.headers.origin;
13
+ return !origin || /^(chrome-extension|moz-extension|safari-web-extension):\/\//.test(origin);
14
+ }
15
+ async function listenForBrowser(options) {
16
+ const keyId = await agentKeyId(options.key);
17
+ const log = options.log ?? (() => {
18
+ });
19
+ const handshakeTimeout = options.handshakeTimeoutMs ?? 5e3;
20
+ const sessions = /* @__PURE__ */ new Map();
21
+ let device;
22
+ let waiters = [];
23
+ const send = (ws, frame) => {
24
+ if (ws?.readyState === WebSocket.OPEN) ws.send(JSON.stringify(frame));
25
+ };
26
+ function endSessions(reason) {
27
+ for (const sink of sessions.values()) sink.ended(reason);
28
+ sessions.clear();
29
+ }
30
+ function accept(ws) {
31
+ let nonce;
32
+ let theirs;
33
+ let authed = false;
34
+ const timer = setTimeout(() => ws.close(4401, "handshake timeout"), handshakeTimeout);
35
+ ws.on("message", (data) => {
36
+ let frame;
37
+ try {
38
+ frame = JSON.parse(data.toString());
39
+ } catch {
40
+ return;
41
+ }
42
+ if (!isDeviceFrame(frame)) return;
43
+ if (!authed) return void handshake(frame);
44
+ if (frame.t === "ping") send(ws, { t: "pong" });
45
+ else if (frame.t === "msg" && isEnvelope(frame.env)) sessions.get(frame.s)?.deliver(frame.env);
46
+ else if (frame.t === "closed") {
47
+ const sink = sessions.get(frame.s);
48
+ sessions.delete(frame.s);
49
+ sink?.ended(frame.reason ?? "closed by the extension");
50
+ }
51
+ });
52
+ async function handshake(frame) {
53
+ if (frame.t === "agent-hello" && !nonce && typeof frame.nonce === "string" && frame.nonce.length >= 16) {
54
+ theirs = frame.nonce;
55
+ nonce = agentNonce();
56
+ send(ws, { t: "agent-challenge", keyId, nonce, proof: await agentProof(options.key, "mcp", theirs, nonce) });
57
+ } else if (frame.t === "agent-proof" && nonce && theirs) {
58
+ const expected = await agentProof(options.key, "extension", nonce, theirs);
59
+ if (!sameProof(frame.proof, expected)) {
60
+ send(ws, { t: "error", code: "UNAUTHORIZED", message: "Wrong agent key" });
61
+ ws.close(4401, "wrong key");
62
+ return;
63
+ }
64
+ authed = true;
65
+ clearTimeout(timer);
66
+ if (device && device !== ws) {
67
+ endSessions("replaced by a new browser connection");
68
+ device.close(4e3, "replaced");
69
+ }
70
+ device = ws;
71
+ send(ws, { t: "ready", deviceId: `agent-${keyId}`, name: "local agent link" });
72
+ log("browser connected");
73
+ for (const w of waiters.splice(0)) w();
74
+ options.onBrowser?.(true);
75
+ } else {
76
+ ws.close(4400, "unexpected frame");
77
+ }
78
+ }
79
+ ws.on("close", () => {
80
+ clearTimeout(timer);
81
+ if (device !== ws) return;
82
+ device = void 0;
83
+ endSessions("The browser disconnected");
84
+ log("browser disconnected");
85
+ options.onBrowser?.(false);
86
+ });
87
+ ws.on("error", () => {
88
+ });
89
+ }
90
+ const wss = new WebSocketServer({ noServer: true, maxPayload: 32 * 1024 * 1024 });
91
+ const server = createServer((_req, res) => res.writeHead(404).end());
92
+ server.on("upgrade", (req, socket, head) => {
93
+ const path = new URL(req.url ?? "/", "http://local").pathname;
94
+ if (path !== AGENT_PATH || !allowedOrigin(req)) {
95
+ socket.destroy();
96
+ return;
97
+ }
98
+ wss.handleUpgrade(req, socket, head, accept);
99
+ });
100
+ const host = options.host ?? "127.0.0.1";
101
+ const port = await bindFirstFree(server, options.ports ?? AGENT_PORTS, host);
102
+ log(`waiting for the browser on ${host}:${port}`);
103
+ function waitForBrowser(ms) {
104
+ if (device) return Promise.resolve();
105
+ return new Promise((resolve, reject) => {
106
+ const done = () => {
107
+ clearTimeout(timer);
108
+ resolve();
109
+ };
110
+ const timer = setTimeout(() => {
111
+ waiters = waiters.filter((w) => w !== done);
112
+ reject(
113
+ new ExtensionUseError(
114
+ "NOT_CONNECTED",
115
+ `The browser hasn't connected yet. In the extension's control panel, check that "Connect an agent" is on and uses the same key as this server; the browser checks for agents every 30 seconds or so.`
116
+ )
117
+ );
118
+ }, ms);
119
+ waiters.push(done);
120
+ });
121
+ }
122
+ return {
123
+ port,
124
+ url: `ws://${host}:${port}${AGENT_PATH}`,
125
+ get connected() {
126
+ return Boolean(device);
127
+ },
128
+ waitForBrowser,
129
+ /**
130
+ * A client transport for one controller session. `label` is how the
131
+ * extension lists it ("agent:<label>"), `waitMs` how long to wait for a
132
+ * browser that hasn't connected yet.
133
+ */
134
+ transport(opts = {}) {
135
+ let s;
136
+ let ws;
137
+ return {
138
+ kind: "agent",
139
+ async open(onMessage, onClose) {
140
+ await waitForBrowser(opts.waitMs ?? 0);
141
+ ws = device;
142
+ s = randomId();
143
+ sessions.set(s, { deliver: onMessage, ended: (reason) => onClose(`DEVICE_OFFLINE: ${reason}`) });
144
+ send(ws, { t: "open", s, origin: `agent:${(opts.label ?? "agent").slice(0, 60)}`, label: "mcp" });
145
+ },
146
+ send(env) {
147
+ if (s) send(ws, { t: "msg", s, env });
148
+ },
149
+ close() {
150
+ if (s && sessions.delete(s)) send(ws, { t: "close", s });
151
+ s = void 0;
152
+ }
153
+ };
154
+ },
155
+ async close() {
156
+ endSessions("The agent's MCP server stopped");
157
+ for (const ws of wss.clients) ws.terminate();
158
+ await new Promise((r) => server.close(() => r()));
159
+ }
160
+ };
161
+ }
162
+ async function bindFirstFree(server, ports, host) {
163
+ for (const port of ports) {
164
+ const bound = await new Promise((resolve, reject) => {
165
+ const onError = (err) => {
166
+ server.off("listening", onListening);
167
+ if (err.code === "EADDRINUSE" || err.code === "EACCES") resolve(void 0);
168
+ else reject(err);
169
+ };
170
+ const onListening = () => {
171
+ server.off("error", onError);
172
+ const addr = server.address();
173
+ resolve(typeof addr === "object" && addr ? addr.port : port);
174
+ };
175
+ server.once("error", onError);
176
+ server.once("listening", onListening);
177
+ server.listen(port, host);
178
+ });
179
+ if (bound !== void 0) return bound;
180
+ }
181
+ throw new Error(`Ports ${ports.join(", ")} are all in use. Close another agent's extension-use MCP server and try again.`);
182
+ }
183
+
184
+ // src/index.ts
185
+ var MCP_VERSION = "0.1.0";
186
+ var INSTRUCTIONS = `These tools act in the user's real browser, signed in as them. Work like this:
187
+ 1. Call dom_snapshot (it defaults to the visible part of the page) to see the page as an accessibility tree. Interactive elements have refs like [ref=e12].
188
+ 2. Act with a locator that uses a ref, e.g. dom_click { "locator": { "ref": "e12" } }. Refs stay valid until the page reloads.
189
+ 3. Take a new snapshot after actions that change the page.
190
+ Use tabs_list / tabs_open / tabs_activate to pick a tab; most tools also take an optional "target" ({ "tab": <id> } or { "tab": { "urlMatch": "https://example.com/*" } }).
191
+ Typing into password and payment fields is refused. If a tool returns BLOCKED_BY_POLICY with "paused", the user pressed the kill switch: stop and ask them.
192
+ Use run_sequence to batch several known steps in one call.`;
193
+ var TARGET_SCHEMA = {
194
+ type: "object",
195
+ description: 'Which tab to act on. Default: the active tab. { "tab": <tabId> } or { "tab": { "urlMatch": "https://example.com/*" } }.',
196
+ properties: {
197
+ tab: {
198
+ anyOf: [{ type: "number" }, { type: "string", enum: ["active"] }, { type: "object", properties: { urlMatch: { type: "string" } }, required: ["urlMatch"] }]
199
+ },
200
+ frame: { anyOf: [{ type: "number" }, { type: "string", enum: ["top"] }] }
201
+ }
202
+ };
203
+ var toolName = (action) => action.replace(/\./g, "_");
204
+ function matches(patterns, name) {
205
+ return patterns?.some((p) => new RegExp(`^${p.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*")}$`).test(name));
206
+ }
207
+ function createExtensionUseMcpServer(options) {
208
+ let client;
209
+ let connecting;
210
+ let described;
211
+ async function ext(purpose) {
212
+ if (client?.connected) return client;
213
+ connecting ??= options.connect({ purpose }).then((c) => {
214
+ client = c;
215
+ described = void 0;
216
+ c.onDisconnect(() => {
217
+ if (client === c) client = void 0;
218
+ });
219
+ return c;
220
+ }).finally(() => connecting = void 0);
221
+ return connecting;
222
+ }
223
+ async function describe(purpose) {
224
+ if (described && Date.now() - described.at < 6e4) return described.actions;
225
+ const c = await ext(purpose);
226
+ const out = await c.callRaw("runtime.describe", {}, { timeoutMs: 1e4 });
227
+ const actions = out.actions.filter(
228
+ (a) => a.name !== "runtime.describe" && c.has(a.name) && (!options.include || matches(options.include, a.name)) && !matches(options.exclude, a.name)
229
+ );
230
+ described = { at: Date.now(), actions };
231
+ return actions;
232
+ }
233
+ const server = new Server({ name: options.name ?? "extension-use", version: MCP_VERSION }, { capabilities: { tools: { listChanged: true } }, instructions: INSTRUCTIONS });
234
+ server.setRequestHandler(ListToolsRequestSchema, async () => {
235
+ let actions;
236
+ try {
237
+ actions = await describe("list");
238
+ } catch (err) {
239
+ const e = ExtensionUseError2.from(err);
240
+ return {
241
+ tools: [
242
+ {
243
+ name: "browser_status",
244
+ description: `The browser is not connected (${e.code}: ${e.message}). Call this tool to check again once the user has connected the browser.`,
245
+ inputSchema: { type: "object", properties: {} }
246
+ }
247
+ ]
248
+ };
249
+ }
250
+ const tools = actions.map((a) => {
251
+ const input = { ...a.input };
252
+ const properties = { ...input.properties ?? {} };
253
+ if (a.where !== "bridge" && !a.name.startsWith("runtime.") && a.name !== "run.sequence") {
254
+ properties.target = TARGET_SCHEMA;
255
+ }
256
+ properties.timeoutMs = { type: "number", description: "Optional timeout for this call, in milliseconds." };
257
+ return {
258
+ name: toolName(a.name),
259
+ description: describeTool(a),
260
+ inputSchema: { type: "object", properties, ...input.required?.length ? { required: input.required } : {} },
261
+ annotations: { readOnlyHint: READ_ONLY.has(a.name), destructiveHint: DESTRUCTIVE.has(a.name), openWorldHint: true }
262
+ };
263
+ });
264
+ return { tools };
265
+ });
266
+ server.setRequestHandler(CallToolRequestSchema, async (req) => {
267
+ const name = req.params.name;
268
+ const args = { ...req.params.arguments ?? {} };
269
+ try {
270
+ if (name === "browser_status") {
271
+ const c2 = await ext("call");
272
+ return text(`Connected to "${c2.host.name ?? c2.host.id}" with ${c2.capabilities.length} actions. List the tools again to see them.`);
273
+ }
274
+ const actions = await describe("call");
275
+ const action = actions.find((a) => toolName(a.name) === name)?.name;
276
+ if (!action) return error("UNKNOWN_ACTION", `No tool "${name}". List the tools again; the browser's actions may have changed.`);
277
+ const { target, timeoutMs, ...input } = args;
278
+ if (action === "dom.snapshot") {
279
+ input.format ??= "text";
280
+ input.viewportOnly ??= true;
281
+ }
282
+ if (action === "dom.html") input.maxLength ??= 5e4;
283
+ const c = await ext("call");
284
+ const output = await c.callRaw(action, input, {
285
+ ...target ? { target } : {},
286
+ ...typeof timeoutMs === "number" ? { timeoutMs } : {}
287
+ });
288
+ return format(action, output);
289
+ } catch (err) {
290
+ const e = ExtensionUseError2.from(err);
291
+ return error(e.code, e.message);
292
+ }
293
+ });
294
+ return {
295
+ server,
296
+ /** Tell the MCP client to list the tools again, e.g. after a browser connects. */
297
+ notifyToolsChanged() {
298
+ described = void 0;
299
+ server.sendToolListChanged().catch(() => {
300
+ });
301
+ },
302
+ async close() {
303
+ client?.close();
304
+ await server.close();
305
+ }
306
+ };
307
+ }
308
+ var READ_ONLY = /* @__PURE__ */ new Set([
309
+ "runtime.ping",
310
+ "tabs.list",
311
+ "windows.list",
312
+ "frames.list",
313
+ "page.info",
314
+ "dom.query",
315
+ "dom.text",
316
+ "dom.snapshot",
317
+ "dom.html",
318
+ "wait.for",
319
+ "capture.screenshot",
320
+ "capture.fullPage",
321
+ "permissions.contains",
322
+ "permissions.getAll",
323
+ "downloads.list",
324
+ "bookmarks.search",
325
+ "bookmarks.list",
326
+ "history.search",
327
+ "cookies.list"
328
+ ]);
329
+ var DESTRUCTIVE = /* @__PURE__ */ new Set([
330
+ "tabs.close",
331
+ "windows.close",
332
+ "edit.setHtml",
333
+ "edit.setText",
334
+ "edit.remove",
335
+ "downloads.cancel",
336
+ "bookmarks.remove",
337
+ "history.delete",
338
+ "cookies.set",
339
+ "cookies.remove"
340
+ ]);
341
+ var IMAGE_ACTIONS = /* @__PURE__ */ new Set(["capture.screenshot", "capture.fullPage"]);
342
+ function describeTool(a) {
343
+ const extra = a.name === "dom.snapshot" ? " Returns a text tree; interactive elements carry [ref=\u2026] for use in locators. Defaults: format text, viewportOnly true (set false for the whole page)." : IMAGE_ACTIONS.has(a.name) ? " Returns an image. The tab must be the visible one in its window (tabs_activate first)." : a.name === "dom.html" ? " Prefer dom_snapshot or dom_text for reading; use this when you need the markup. Default maxLength here is 50000; pass a locator to get one part." : a.where === "content" ? " Locators: { ref } from dom_snapshot is most reliable; also { role, name }, { text }, { testId }, { css }." : "";
344
+ return `${a.description}${extra}`;
345
+ }
346
+ function text(t) {
347
+ return { content: [{ type: "text", text: t }] };
348
+ }
349
+ function error(code, message) {
350
+ return { isError: true, content: [{ type: "text", text: `${code}: ${message}` }] };
351
+ }
352
+ function format(action, output) {
353
+ if (action === "dom.snapshot") {
354
+ const o = output;
355
+ if (o.text !== void 0) return text(`${o.text}${o.truncated ? "\n(truncated: pass maxNodes or viewportOnly to see other parts)" : ""}`);
356
+ }
357
+ if (IMAGE_ACTIONS.has(action)) {
358
+ const o = output;
359
+ const m = /^data:([^;]+);base64,(.*)$/.exec(o.dataUrl);
360
+ const size = `${o.width}\xD7${o.height}${o.truncated ? " (truncated: the page is taller; pass maxHeight)" : ""}`;
361
+ if (m) return { content: [{ type: "image", mimeType: m[1], data: m[2] }, { type: "text", text: size }] };
362
+ }
363
+ if (action === "dom.html") {
364
+ const o = output;
365
+ return text(`${o.html}${o.truncated ? `
366
+ (truncated at ${o.html.length} of ${o.length} characters: pass a locator or a larger maxLength)` : ""}`);
367
+ }
368
+ if (action === "dom.text") {
369
+ const o = output;
370
+ return text(`${o.text}${o.truncated ? "\n(truncated)" : ""}`);
371
+ }
372
+ return text(JSON.stringify(output, null, 2));
373
+ }
374
+
375
+ export {
376
+ listenForBrowser,
377
+ MCP_VERSION,
378
+ createExtensionUseMcpServer
379
+ };
package/dist/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
package/dist/cli.js ADDED
@@ -0,0 +1,69 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ createExtensionUseMcpServer,
4
+ listenForBrowser
5
+ } from "./chunk-OS4ME7CC.js";
6
+
7
+ // src/cli.ts
8
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
9
+ import { connect } from "@extension-use/client";
10
+ import { remote } from "@extension-use/client/remote";
11
+ import { isAgentKey } from "@extension-use/protocol/remote";
12
+ var argv = process.argv.slice(2);
13
+ var flag = (name) => {
14
+ const i = argv.indexOf(`--${name}`);
15
+ return i >= 0 ? argv[i + 1] : void 0;
16
+ };
17
+ var list = (v) => v?.split(",").map((s) => s.trim()).filter(Boolean);
18
+ var say = (line) => console.error(`extension-use-mcp: ${line}`);
19
+ var agentKey = process.env.EXTENSION_USE_AGENT_KEY ?? flag("agent-key");
20
+ var relayFlag = flag("relay") ?? process.env.EXTENSION_USE_RELAY;
21
+ var token = process.env.EXTENSION_USE_TOKEN ?? flag("token");
22
+ var device = flag("device") ?? process.env.EXTENSION_USE_DEVICE ?? "default";
23
+ var include = list(flag("include"));
24
+ var exclude = list(flag("exclude"));
25
+ if (agentKey && !isAgentKey(agentKey)) {
26
+ say("EXTENSION_USE_AGENT_KEY doesn't look like an agent key (eu_agent_\u2026). Copy the instructions from the extension's control panel again.");
27
+ process.exit(1);
28
+ }
29
+ if (!agentKey && !token) {
30
+ say(`set EXTENSION_USE_AGENT_KEY (from "Connect an agent" in the extension's control panel), or EXTENSION_USE_TOKEN for a relay (create one with: npx @extension-use/relay token create agent)`);
31
+ process.exit(1);
32
+ }
33
+ var LIST_WAIT_MS = 3e3;
34
+ var CALL_WAIT_MS = 4e4;
35
+ var local;
36
+ var mcp = createExtensionUseMcpServer({
37
+ connect: (ctx) => {
38
+ if (!local) {
39
+ const relay = relayFlag ?? "http://127.0.0.1:7777";
40
+ return connect(remote({ relay, token, device }), { name: "extension-use-mcp" });
41
+ }
42
+ const label = mcp.server.getClientVersion()?.name ?? "agent";
43
+ return connect(local.transport({ label, waitMs: ctx?.purpose === "list" ? LIST_WAIT_MS : CALL_WAIT_MS }), { name: "extension-use-mcp", handshakeTimeoutMs: 1e4 });
44
+ },
45
+ ...include ? { include } : {},
46
+ ...exclude ? { exclude } : {}
47
+ });
48
+ if (agentKey) {
49
+ try {
50
+ local = await listenForBrowser({
51
+ key: agentKey,
52
+ log: say,
53
+ onBrowser: () => mcp.notifyToolsChanged()
54
+ });
55
+ } catch (e) {
56
+ say(e.message);
57
+ process.exit(1);
58
+ }
59
+ }
60
+ await mcp.server.connect(new StdioServerTransport());
61
+ if (!local) say(`serving tools for ${device} via ${relayFlag ?? "http://127.0.0.1:7777"}`);
62
+ var stop = async () => {
63
+ await mcp.close();
64
+ await local?.close();
65
+ process.exit(0);
66
+ };
67
+ process.on("SIGINT", stop);
68
+ process.on("SIGTERM", stop);
69
+ process.stdin.on("end", stop);
@@ -0,0 +1,100 @@
1
+ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
2
+ import { Transport, Client } from '@extension-use/client';
3
+
4
+ interface LocalAgentOptions {
5
+ /** The agent key from the extension's control panel (eu_agent_…). */
6
+ key: string;
7
+ /** Ports to try, in order. Default: AGENT_PORTS. Pass [0] for a random port (tests). */
8
+ ports?: readonly number[];
9
+ /** Default 127.0.0.1. */
10
+ host?: string;
11
+ /** How long an unauthenticated socket may take to finish the handshake. Default 5 s. */
12
+ handshakeTimeoutMs?: number;
13
+ /** Called when a browser connects (after the proof checks out) or disconnects. */
14
+ onBrowser?(connected: boolean): void;
15
+ log?(line: string): void;
16
+ }
17
+ declare function listenForBrowser(options: LocalAgentOptions): Promise<{
18
+ port: number;
19
+ url: string;
20
+ readonly connected: boolean;
21
+ waitForBrowser: (ms: number) => Promise<void>;
22
+ /**
23
+ * A client transport for one controller session. `label` is how the
24
+ * extension lists it ("agent:<label>"), `waitMs` how long to wait for a
25
+ * browser that hasn't connected yet.
26
+ */
27
+ transport(opts?: {
28
+ label?: string;
29
+ waitMs?: number;
30
+ }): Transport;
31
+ close(): Promise<void>;
32
+ }>;
33
+ type LocalAgentLink = Awaited<ReturnType<typeof listenForBrowser>>;
34
+
35
+ /**
36
+ * @extension-use/mcp
37
+ *
38
+ * An MCP server whose tools are the actions of a paired browser. Tool lists
39
+ * come from the extension itself (runtime.describe), so host-defined actions
40
+ * show up too, and every call goes through the extension's grants, site
41
+ * policy, kill switch and visible-control indicators.
42
+ */
43
+
44
+ declare const MCP_VERSION = "0.1.0";
45
+
46
+ interface ExtensionUseMcpOptions {
47
+ /**
48
+ * Returns a connected client (for example `connect(remote({ relay, token }))`). Called again after a disconnect.
49
+ * `purpose` says why: "list" (listing tools, so don't wait long for a browser) or "call" (a tool call).
50
+ */
51
+ connect(context?: {
52
+ purpose: "list" | "call";
53
+ }): Promise<Client>;
54
+ /** Only expose these actions (patterns like "dom.*"). Default: everything the token allows. */
55
+ include?: string[];
56
+ /** Hide these actions. Default: none. */
57
+ exclude?: string[];
58
+ name?: string;
59
+ }
60
+ declare function createExtensionUseMcpServer(options: ExtensionUseMcpOptions): {
61
+ server: Server<{
62
+ method: string;
63
+ params?: {
64
+ [x: string]: unknown;
65
+ _meta?: {
66
+ [x: string]: unknown;
67
+ progressToken?: string | number | undefined;
68
+ "io.modelcontextprotocol/related-task"?: {
69
+ taskId: string;
70
+ } | undefined;
71
+ } | undefined;
72
+ } | undefined;
73
+ }, {
74
+ method: string;
75
+ params?: {
76
+ [x: string]: unknown;
77
+ _meta?: {
78
+ [x: string]: unknown;
79
+ progressToken?: string | number | undefined;
80
+ "io.modelcontextprotocol/related-task"?: {
81
+ taskId: string;
82
+ } | undefined;
83
+ } | undefined;
84
+ } | undefined;
85
+ }, {
86
+ [x: string]: unknown;
87
+ _meta?: {
88
+ [x: string]: unknown;
89
+ progressToken?: string | number | undefined;
90
+ "io.modelcontextprotocol/related-task"?: {
91
+ taskId: string;
92
+ } | undefined;
93
+ } | undefined;
94
+ }>;
95
+ /** Tell the MCP client to list the tools again, e.g. after a browser connects. */
96
+ notifyToolsChanged(): void;
97
+ close(): Promise<void>;
98
+ };
99
+
100
+ export { type ExtensionUseMcpOptions, type LocalAgentLink, type LocalAgentOptions, MCP_VERSION, createExtensionUseMcpServer, listenForBrowser };
package/dist/index.js ADDED
@@ -0,0 +1,10 @@
1
+ import {
2
+ MCP_VERSION,
3
+ createExtensionUseMcpServer,
4
+ listenForBrowser
5
+ } from "./chunk-OS4ME7CC.js";
6
+ export {
7
+ MCP_VERSION,
8
+ createExtensionUseMcpServer,
9
+ listenForBrowser
10
+ };
package/package.json CHANGED
@@ -1,6 +1,56 @@
1
1
  {
2
2
  "name": "@extension-use/mcp",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.2.0",
4
+ "description": "MCP server that lets AI agents use your real browser, locally or through an Extension-use relay",
5
+ "license": "MIT",
6
+ "author": "Ahmed Gamal",
7
+ "homepage": "https://extension-use.appzlr.com",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/ahmedGamalhamed/extension-use.git",
11
+ "directory": "packages/mcp"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/ahmedGamalhamed/extension-use/issues"
15
+ },
16
+ "type": "module",
17
+ "bin": {
18
+ "extension-use-mcp": "./dist/cli.js"
19
+ },
20
+ "exports": {
21
+ ".": {
22
+ "source": "./src/index.ts",
23
+ "types": "./dist/index.d.ts",
24
+ "default": "./dist/index.js"
25
+ },
26
+ "./package.json": "./package.json"
27
+ },
28
+ "files": [
29
+ "dist"
30
+ ],
31
+ "engines": {
32
+ "node": ">=22"
33
+ },
34
+ "dependencies": {
35
+ "@modelcontextprotocol/sdk": "^1.32.2",
36
+ "ws": "^8.18.3",
37
+ "@extension-use/client": "0.2.0",
38
+ "@extension-use/protocol": "0.2.0"
39
+ },
40
+ "devDependencies": {
41
+ "@types/ws": "^8.18.1",
42
+ "@extension-use/host": "0.2.0",
43
+ "@extension-use/relay": "0.2.0"
44
+ },
45
+ "keywords": [
46
+ "mcp",
47
+ "model-context-protocol",
48
+ "ai-agent",
49
+ "browser-automation",
50
+ "browser-extension",
51
+ "extension-use"
52
+ ],
53
+ "scripts": {
54
+ "build": "tsup src/index.ts src/cli.ts --format esm --dts --clean"
55
+ }
6
56
  }