@cotestdev/mcp_playwright 0.0.50 → 0.0.52
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 +11 -4
- package/lib/mcp/browser/browserServerBackend.js +2 -4
- package/lib/mcp/browser/config.js +71 -47
- package/lib/mcp/browser/context.js +65 -4
- package/lib/mcp/browser/logFile.js +96 -0
- package/lib/mcp/browser/response.js +107 -104
- package/lib/mcp/browser/sessionLog.js +1 -1
- package/lib/mcp/browser/tab.js +73 -18
- package/lib/mcp/browser/tools/config.js +41 -0
- package/lib/mcp/browser/tools/console.js +6 -2
- package/lib/mcp/browser/tools/cookies.js +152 -0
- package/lib/mcp/browser/tools/install.js +1 -0
- package/lib/mcp/browser/tools/network.js +25 -11
- package/lib/mcp/browser/tools/pdf.js +3 -4
- package/lib/mcp/browser/tools/route.js +140 -0
- package/lib/mcp/browser/tools/runCode.js +0 -2
- package/lib/mcp/browser/tools/screenshot.js +6 -7
- package/lib/mcp/browser/tools/storage.js +3 -4
- package/lib/mcp/browser/tools/tracing.js +10 -9
- package/lib/mcp/browser/tools/utils.js +0 -6
- package/lib/mcp/browser/tools/video.js +31 -13
- package/lib/mcp/browser/tools/webstorage.js +223 -0
- package/lib/mcp/browser/tools.js +11 -3
- package/lib/mcp/extension/cdpRelay.js +7 -7
- package/lib/mcp/extension/extensionContextFactory.js +4 -2
- package/lib/mcp/program.js +19 -12
- package/lib/mcp/terminal/cli.js +23 -2
- package/lib/mcp/terminal/command.js +34 -30
- package/lib/mcp/terminal/commands.js +310 -38
- package/lib/mcp/terminal/daemon.js +23 -38
- package/lib/mcp/terminal/helpGenerator.js +8 -6
- package/lib/mcp/terminal/program.js +482 -199
- package/lib/mcp/terminal/socketConnection.js +17 -2
- package/package.json +2 -2
|
@@ -0,0 +1,223 @@
|
|
|
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 webstorage_exports = {};
|
|
20
|
+
__export(webstorage_exports, {
|
|
21
|
+
default: () => webstorage_default
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(webstorage_exports);
|
|
24
|
+
var import_mcpBundle = require("../../../mcpBundle");
|
|
25
|
+
var import_tool = require("./tool");
|
|
26
|
+
const localStorageList = (0, import_tool.defineTabTool)({
|
|
27
|
+
capability: "storage",
|
|
28
|
+
schema: {
|
|
29
|
+
name: "browser_localstorage_list",
|
|
30
|
+
title: "List localStorage",
|
|
31
|
+
description: "List all localStorage key-value pairs",
|
|
32
|
+
inputSchema: import_mcpBundle.z.object({}),
|
|
33
|
+
type: "readOnly"
|
|
34
|
+
},
|
|
35
|
+
handle: async (tab, params, response) => {
|
|
36
|
+
const items = await tab.page.evaluate(() => {
|
|
37
|
+
const result = [];
|
|
38
|
+
for (let i = 0; i < localStorage.length; i++) {
|
|
39
|
+
const key = localStorage.key(i);
|
|
40
|
+
if (key !== null)
|
|
41
|
+
result.push({ key, value: localStorage.getItem(key) || "" });
|
|
42
|
+
}
|
|
43
|
+
return result;
|
|
44
|
+
});
|
|
45
|
+
if (items.length === 0)
|
|
46
|
+
response.addTextResult("No localStorage items found");
|
|
47
|
+
else
|
|
48
|
+
response.addTextResult(items.map((item) => `${item.key}=${item.value}`).join("\n"));
|
|
49
|
+
response.addCode(`await page.evaluate(() => ({ ...localStorage }));`);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
const localStorageGet = (0, import_tool.defineTabTool)({
|
|
53
|
+
capability: "storage",
|
|
54
|
+
schema: {
|
|
55
|
+
name: "browser_localstorage_get",
|
|
56
|
+
title: "Get localStorage item",
|
|
57
|
+
description: "Get a localStorage item by key",
|
|
58
|
+
inputSchema: import_mcpBundle.z.object({
|
|
59
|
+
key: import_mcpBundle.z.string().describe("Key to get")
|
|
60
|
+
}),
|
|
61
|
+
type: "readOnly"
|
|
62
|
+
},
|
|
63
|
+
handle: async (tab, params, response) => {
|
|
64
|
+
const value = await tab.page.evaluate((key) => localStorage.getItem(key), params.key);
|
|
65
|
+
if (value === null)
|
|
66
|
+
response.addTextResult(`localStorage key '${params.key}' not found`);
|
|
67
|
+
else
|
|
68
|
+
response.addTextResult(`${params.key}=${value}`);
|
|
69
|
+
response.addCode(`await page.evaluate(() => localStorage.getItem('${params.key}'));`);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
const localStorageSet = (0, import_tool.defineTabTool)({
|
|
73
|
+
capability: "storage",
|
|
74
|
+
schema: {
|
|
75
|
+
name: "browser_localstorage_set",
|
|
76
|
+
title: "Set localStorage item",
|
|
77
|
+
description: "Set a localStorage item",
|
|
78
|
+
inputSchema: import_mcpBundle.z.object({
|
|
79
|
+
key: import_mcpBundle.z.string().describe("Key to set"),
|
|
80
|
+
value: import_mcpBundle.z.string().describe("Value to set")
|
|
81
|
+
}),
|
|
82
|
+
type: "action"
|
|
83
|
+
},
|
|
84
|
+
handle: async (tab, params, response) => {
|
|
85
|
+
await tab.page.evaluate(({ key, value }) => localStorage.setItem(key, value), params);
|
|
86
|
+
response.addCode(`await page.evaluate(() => localStorage.setItem('${params.key}', '${params.value}'));`);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
const localStorageDelete = (0, import_tool.defineTabTool)({
|
|
90
|
+
capability: "storage",
|
|
91
|
+
schema: {
|
|
92
|
+
name: "browser_localstorage_delete",
|
|
93
|
+
title: "Delete localStorage item",
|
|
94
|
+
description: "Delete a localStorage item",
|
|
95
|
+
inputSchema: import_mcpBundle.z.object({
|
|
96
|
+
key: import_mcpBundle.z.string().describe("Key to delete")
|
|
97
|
+
}),
|
|
98
|
+
type: "action"
|
|
99
|
+
},
|
|
100
|
+
handle: async (tab, params, response) => {
|
|
101
|
+
await tab.page.evaluate((key) => localStorage.removeItem(key), params.key);
|
|
102
|
+
response.addCode(`await page.evaluate(() => localStorage.removeItem('${params.key}'));`);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
const localStorageClear = (0, import_tool.defineTabTool)({
|
|
106
|
+
capability: "storage",
|
|
107
|
+
schema: {
|
|
108
|
+
name: "browser_localstorage_clear",
|
|
109
|
+
title: "Clear localStorage",
|
|
110
|
+
description: "Clear all localStorage",
|
|
111
|
+
inputSchema: import_mcpBundle.z.object({}),
|
|
112
|
+
type: "action"
|
|
113
|
+
},
|
|
114
|
+
handle: async (tab, params, response) => {
|
|
115
|
+
await tab.page.evaluate(() => localStorage.clear());
|
|
116
|
+
response.addCode(`await page.evaluate(() => localStorage.clear());`);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
const sessionStorageList = (0, import_tool.defineTabTool)({
|
|
120
|
+
capability: "storage",
|
|
121
|
+
schema: {
|
|
122
|
+
name: "browser_sessionstorage_list",
|
|
123
|
+
title: "List sessionStorage",
|
|
124
|
+
description: "List all sessionStorage key-value pairs",
|
|
125
|
+
inputSchema: import_mcpBundle.z.object({}),
|
|
126
|
+
type: "readOnly"
|
|
127
|
+
},
|
|
128
|
+
handle: async (tab, params, response) => {
|
|
129
|
+
const items = await tab.page.evaluate(() => {
|
|
130
|
+
const result = [];
|
|
131
|
+
for (let i = 0; i < sessionStorage.length; i++) {
|
|
132
|
+
const key = sessionStorage.key(i);
|
|
133
|
+
if (key !== null)
|
|
134
|
+
result.push({ key, value: sessionStorage.getItem(key) || "" });
|
|
135
|
+
}
|
|
136
|
+
return result;
|
|
137
|
+
});
|
|
138
|
+
if (items.length === 0)
|
|
139
|
+
response.addTextResult("No sessionStorage items found");
|
|
140
|
+
else
|
|
141
|
+
response.addTextResult(items.map((item) => `${item.key}=${item.value}`).join("\n"));
|
|
142
|
+
response.addCode(`await page.evaluate(() => ({ ...sessionStorage }));`);
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
const sessionStorageGet = (0, import_tool.defineTabTool)({
|
|
146
|
+
capability: "storage",
|
|
147
|
+
schema: {
|
|
148
|
+
name: "browser_sessionstorage_get",
|
|
149
|
+
title: "Get sessionStorage item",
|
|
150
|
+
description: "Get a sessionStorage item by key",
|
|
151
|
+
inputSchema: import_mcpBundle.z.object({
|
|
152
|
+
key: import_mcpBundle.z.string().describe("Key to get")
|
|
153
|
+
}),
|
|
154
|
+
type: "readOnly"
|
|
155
|
+
},
|
|
156
|
+
handle: async (tab, params, response) => {
|
|
157
|
+
const value = await tab.page.evaluate((key) => sessionStorage.getItem(key), params.key);
|
|
158
|
+
if (value === null)
|
|
159
|
+
response.addTextResult(`sessionStorage key '${params.key}' not found`);
|
|
160
|
+
else
|
|
161
|
+
response.addTextResult(`${params.key}=${value}`);
|
|
162
|
+
response.addCode(`await page.evaluate(() => sessionStorage.getItem('${params.key}'));`);
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
const sessionStorageSet = (0, import_tool.defineTabTool)({
|
|
166
|
+
capability: "storage",
|
|
167
|
+
schema: {
|
|
168
|
+
name: "browser_sessionstorage_set",
|
|
169
|
+
title: "Set sessionStorage item",
|
|
170
|
+
description: "Set a sessionStorage item",
|
|
171
|
+
inputSchema: import_mcpBundle.z.object({
|
|
172
|
+
key: import_mcpBundle.z.string().describe("Key to set"),
|
|
173
|
+
value: import_mcpBundle.z.string().describe("Value to set")
|
|
174
|
+
}),
|
|
175
|
+
type: "action"
|
|
176
|
+
},
|
|
177
|
+
handle: async (tab, params, response) => {
|
|
178
|
+
await tab.page.evaluate(({ key, value }) => sessionStorage.setItem(key, value), params);
|
|
179
|
+
response.addCode(`await page.evaluate(() => sessionStorage.setItem('${params.key}', '${params.value}'));`);
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
const sessionStorageDelete = (0, import_tool.defineTabTool)({
|
|
183
|
+
capability: "storage",
|
|
184
|
+
schema: {
|
|
185
|
+
name: "browser_sessionstorage_delete",
|
|
186
|
+
title: "Delete sessionStorage item",
|
|
187
|
+
description: "Delete a sessionStorage item",
|
|
188
|
+
inputSchema: import_mcpBundle.z.object({
|
|
189
|
+
key: import_mcpBundle.z.string().describe("Key to delete")
|
|
190
|
+
}),
|
|
191
|
+
type: "action"
|
|
192
|
+
},
|
|
193
|
+
handle: async (tab, params, response) => {
|
|
194
|
+
await tab.page.evaluate((key) => sessionStorage.removeItem(key), params.key);
|
|
195
|
+
response.addCode(`await page.evaluate(() => sessionStorage.removeItem('${params.key}'));`);
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
const sessionStorageClear = (0, import_tool.defineTabTool)({
|
|
199
|
+
capability: "storage",
|
|
200
|
+
schema: {
|
|
201
|
+
name: "browser_sessionstorage_clear",
|
|
202
|
+
title: "Clear sessionStorage",
|
|
203
|
+
description: "Clear all sessionStorage",
|
|
204
|
+
inputSchema: import_mcpBundle.z.object({}),
|
|
205
|
+
type: "action"
|
|
206
|
+
},
|
|
207
|
+
handle: async (tab, params, response) => {
|
|
208
|
+
await tab.page.evaluate(() => sessionStorage.clear());
|
|
209
|
+
response.addCode(`await page.evaluate(() => sessionStorage.clear());`);
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
var webstorage_default = [
|
|
213
|
+
localStorageList,
|
|
214
|
+
localStorageGet,
|
|
215
|
+
localStorageSet,
|
|
216
|
+
localStorageDelete,
|
|
217
|
+
localStorageClear,
|
|
218
|
+
sessionStorageList,
|
|
219
|
+
sessionStorageGet,
|
|
220
|
+
sessionStorageSet,
|
|
221
|
+
sessionStorageDelete,
|
|
222
|
+
sessionStorageClear
|
|
223
|
+
];
|
package/lib/mcp/browser/tools.js
CHANGED
|
@@ -33,7 +33,9 @@ __export(tools_exports, {
|
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(tools_exports);
|
|
35
35
|
var import_common = __toESM(require("./tools/common"));
|
|
36
|
+
var import_config = __toESM(require("./tools/config"));
|
|
36
37
|
var import_console = __toESM(require("./tools/console"));
|
|
38
|
+
var import_cookies = __toESM(require("./tools/cookies"));
|
|
37
39
|
var import_dialogs = __toESM(require("./tools/dialogs"));
|
|
38
40
|
var import_evaluate = __toESM(require("./tools/evaluate"));
|
|
39
41
|
var import_files = __toESM(require("./tools/files"));
|
|
@@ -44,6 +46,7 @@ var import_mouse = __toESM(require("./tools/mouse"));
|
|
|
44
46
|
var import_navigate = __toESM(require("./tools/navigate"));
|
|
45
47
|
var import_network = __toESM(require("./tools/network"));
|
|
46
48
|
var import_pdf = __toESM(require("./tools/pdf"));
|
|
49
|
+
var import_route = __toESM(require("./tools/route"));
|
|
47
50
|
var import_runCode = __toESM(require("./tools/runCode"));
|
|
48
51
|
var import_snapshot = __toESM(require("./tools/snapshot"));
|
|
49
52
|
var import_screenshot = __toESM(require("./tools/screenshot"));
|
|
@@ -53,9 +56,12 @@ var import_tracing = __toESM(require("./tools/tracing"));
|
|
|
53
56
|
var import_verify = __toESM(require("./tools/verify"));
|
|
54
57
|
var import_video = __toESM(require("./tools/video"));
|
|
55
58
|
var import_wait = __toESM(require("./tools/wait"));
|
|
59
|
+
var import_webstorage = __toESM(require("./tools/webstorage"));
|
|
56
60
|
const browserTools = [
|
|
57
61
|
...import_common.default,
|
|
62
|
+
...import_config.default,
|
|
58
63
|
...import_console.default,
|
|
64
|
+
...import_cookies.default,
|
|
59
65
|
...import_dialogs.default,
|
|
60
66
|
...import_evaluate.default,
|
|
61
67
|
...import_files.default,
|
|
@@ -66,6 +72,7 @@ const browserTools = [
|
|
|
66
72
|
...import_navigate.default,
|
|
67
73
|
...import_network.default,
|
|
68
74
|
...import_pdf.default,
|
|
75
|
+
...import_route.default,
|
|
69
76
|
...import_runCode.default,
|
|
70
77
|
...import_screenshot.default,
|
|
71
78
|
...import_snapshot.default,
|
|
@@ -74,10 +81,11 @@ const browserTools = [
|
|
|
74
81
|
...import_tracing.default,
|
|
75
82
|
...import_verify.default,
|
|
76
83
|
...import_video.default,
|
|
77
|
-
...import_wait.default
|
|
84
|
+
...import_wait.default,
|
|
85
|
+
...import_webstorage.default
|
|
78
86
|
];
|
|
79
|
-
function filteredTools(
|
|
80
|
-
return browserTools.filter((tool) => tool.capability.startsWith("core") ||
|
|
87
|
+
function filteredTools(config2) {
|
|
88
|
+
return browserTools.filter((tool) => tool.capability.startsWith("core") || config2.capabilities?.includes(tool.capability)).filter((tool) => !tool.skillOnly);
|
|
81
89
|
}
|
|
82
90
|
// Annotate the CommonJS export names for ESM import in node:
|
|
83
91
|
0 && (module.exports = {
|
|
@@ -62,22 +62,22 @@ class CDPRelayServer {
|
|
|
62
62
|
extensionEndpoint() {
|
|
63
63
|
return `${this._wsHost}${this._extensionPath}`;
|
|
64
64
|
}
|
|
65
|
-
async ensureExtensionConnectionForMCPContext(clientInfo, abortSignal,
|
|
65
|
+
async ensureExtensionConnectionForMCPContext(clientInfo, abortSignal, forceNewTab) {
|
|
66
66
|
debugLogger("Ensuring extension connection for MCP context");
|
|
67
67
|
if (this._extensionConnection)
|
|
68
68
|
return;
|
|
69
|
-
this._connectBrowser(clientInfo,
|
|
69
|
+
this._connectBrowser(clientInfo, forceNewTab);
|
|
70
70
|
debugLogger("Waiting for incoming extension connection");
|
|
71
71
|
await Promise.race([
|
|
72
72
|
this._extensionConnectionPromise,
|
|
73
73
|
new Promise((_, reject) => setTimeout(() => {
|
|
74
|
-
reject(new Error(`Extension connection timeout. Make sure the "Playwright MCP Bridge" extension is installed. See https://github.com/microsoft/playwright-mcp/blob/main/extension/README.md for installation instructions.`));
|
|
74
|
+
reject(new Error(`Extension connection timeout. Make sure the "Playwright MCP Bridge" extension is installed. See https://github.com/microsoft/playwright-mcp/blob/main/packages/extension/README.md for installation instructions.`));
|
|
75
75
|
}, process.env.PWMCP_TEST_CONNECTION_TIMEOUT ? parseInt(process.env.PWMCP_TEST_CONNECTION_TIMEOUT, 10) : 5e3)),
|
|
76
76
|
new Promise((_, reject) => abortSignal.addEventListener("abort", reject))
|
|
77
77
|
]);
|
|
78
78
|
debugLogger("Extension connection established");
|
|
79
79
|
}
|
|
80
|
-
_connectBrowser(clientInfo,
|
|
80
|
+
_connectBrowser(clientInfo, forceNewTab) {
|
|
81
81
|
const mcpRelayEndpoint = `${this._wsHost}${this._extensionPath}`;
|
|
82
82
|
const url = new URL("chrome-extension://jakfalbnbhgkpmoaakfflhflbfpkailf/connect.html");
|
|
83
83
|
url.searchParams.set("mcpRelayUrl", mcpRelayEndpoint);
|
|
@@ -87,8 +87,8 @@ class CDPRelayServer {
|
|
|
87
87
|
};
|
|
88
88
|
url.searchParams.set("client", JSON.stringify(client));
|
|
89
89
|
url.searchParams.set("protocolVersion", process.env.PWMCP_TEST_PROTOCOL_VERSION ?? protocol.VERSION.toString());
|
|
90
|
-
if (
|
|
91
|
-
url.searchParams.set("newTab",
|
|
90
|
+
if (forceNewTab)
|
|
91
|
+
url.searchParams.set("newTab", "true");
|
|
92
92
|
const token = process.env.PLAYWRIGHT_MCP_EXTENSION_TOKEN;
|
|
93
93
|
if (token)
|
|
94
94
|
url.searchParams.set("token", token);
|
|
@@ -98,7 +98,7 @@ class CDPRelayServer {
|
|
|
98
98
|
const executableInfo = import_registry.registry.findExecutable(this._browserChannel);
|
|
99
99
|
if (!executableInfo)
|
|
100
100
|
throw new Error(`Unsupported channel: "${this._browserChannel}"`);
|
|
101
|
-
executablePath = executableInfo.executablePath(
|
|
101
|
+
executablePath = executableInfo.executablePath();
|
|
102
102
|
if (!executablePath)
|
|
103
103
|
throw new Error(`"${this._browserChannel}" executable not found. Make sure it is installed at a standard location.`);
|
|
104
104
|
}
|
|
@@ -37,10 +37,11 @@ var import_utils = require("playwright-core/lib/utils");
|
|
|
37
37
|
var import_cdpRelay = require("./cdpRelay");
|
|
38
38
|
const debugLogger = (0, import_utilsBundle.debug)("pw:mcp:relay");
|
|
39
39
|
class ExtensionContextFactory {
|
|
40
|
-
constructor(browserChannel, userDataDir, executablePath) {
|
|
40
|
+
constructor(browserChannel, userDataDir, executablePath, forceNewTab) {
|
|
41
41
|
this._browserChannel = browserChannel;
|
|
42
42
|
this._userDataDir = userDataDir;
|
|
43
43
|
this._executablePath = executablePath;
|
|
44
|
+
this._forceNewTab = forceNewTab;
|
|
44
45
|
}
|
|
45
46
|
async createContext(clientInfo, abortSignal, options) {
|
|
46
47
|
const browser = await this._obtainBrowser(clientInfo, abortSignal, options?.toolName);
|
|
@@ -54,7 +55,8 @@ class ExtensionContextFactory {
|
|
|
54
55
|
}
|
|
55
56
|
async _obtainBrowser(clientInfo, abortSignal, toolName) {
|
|
56
57
|
const relay = await this._startRelay(abortSignal);
|
|
57
|
-
|
|
58
|
+
const forceNewTab = this._forceNewTab || toolName === "browser_navigate";
|
|
59
|
+
await relay.ensureExtensionConnectionForMCPContext(clientInfo, abortSignal, forceNewTab);
|
|
58
60
|
return await playwright.chromium.connectOverCDP(relay.cdpEndpoint(), { isLocal: true });
|
|
59
61
|
}
|
|
60
62
|
async _startRelay(abortSignal) {
|
package/lib/mcp/program.js
CHANGED
|
@@ -42,7 +42,7 @@ 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, devtools.", 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
|
|
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, devtools.", 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("--cdp-timeout <timeout>", "timeout in milliseconds for connecting to CDP endpoint, defaults to 30000ms", import_config.numberParser).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-session <path>", "path to the daemon config.").hideHelp()).action(async (options) => {
|
|
46
46
|
options.sandbox = options.sandbox === true ? void 0 : false;
|
|
47
47
|
(0, import_watchdog.setupExitWatchdog)();
|
|
48
48
|
if (options.vision) {
|
|
@@ -63,17 +63,24 @@ Please run the command below. It will install a local copy of ffmpeg and will no
|
|
|
63
63
|
process.exit(1);
|
|
64
64
|
}
|
|
65
65
|
const browserContextFactory = (0, import_browserContextFactory.contextFactory)(config);
|
|
66
|
-
const
|
|
67
|
-
|
|
66
|
+
const forceNewTab = !!config.sessionConfig;
|
|
67
|
+
const extensionContextFactory = new import_extensionContextFactory.ExtensionContextFactory(config.browser.launchOptions.channel || "chrome", config.browser.userDataDir, config.browser.launchOptions.executablePath, forceNewTab);
|
|
68
|
+
if (config.sessionConfig) {
|
|
68
69
|
const contextFactory2 = config.extension ? extensionContextFactory : browserContextFactory;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
70
|
+
console.log(`### Config`);
|
|
71
|
+
console.log("```json");
|
|
72
|
+
console.log(JSON.stringify(config, null, 2));
|
|
73
|
+
console.log("```");
|
|
74
|
+
try {
|
|
75
|
+
const socketPath = await (0, import_daemon.startMcpDaemonServer)(config, contextFactory2);
|
|
76
|
+
console.log(`### Success
|
|
77
|
+
Daemon listening on ${socketPath}`);
|
|
78
|
+
console.log("<EOF>");
|
|
79
|
+
} catch (error) {
|
|
80
|
+
console.log(`### Error
|
|
81
|
+
${error.message}`);
|
|
82
|
+
console.log("<EOF>");
|
|
83
|
+
}
|
|
77
84
|
return;
|
|
78
85
|
}
|
|
79
86
|
if (config.extension) {
|
|
@@ -98,7 +105,7 @@ Please run the command below. It will install a local copy of ffmpeg and will no
|
|
|
98
105
|
function checkFfmpeg() {
|
|
99
106
|
try {
|
|
100
107
|
const executable = import_server.registry.findExecutable("ffmpeg");
|
|
101
|
-
return import_fs.default.existsSync(executable.executablePath(
|
|
108
|
+
return import_fs.default.existsSync(executable.executablePath());
|
|
102
109
|
} catch (error) {
|
|
103
110
|
return false;
|
|
104
111
|
}
|
package/lib/mcp/terminal/cli.js
CHANGED
|
@@ -1,7 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
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
|
+
));
|
|
2
24
|
var import_program = require("./program");
|
|
3
|
-
|
|
4
|
-
(0, import_program.program)({ version: packageJSON.version }).catch((e) => {
|
|
25
|
+
(0, import_program.program)(require.resolve("../../../package.json")).catch((e) => {
|
|
5
26
|
console.error(e.message);
|
|
6
27
|
process.exit(1);
|
|
7
28
|
});
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
var command_exports = {};
|
|
30
20
|
__export(command_exports, {
|
|
@@ -32,35 +22,49 @@ __export(command_exports, {
|
|
|
32
22
|
parseCommand: () => parseCommand
|
|
33
23
|
});
|
|
34
24
|
module.exports = __toCommonJS(command_exports);
|
|
35
|
-
var
|
|
25
|
+
var import_mcpBundle = require("../../mcpBundle");
|
|
36
26
|
function declareCommand(command) {
|
|
37
27
|
return command;
|
|
38
28
|
}
|
|
29
|
+
const kEmptyOptions = import_mcpBundle.z.object({});
|
|
30
|
+
const kEmptyArgs = import_mcpBundle.z.object({});
|
|
39
31
|
function parseCommand(command, args) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
const
|
|
44
|
-
const
|
|
32
|
+
const optionsObject = { ...args };
|
|
33
|
+
delete optionsObject["_"];
|
|
34
|
+
const optionsSchema = (command.options ?? kEmptyOptions).strict();
|
|
35
|
+
const options = zodParse(optionsSchema, optionsObject, "option");
|
|
36
|
+
const argsSchema = (command.args ?? kEmptyArgs).strict();
|
|
37
|
+
const argNames = [...Object.keys(argsSchema.shape)];
|
|
38
|
+
const argv = args["_"].slice(1);
|
|
39
|
+
if (argv.length > argNames.length)
|
|
40
|
+
throw new Error(`error: too many arguments: expected ${argNames.length}, received ${argv.length}`);
|
|
45
41
|
const argsObject = {};
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
argsObject[name] = argv[++i];
|
|
49
|
-
let parsedArgsObject = {};
|
|
50
|
-
try {
|
|
51
|
-
parsedArgsObject = command.args?.parse(argsObject) ?? {};
|
|
52
|
-
} catch (e) {
|
|
53
|
-
throw new Error(formatZodError(e));
|
|
54
|
-
}
|
|
42
|
+
argNames.forEach((name, index) => argsObject[name] = argv[index]);
|
|
43
|
+
const parsedArgsObject = zodParse(argsSchema, argsObject, "argument");
|
|
55
44
|
const toolName = typeof command.toolName === "function" ? command.toolName({ ...parsedArgsObject, ...options }) : command.toolName;
|
|
56
45
|
const toolParams = command.toolParams({ ...parsedArgsObject, ...options });
|
|
57
46
|
return { toolName, toolParams };
|
|
58
47
|
}
|
|
59
|
-
function
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
48
|
+
function zodParse(schema, data, type) {
|
|
49
|
+
try {
|
|
50
|
+
return schema.parse(data);
|
|
51
|
+
} catch (e) {
|
|
52
|
+
throw new Error(e.issues.map((issue) => {
|
|
53
|
+
const keys = issue.keys || [""];
|
|
54
|
+
const props = keys.map((key) => [...issue.path, key].filter(Boolean).join("."));
|
|
55
|
+
return props.map((prop) => {
|
|
56
|
+
const label = type === "option" ? `'--${prop}' option` : `'${prop}' argument`;
|
|
57
|
+
switch (issue.code) {
|
|
58
|
+
case "invalid_type":
|
|
59
|
+
return "error: " + label + ": " + issue.message.toLowerCase().replace(/invalid input:/, "").trim();
|
|
60
|
+
case "unrecognized_keys":
|
|
61
|
+
return "error: unknown " + label;
|
|
62
|
+
default:
|
|
63
|
+
return "error: " + label + ": " + issue.message.toLowerCase();
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}).flat().join("\n"));
|
|
67
|
+
}
|
|
64
68
|
}
|
|
65
69
|
// Annotate the CommonJS export names for ESM import in node:
|
|
66
70
|
0 && (module.exports = {
|