@cotestdev/mcp_playwright 0.0.35 → 0.0.37
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/lib/mcp/browser/browserContextFactory.js +12 -12
- package/lib/mcp/browser/browserServerBackend.js +24 -12
- package/lib/mcp/browser/config.js +37 -7
- package/lib/mcp/browser/context.js +13 -61
- package/lib/mcp/browser/response.js +183 -251
- package/lib/mcp/browser/sessionLog.js +19 -104
- package/lib/mcp/browser/tab.js +49 -28
- package/lib/mcp/browser/tools/common.js +8 -9
- package/lib/mcp/browser/tools/console.js +20 -3
- package/lib/mcp/browser/tools/dialogs.js +2 -3
- package/lib/mcp/browser/tools/evaluate.js +8 -6
- package/lib/mcp/browser/tools/files.js +2 -2
- package/lib/mcp/browser/tools/form.js +2 -2
- package/lib/mcp/browser/tools/install.js +4 -1
- package/lib/mcp/browser/tools/keyboard.js +77 -10
- package/lib/mcp/browser/tools/mouse.js +59 -7
- package/lib/mcp/browser/tools/navigate.js +51 -8
- package/lib/mcp/browser/tools/network.js +21 -3
- package/lib/mcp/browser/tools/pdf.js +4 -3
- package/lib/mcp/browser/tools/runCode.js +8 -12
- package/lib/mcp/browser/tools/schema.js +31 -0
- package/lib/mcp/browser/tools/screenshot.js +10 -28
- package/lib/mcp/browser/tools/snapshot.js +40 -24
- package/lib/mcp/browser/tools/tabs.js +10 -10
- package/lib/mcp/browser/tools/tool.js +3 -6
- package/lib/mcp/browser/tools/tracing.js +3 -3
- package/lib/mcp/browser/tools/utils.js +2 -2
- package/lib/mcp/browser/tools/verify.js +9 -9
- package/lib/mcp/browser/tools/wait.js +3 -3
- package/lib/mcp/browser/tools.js +2 -2
- package/lib/mcp/extension/extensionContextFactory.js +2 -2
- package/lib/mcp/program.js +3 -2
- package/lib/mcp/terminal/cli.js +4 -216
- package/lib/mcp/terminal/command.js +56 -0
- package/lib/mcp/terminal/commands.js +528 -0
- package/lib/mcp/terminal/daemon.js +42 -25
- package/lib/mcp/terminal/helpGenerator.js +152 -0
- package/lib/mcp/terminal/program.js +434 -0
- package/lib/mcp/terminal/socketConnection.js +2 -4
- package/lib/mcpBundleImpl/index.js +44 -44
- package/lib/util.js +3 -6
- package/package.json +1 -1
|
@@ -23,14 +23,14 @@ __export(wait_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(wait_exports);
|
|
24
24
|
var import_mcpBundle = require("../../../mcpBundle");
|
|
25
25
|
var import_tool = require("./tool");
|
|
26
|
-
var
|
|
26
|
+
var import_schema = require("./schema");
|
|
27
27
|
const wait = (0, import_tool.defineTool)({
|
|
28
28
|
capability: "core",
|
|
29
29
|
schema: {
|
|
30
30
|
name: "browser_wait_for",
|
|
31
31
|
title: "Wait for",
|
|
32
32
|
description: "Wait for text to appear or disappear or a specified time to pass",
|
|
33
|
-
inputSchema:
|
|
33
|
+
inputSchema: import_schema.baseSchema.extend({
|
|
34
34
|
time: import_mcpBundle.z.number().optional().describe("The time to wait in seconds"),
|
|
35
35
|
text: import_mcpBundle.z.string().optional().describe("The text to wait for"),
|
|
36
36
|
textGone: import_mcpBundle.z.string().optional().describe("The text to wait for to disappear")
|
|
@@ -55,7 +55,7 @@ const wait = (0, import_tool.defineTool)({
|
|
|
55
55
|
response.addCode(`await page.getByText(${JSON.stringify(params.text)}).first().waitFor({ state: 'visible' });`);
|
|
56
56
|
await locator.waitFor({ state: "visible" });
|
|
57
57
|
}
|
|
58
|
-
response.
|
|
58
|
+
response.addTextResult(`Waited for ${params.text || params.textGone || params.time}`);
|
|
59
59
|
response.setIncludeSnapshot();
|
|
60
60
|
}
|
|
61
61
|
});
|
package/lib/mcp/browser/tools.js
CHANGED
|
@@ -60,9 +60,9 @@ const browserTools = [
|
|
|
60
60
|
...import_form.default,
|
|
61
61
|
...import_install.default,
|
|
62
62
|
...import_keyboard.default,
|
|
63
|
+
...import_mouse.default,
|
|
63
64
|
...import_navigate.default,
|
|
64
65
|
...import_network.default,
|
|
65
|
-
...import_mouse.default,
|
|
66
66
|
...import_pdf.default,
|
|
67
67
|
...import_runCode.default,
|
|
68
68
|
...import_screenshot.default,
|
|
@@ -73,7 +73,7 @@ const browserTools = [
|
|
|
73
73
|
...import_verify.default
|
|
74
74
|
];
|
|
75
75
|
function filteredTools(config) {
|
|
76
|
-
return browserTools.filter((tool) => tool.capability.startsWith("core") || config.capabilities?.includes(tool.capability));
|
|
76
|
+
return browserTools.filter((tool) => tool.capability.startsWith("core") || config.capabilities?.includes(tool.capability)).filter((tool) => !tool.skillOnly);
|
|
77
77
|
}
|
|
78
78
|
// Annotate the CommonJS export names for ESM import in node:
|
|
79
79
|
0 && (module.exports = {
|
|
@@ -42,8 +42,8 @@ class ExtensionContextFactory {
|
|
|
42
42
|
this._userDataDir = userDataDir;
|
|
43
43
|
this._executablePath = executablePath;
|
|
44
44
|
}
|
|
45
|
-
async createContext(clientInfo, abortSignal,
|
|
46
|
-
const browser = await this._obtainBrowser(clientInfo, abortSignal, toolName);
|
|
45
|
+
async createContext(clientInfo, abortSignal, options) {
|
|
46
|
+
const browser = await this._obtainBrowser(clientInfo, abortSignal, options?.toolName);
|
|
47
47
|
return {
|
|
48
48
|
browserContext: browser.contexts()[0],
|
|
49
49
|
close: async () => {
|
package/lib/mcp/program.js
CHANGED
|
@@ -42,7 +42,8 @@ var import_browserContextFactory = require("./browser/browserContextFactory");
|
|
|
42
42
|
var import_browserServerBackend = require("./browser/browserServerBackend");
|
|
43
43
|
var import_extensionContextFactory = require("./extension/extensionContextFactory");
|
|
44
44
|
function decorateCommand(command, version) {
|
|
45
|
-
command.option("--allowed-hosts <hosts...>", "comma-separated list of hosts this server is allowed to serve from. Defaults to the host the server is bound to. Pass '*' to disable the host check.", import_config.commaSeparatedList).option("--allowed-origins <origins>", "semicolon-separated list of TRUSTED origins to allow the browser to request. Default is to allow all.\nImportant: *does not* serve as a security boundary and *does not* affect redirects. ", import_config.semicolonSeparatedList).option("--allow-unrestricted-file-access", "allow access to files outside of the workspace roots. Also allows unrestricted access to file:// URLs. By default access to file system is restricted to workspace root directories (or cwd if no roots are configured) only, and navigation to file:// URLs is blocked.").option("--blocked-origins <origins>", "semicolon-separated list of origins to block the browser from requesting. Blocklist is evaluated before allowlist. If used without the allowlist, requests not matching the blocklist are still allowed.\nImportant: *does not* serve as a security boundary and *does not* affect redirects.", import_config.semicolonSeparatedList).option("--block-service-workers", "block service workers").option("--browser <browser>", "browser or chrome channel to use, possible values: chrome, firefox, webkit, msedge.").option("--caps <caps>", "comma-separated list of additional capabilities to enable, possible values: vision, pdf.", import_config.commaSeparatedList).option("--cdp-endpoint <endpoint>", "CDP endpoint to connect to.").option("--cdp-header <headers...>", "CDP headers to send with the connect request, multiple can be specified.", import_config.headerParser).option("--config <path>", "path to the configuration file.").option("--console-level <level>", 'level of console messages to return: "error", "warning", "info", "debug". Each level includes the messages of more severe levels.', import_config.enumParser.bind(null, "--console-level", ["error", "warning", "info", "debug"])).option("--device <device>", 'device to emulate, for example: "iPhone 15"').option("--executable-path <path>", "path to the browser executable.").option("--extension", 'Connect to a running browser instance (Edge/Chrome only). Requires the "Playwright MCP Bridge" browser extension to be installed.').option("--grant-permissions <permissions...>", 'List of permissions to grant to the browser context, for example "geolocation", "clipboard-read", "clipboard-write".', import_config.commaSeparatedList).option("--headless", "run browser in headless mode, headed by default").option("--host <host>", "host to bind server to. Default is localhost. Use 0.0.0.0 to bind to all interfaces.").option("--ignore-https-errors", "ignore https errors").option("--init-page <path...>", "path to TypeScript file to evaluate on Playwright page object").option("--init-script <path...>", "path to JavaScript file to add as an initialization script. The script will be evaluated in every page before any of the page's scripts. Can be specified multiple times.").option("--isolated", "keep the browser profile in memory, do not save it to disk.").option("--image-responses <mode>", 'whether to send image responses to the client. Can be "allow" or "omit", Defaults to "allow".', import_config.enumParser.bind(null, "--image-responses", ["allow", "omit"])).option("--no-sandbox", "disable the sandbox for all process types that are normally sandboxed.").option("--output-dir <path>", "path to the directory for output files.").option("--port <port>", "port to listen on for SSE transport.").option("--proxy-bypass <bypass>", 'comma-separated domains to bypass proxy, for example ".com,chromium.org,.domain.com"').option("--proxy-server <proxy>", 'specify proxy server, for example "http://myproxy:3128" or "socks5://myproxy:8080"').option("--save-session", "Whether to save the Playwright MCP session into the output directory.").option("--save-trace", "Whether to save the Playwright Trace of the session into the output directory.").option("--save-video <size>", 'Whether to save the video of the session into the output directory. For example "--save-video=800x600"', import_config.resolutionParser.bind(null, "--save-video")).option("--secrets <path>", "path to a file containing secrets in the dotenv format", import_config.dotenvFileLoader).option("--shared-browser-context", "reuse the same browser context between all connected HTTP clients.").option("--snapshot-mode <mode>", 'when taking snapshots for responses, specifies the mode to use. Can be "incremental", "full", or "none". Default is incremental.').option("--storage-state <path>", "path to the storage state file for isolated sessions.").option("--test-id-attribute <attribute>", 'specify the attribute to use for test ids, defaults to "data-testid"').option("--timeout-action <timeout>", "specify action timeout in milliseconds, defaults to 5000ms", import_config.numberParser).option("--timeout-navigation <timeout>", "specify navigation timeout in milliseconds, defaults to 60000ms", import_config.numberParser).option("--user-agent <ua string>", "specify user agent string").option("--user-data-dir <path>", "path to the user data directory. If not specified, a temporary directory will be created.").option("--viewport-size <size>", 'specify browser viewport size in pixels, for example "1280x720"', import_config.resolutionParser.bind(null, "--viewport-size")).addOption(new import_utilsBundle.ProgramOption("--vision", "Legacy option, use --caps=vision instead").hideHelp()).addOption(new import_utilsBundle.ProgramOption("--daemon <socket>", "run as daemon").hideHelp()).action(async (options) => {
|
|
45
|
+
command.option("--allowed-hosts <hosts...>", "comma-separated list of hosts this server is allowed to serve from. Defaults to the host the server is bound to. Pass '*' to disable the host check.", import_config.commaSeparatedList).option("--allowed-origins <origins>", "semicolon-separated list of TRUSTED origins to allow the browser to request. Default is to allow all.\nImportant: *does not* serve as a security boundary and *does not* affect redirects. ", import_config.semicolonSeparatedList).option("--allow-unrestricted-file-access", "allow access to files outside of the workspace roots. Also allows unrestricted access to file:// URLs. By default access to file system is restricted to workspace root directories (or cwd if no roots are configured) only, and navigation to file:// URLs is blocked.").option("--blocked-origins <origins>", "semicolon-separated list of origins to block the browser from requesting. Blocklist is evaluated before allowlist. If used without the allowlist, requests not matching the blocklist are still allowed.\nImportant: *does not* serve as a security boundary and *does not* affect redirects.", import_config.semicolonSeparatedList).option("--block-service-workers", "block service workers").option("--browser <browser>", "browser or chrome channel to use, possible values: chrome, firefox, webkit, msedge.").option("--caps <caps>", "comma-separated list of additional capabilities to enable, possible values: vision, pdf.", import_config.commaSeparatedList).option("--cdp-endpoint <endpoint>", "CDP endpoint to connect to.").option("--cdp-header <headers...>", "CDP headers to send with the connect request, multiple can be specified.", import_config.headerParser).option("--codegen <lang>", 'specify the language to use for code generation, possible values: "typescript", "none". Default is "typescript".', import_config.enumParser.bind(null, "--codegen", ["none", "typescript"])).option("--config <path>", "path to the configuration file.").option("--console-level <level>", 'level of console messages to return: "error", "warning", "info", "debug". Each level includes the messages of more severe levels.', import_config.enumParser.bind(null, "--console-level", ["error", "warning", "info", "debug"])).option("--device <device>", 'device to emulate, for example: "iPhone 15"').option("--executable-path <path>", "path to the browser executable.").option("--extension", 'Connect to a running browser instance (Edge/Chrome only). Requires the "Playwright MCP Bridge" browser extension to be installed.').option("--grant-permissions <permissions...>", 'List of permissions to grant to the browser context, for example "geolocation", "clipboard-read", "clipboard-write".', import_config.commaSeparatedList).option("--headless", "run browser in headless mode, headed by default").option("--host <host>", "host to bind server to. Default is localhost. Use 0.0.0.0 to bind to all interfaces.").option("--ignore-https-errors", "ignore https errors").option("--init-page <path...>", "path to TypeScript file to evaluate on Playwright page object").option("--init-script <path...>", "path to JavaScript file to add as an initialization script. The script will be evaluated in every page before any of the page's scripts. Can be specified multiple times.").option("--isolated", "keep the browser profile in memory, do not save it to disk.").option("--image-responses <mode>", 'whether to send image responses to the client. Can be "allow" or "omit", Defaults to "allow".', import_config.enumParser.bind(null, "--image-responses", ["allow", "omit"])).option("--no-sandbox", "disable the sandbox for all process types that are normally sandboxed.").option("--output-dir <path>", "path to the directory for output files.").option("--output-mode <mode>", 'whether to save snapshots, console messages, network logs to a file or to the standard output. Can be "file" or "stdout". Default is "stdout".', import_config.enumParser.bind(null, "--output-mode", ["file", "stdout"])).option("--port <port>", "port to listen on for SSE transport.").option("--proxy-bypass <bypass>", 'comma-separated domains to bypass proxy, for example ".com,chromium.org,.domain.com"').option("--proxy-server <proxy>", 'specify proxy server, for example "http://myproxy:3128" or "socks5://myproxy:8080"').option("--sandbox", "enable the sandbox for all process types that are normally not sandboxed.").option("--save-session", "Whether to save the Playwright MCP session into the output directory.").option("--save-trace", "Whether to save the Playwright Trace of the session into the output directory.").option("--save-video <size>", 'Whether to save the video of the session into the output directory. For example "--save-video=800x600"', import_config.resolutionParser.bind(null, "--save-video")).option("--secrets <path>", "path to a file containing secrets in the dotenv format", import_config.dotenvFileLoader).option("--shared-browser-context", "reuse the same browser context between all connected HTTP clients.").option("--snapshot-mode <mode>", 'when taking snapshots for responses, specifies the mode to use. Can be "incremental", "full", or "none". Default is incremental.').option("--storage-state <path>", "path to the storage state file for isolated sessions.").option("--test-id-attribute <attribute>", 'specify the attribute to use for test ids, defaults to "data-testid"').option("--timeout-action <timeout>", "specify action timeout in milliseconds, defaults to 5000ms", import_config.numberParser).option("--timeout-navigation <timeout>", "specify navigation timeout in milliseconds, defaults to 60000ms", import_config.numberParser).option("--user-agent <ua string>", "specify user agent string").option("--user-data-dir <path>", "path to the user data directory. If not specified, a temporary directory will be created.").option("--viewport-size <size>", 'specify browser viewport size in pixels, for example "1280x720"', import_config.resolutionParser.bind(null, "--viewport-size")).addOption(new import_utilsBundle.ProgramOption("--vision", "Legacy option, use --caps=vision instead").hideHelp()).addOption(new import_utilsBundle.ProgramOption("--daemon <socket>", "run as daemon").hideHelp()).addOption(new import_utilsBundle.ProgramOption("--daemon-data-dir <path>", "path to the daemon data directory.").hideHelp()).addOption(new import_utilsBundle.ProgramOption("--daemon-headed", "run daemon in headed mode").hideHelp()).action(async (options) => {
|
|
46
|
+
options.sandbox = options.sandbox === true ? void 0 : false;
|
|
46
47
|
(0, import_watchdog.setupExitWatchdog)();
|
|
47
48
|
if (options.vision) {
|
|
48
49
|
console.error("The --vision option is deprecated, use --caps=vision instead");
|
|
@@ -76,7 +77,7 @@ Please run the command below. It will install a local copy of ffmpeg and will no
|
|
|
76
77
|
name: "Playwright",
|
|
77
78
|
nameInConfig: "playwright-daemon",
|
|
78
79
|
version,
|
|
79
|
-
create: () => new import_browserServerBackend.BrowserServerBackend(config, browserContextFactory)
|
|
80
|
+
create: () => new import_browserServerBackend.BrowserServerBackend(config, browserContextFactory, { allTools: true, structuredOutput: true })
|
|
80
81
|
};
|
|
81
82
|
const socketPath = await (0, import_daemon.startMcpDaemonServer)(options.daemon, serverBackendFactory);
|
|
82
83
|
console.error(`Daemon server listening on ${socketPath}`);
|
package/lib/mcp/terminal/cli.js
CHANGED
|
@@ -1,219 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
-
for (let key of __getOwnPropNames(from))
|
|
11
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
-
}
|
|
14
|
-
return to;
|
|
15
|
-
};
|
|
16
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
-
mod
|
|
23
|
-
));
|
|
24
|
-
var import_child_process = require("child_process");
|
|
25
|
-
var import_fs = __toESM(require("fs"));
|
|
26
|
-
var import_net = __toESM(require("net"));
|
|
27
|
-
var import_os = __toESM(require("os"));
|
|
28
|
-
var import_path = __toESM(require("path"));
|
|
29
|
-
var import_utilsBundle = require("playwright-core/lib/utilsBundle");
|
|
30
|
-
var import_socketConnection = require("./socketConnection");
|
|
31
|
-
const debugCli = (0, import_utilsBundle.debug)("pw:cli");
|
|
2
|
+
var import_program = require("./program");
|
|
32
3
|
const packageJSON = require("../../../package.json");
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
addCommand("navigate <url>", "open url in the browser", async (url) => {
|
|
38
|
-
await runMcpCommand("browser_navigate", { url });
|
|
4
|
+
(0, import_program.program)({ version: packageJSON.version }).catch((e) => {
|
|
5
|
+
console.error(e.message);
|
|
6
|
+
process.exit(1);
|
|
39
7
|
});
|
|
40
|
-
addCommand("close", "close the browser", async () => {
|
|
41
|
-
await runMcpCommand("browser_close", {});
|
|
42
|
-
});
|
|
43
|
-
addCommand("click <ref>", "click an element using a ref from a snapshot, e.g. e67", async (ref) => {
|
|
44
|
-
await runMcpCommand("browser_click", { ref });
|
|
45
|
-
});
|
|
46
|
-
addCommand("snapshot", "get accessible snapshot of the current page", async () => {
|
|
47
|
-
await runMcpCommand("browser_snapshot", {});
|
|
48
|
-
});
|
|
49
|
-
addCommand("drag <startRef> <endRef>", "drag from one element to another", async (startRef, endRef) => {
|
|
50
|
-
await runMcpCommand("browser_drag", { startRef, endRef });
|
|
51
|
-
});
|
|
52
|
-
addCommand("hover <ref>", "hover over an element", async (ref) => {
|
|
53
|
-
await runMcpCommand("browser_hover", { ref });
|
|
54
|
-
});
|
|
55
|
-
addCommand("select <ref> <values...>", "select option(s) in a dropdown", async (ref, values) => {
|
|
56
|
-
await runMcpCommand("browser_select_option", { ref, values });
|
|
57
|
-
});
|
|
58
|
-
addCommand("locator <ref>", "generate a locator for an element", async (ref) => {
|
|
59
|
-
await runMcpCommand("browser_generate_locator", { ref });
|
|
60
|
-
});
|
|
61
|
-
addCommand("press <key>", "press a key on the keyboard", async (key) => {
|
|
62
|
-
await runMcpCommand("browser_press_key", { key });
|
|
63
|
-
});
|
|
64
|
-
addCommand("type <ref> <text>", "type text into an element", async (ref, text) => {
|
|
65
|
-
await runMcpCommand("browser_type", { ref, text });
|
|
66
|
-
});
|
|
67
|
-
addCommand("back", "go back to the previous page", async () => {
|
|
68
|
-
await runMcpCommand("browser_navigate_back", {});
|
|
69
|
-
});
|
|
70
|
-
addCommand("wait <time>", "wait for a specified time in seconds", async (time) => {
|
|
71
|
-
await runMcpCommand("browser_wait_for", { time: parseFloat(time) });
|
|
72
|
-
});
|
|
73
|
-
addCommand("wait-for-text <text>", "wait for text to appear", async (text) => {
|
|
74
|
-
await runMcpCommand("browser_wait_for", { text });
|
|
75
|
-
});
|
|
76
|
-
addCommand("dialog-accept [promptText]", "accept a dialog", async (promptText) => {
|
|
77
|
-
await runMcpCommand("browser_handle_dialog", { accept: true, promptText });
|
|
78
|
-
});
|
|
79
|
-
addCommand("dialog-dismiss", "dismiss a dialog", async () => {
|
|
80
|
-
await runMcpCommand("browser_handle_dialog", { accept: false });
|
|
81
|
-
});
|
|
82
|
-
addCommand("screenshot [filename]", "take a screenshot of the current page", async (filename) => {
|
|
83
|
-
await runMcpCommand("browser_take_screenshot", { filename });
|
|
84
|
-
});
|
|
85
|
-
addCommand("resize <width> <height>", "resize the browser window", async (width, height) => {
|
|
86
|
-
await runMcpCommand("browser_resize", { width: parseInt(width, 10), height: parseInt(height, 10) });
|
|
87
|
-
});
|
|
88
|
-
addCommand("upload <paths...>", "upload files", async (paths) => {
|
|
89
|
-
await runMcpCommand("browser_file_upload", { paths });
|
|
90
|
-
});
|
|
91
|
-
addCommand("tabs", "list all browser tabs", async () => {
|
|
92
|
-
await runMcpCommand("browser_tabs", { action: "list" });
|
|
93
|
-
});
|
|
94
|
-
addCommand("tab-new", "create a new browser tab", async () => {
|
|
95
|
-
await runMcpCommand("browser_tabs", { action: "new" });
|
|
96
|
-
});
|
|
97
|
-
addCommand("tab-close [index]", "close a browser tab", async (index) => {
|
|
98
|
-
await runMcpCommand("browser_tabs", { action: "close", index: index !== void 0 ? parseInt(index, 10) : void 0 });
|
|
99
|
-
});
|
|
100
|
-
addCommand("tab-select <index>", "select a browser tab", async (index) => {
|
|
101
|
-
await runMcpCommand("browser_tabs", { action: "select", index: parseInt(index, 10) });
|
|
102
|
-
});
|
|
103
|
-
async function runMcpCommand(name, args) {
|
|
104
|
-
const session = await connectToDaemon();
|
|
105
|
-
const result = await session.callTool(name, args);
|
|
106
|
-
printResult(result);
|
|
107
|
-
session.dispose();
|
|
108
|
-
}
|
|
109
|
-
function printResult(result) {
|
|
110
|
-
for (const content of result.content) {
|
|
111
|
-
if (content.type === "text")
|
|
112
|
-
console.log(content.text);
|
|
113
|
-
else
|
|
114
|
-
console.log(`<${content.type} content>`);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
async function socketExists(socketPath) {
|
|
118
|
-
try {
|
|
119
|
-
const stat = await import_fs.default.promises.stat(socketPath);
|
|
120
|
-
if (stat?.isSocket())
|
|
121
|
-
return true;
|
|
122
|
-
} catch (e) {
|
|
123
|
-
}
|
|
124
|
-
return false;
|
|
125
|
-
}
|
|
126
|
-
class SocketSession {
|
|
127
|
-
constructor(connection) {
|
|
128
|
-
this._nextMessageId = 1;
|
|
129
|
-
this._callbacks = /* @__PURE__ */ new Map();
|
|
130
|
-
this._connection = connection;
|
|
131
|
-
this._connection.onmessage = (message) => this._onMessage(message);
|
|
132
|
-
this._connection.onclose = () => this.dispose();
|
|
133
|
-
}
|
|
134
|
-
async callTool(name, args) {
|
|
135
|
-
return this._send(name, args);
|
|
136
|
-
}
|
|
137
|
-
async _send(method, params = {}) {
|
|
138
|
-
const messageId = this._nextMessageId++;
|
|
139
|
-
const message = {
|
|
140
|
-
id: messageId,
|
|
141
|
-
method,
|
|
142
|
-
params
|
|
143
|
-
};
|
|
144
|
-
await this._connection.send(message);
|
|
145
|
-
return new Promise((resolve, reject) => {
|
|
146
|
-
this._callbacks.set(messageId, { resolve, reject, error: new Error(`Error in method: ${method}`) });
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
dispose() {
|
|
150
|
-
for (const callback of this._callbacks.values())
|
|
151
|
-
callback.reject(callback.error);
|
|
152
|
-
this._callbacks.clear();
|
|
153
|
-
this._connection.close();
|
|
154
|
-
}
|
|
155
|
-
_onMessage(object) {
|
|
156
|
-
if (object.id && this._callbacks.has(object.id)) {
|
|
157
|
-
const callback = this._callbacks.get(object.id);
|
|
158
|
-
this._callbacks.delete(object.id);
|
|
159
|
-
if (object.error) {
|
|
160
|
-
callback.error.cause = new Error(object.error);
|
|
161
|
-
callback.reject(callback.error);
|
|
162
|
-
} else {
|
|
163
|
-
callback.resolve(object.result);
|
|
164
|
-
}
|
|
165
|
-
} else if (object.id) {
|
|
166
|
-
throw new Error(`Unexpected message id: ${object.id}`);
|
|
167
|
-
} else {
|
|
168
|
-
throw new Error(`Unexpected message without id: ${JSON.stringify(object)}`);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
function daemonSocketPath() {
|
|
173
|
-
if (import_os.default.platform() === "win32")
|
|
174
|
-
return import_path.default.join("\\\\.\\pipe", "pw-daemon.sock");
|
|
175
|
-
return import_path.default.join(import_os.default.homedir(), ".playwright", "pw-daemon.sock");
|
|
176
|
-
}
|
|
177
|
-
async function connectToDaemon() {
|
|
178
|
-
const socketPath = daemonSocketPath();
|
|
179
|
-
debugCli(`Connecting to daemon at ${socketPath}`);
|
|
180
|
-
if (await socketExists(socketPath)) {
|
|
181
|
-
debugCli(`Socket file exists, attempting to connect...`);
|
|
182
|
-
try {
|
|
183
|
-
return await connectToSocket(socketPath);
|
|
184
|
-
} catch (e) {
|
|
185
|
-
import_fs.default.unlinkSync(socketPath);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
const cliPath = import_path.default.join(__dirname, "../../../cli.js");
|
|
189
|
-
debugCli(`Will launch daemon process: ${cliPath}`);
|
|
190
|
-
const child = (0, import_child_process.spawn)(process.execPath, [cliPath, "run-mcp-server", `--daemon=${socketPath}`], {
|
|
191
|
-
detached: true,
|
|
192
|
-
stdio: "ignore"
|
|
193
|
-
});
|
|
194
|
-
child.unref();
|
|
195
|
-
const maxRetries = 50;
|
|
196
|
-
const retryDelay = 100;
|
|
197
|
-
for (let i = 0; i < maxRetries; i++) {
|
|
198
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
199
|
-
try {
|
|
200
|
-
return await connectToSocket(socketPath);
|
|
201
|
-
} catch (e) {
|
|
202
|
-
if (e.code !== "ENOENT")
|
|
203
|
-
throw e;
|
|
204
|
-
debugCli(`Retrying to connect to daemon at ${socketPath} (${i + 1}/${maxRetries})`);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
throw new Error(`Failed to connect to daemon at ${socketPath} after ${maxRetries * retryDelay}ms`);
|
|
208
|
-
}
|
|
209
|
-
async function connectToSocket(socketPath) {
|
|
210
|
-
const socket = await new Promise((resolve, reject) => {
|
|
211
|
-
const socket2 = import_net.default.createConnection(socketPath, () => {
|
|
212
|
-
debugCli(`Connected to daemon at ${socketPath}`);
|
|
213
|
-
resolve(socket2);
|
|
214
|
-
});
|
|
215
|
-
socket2.on("error", reject);
|
|
216
|
-
});
|
|
217
|
-
return new SocketSession(new import_socketConnection.SocketConnection(socket));
|
|
218
|
-
}
|
|
219
|
-
void import_utilsBundle.program.parseAsync(process.argv);
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var command_exports = {};
|
|
20
|
+
__export(command_exports, {
|
|
21
|
+
declareCommand: () => declareCommand,
|
|
22
|
+
parseCommand: () => parseCommand
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(command_exports);
|
|
25
|
+
function declareCommand(command) {
|
|
26
|
+
return command;
|
|
27
|
+
}
|
|
28
|
+
function parseCommand(command, args) {
|
|
29
|
+
const shape = command.args ? command.args.shape : {};
|
|
30
|
+
const argv = args["_"];
|
|
31
|
+
const options = command.options?.parse({ ...args, _: void 0 }) ?? {};
|
|
32
|
+
const argsObject = {};
|
|
33
|
+
let i = 0;
|
|
34
|
+
for (const name of Object.keys(shape))
|
|
35
|
+
argsObject[name] = argv[++i];
|
|
36
|
+
let parsedArgsObject = {};
|
|
37
|
+
try {
|
|
38
|
+
parsedArgsObject = command.args?.parse(argsObject) ?? {};
|
|
39
|
+
} catch (e) {
|
|
40
|
+
throw new Error(formatZodError(e));
|
|
41
|
+
}
|
|
42
|
+
const toolName = typeof command.toolName === "function" ? command.toolName({ ...parsedArgsObject, ...options }) : command.toolName;
|
|
43
|
+
const toolParams = command.toolParams({ ...parsedArgsObject, ...options });
|
|
44
|
+
return { toolName, toolParams };
|
|
45
|
+
}
|
|
46
|
+
function formatZodError(error) {
|
|
47
|
+
const issue = error.issues[0];
|
|
48
|
+
if (issue.code === "invalid_type")
|
|
49
|
+
return `${issue.message} in <${issue.path.join(".")}>`;
|
|
50
|
+
return error.issues.map((i) => i.message).join("\n");
|
|
51
|
+
}
|
|
52
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
53
|
+
0 && (module.exports = {
|
|
54
|
+
declareCommand,
|
|
55
|
+
parseCommand
|
|
56
|
+
});
|