playwright 1.58.0-alpha-2025-11-21 → 1.58.0-alpha-2025-11-22
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/ThirdPartyNotices.txt +208 -1
- package/lib/agents/agent.js +85 -0
- package/lib/agents/agentParser.js +89 -0
- package/lib/agents/generateAgents.js +26 -73
- package/lib/agents/performTask.js +60 -0
- package/lib/index.js +6 -0
- package/lib/mcp/browser/browserContextFactory.js +15 -2
- package/lib/mcp/browser/config.js +29 -2
- package/lib/mcp/browser/context.js +21 -1
- package/lib/mcp/browser/tab.js +11 -4
- package/lib/mcp/program.js +1 -1
- package/lib/mcp/sdk/bundle.js +3 -0
- package/lib/mcp/sdk/proxyBackend.js +1 -1
- package/lib/mcp/sdk/server.js +11 -1
- package/lib/mcp/test/browserBackend.js +2 -12
- package/lib/mcp/test/testBackend.js +4 -4
- package/lib/mcpBundleImpl.js +18 -15
- package/lib/runner/processHost.js +3 -0
- package/package.json +2 -2
|
@@ -29,7 +29,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
29
29
|
var browserContextFactory_exports = {};
|
|
30
30
|
__export(browserContextFactory_exports, {
|
|
31
31
|
SharedContextFactory: () => SharedContextFactory,
|
|
32
|
-
contextFactory: () => contextFactory
|
|
32
|
+
contextFactory: () => contextFactory,
|
|
33
|
+
identityBrowserContextFactory: () => identityBrowserContextFactory
|
|
33
34
|
});
|
|
34
35
|
module.exports = __toCommonJS(browserContextFactory_exports);
|
|
35
36
|
var import_crypto = __toESM(require("crypto"));
|
|
@@ -53,6 +54,17 @@ function contextFactory(config) {
|
|
|
53
54
|
return new IsolatedContextFactory(config);
|
|
54
55
|
return new PersistentContextFactory(config);
|
|
55
56
|
}
|
|
57
|
+
function identityBrowserContextFactory(browserContext) {
|
|
58
|
+
return {
|
|
59
|
+
createContext: async (clientInfo, abortSignal, toolName) => {
|
|
60
|
+
return {
|
|
61
|
+
browserContext,
|
|
62
|
+
close: async () => {
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
56
68
|
class BaseContextFactory {
|
|
57
69
|
constructor(name, config) {
|
|
58
70
|
this._logName = name;
|
|
@@ -292,5 +304,6 @@ async function computeTracesDir(config, clientInfo) {
|
|
|
292
304
|
// Annotate the CommonJS export names for ESM import in node:
|
|
293
305
|
0 && (module.exports = {
|
|
294
306
|
SharedContextFactory,
|
|
295
|
-
contextFactory
|
|
307
|
+
contextFactory,
|
|
308
|
+
identityBrowserContextFactory
|
|
296
309
|
});
|
|
@@ -38,7 +38,8 @@ __export(config_exports, {
|
|
|
38
38
|
outputFile: () => outputFile,
|
|
39
39
|
resolutionParser: () => resolutionParser,
|
|
40
40
|
resolveCLIConfig: () => resolveCLIConfig,
|
|
41
|
-
resolveConfig: () => resolveConfig
|
|
41
|
+
resolveConfig: () => resolveConfig,
|
|
42
|
+
semicolonSeparatedList: () => semicolonSeparatedList
|
|
42
43
|
});
|
|
43
44
|
module.exports = __toCommonJS(config_exports);
|
|
44
45
|
var import_fs = __toESM(require("fs"));
|
|
@@ -60,6 +61,10 @@ const defaultConfig = {
|
|
|
60
61
|
viewport: null
|
|
61
62
|
}
|
|
62
63
|
},
|
|
64
|
+
network: {
|
|
65
|
+
allowedOrigins: void 0,
|
|
66
|
+
blockedOrigins: void 0
|
|
67
|
+
},
|
|
63
68
|
server: {},
|
|
64
69
|
saveTrace: false,
|
|
65
70
|
timeouts: {
|
|
@@ -88,6 +93,12 @@ async function validateConfig(config) {
|
|
|
88
93
|
throw new Error(`Init script file does not exist: ${script}`);
|
|
89
94
|
}
|
|
90
95
|
}
|
|
96
|
+
if (config.browser.initPage) {
|
|
97
|
+
for (const page of config.browser.initPage) {
|
|
98
|
+
if (!await (0, import_util.fileExistsAsync)(page))
|
|
99
|
+
throw new Error(`Init page file does not exist: ${page}`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
91
102
|
if (config.sharedBrowserContext && config.saveVideo)
|
|
92
103
|
throw new Error("saveVideo is not supported when sharedBrowserContext is true");
|
|
93
104
|
}
|
|
@@ -168,6 +179,10 @@ function configFromCLIOptions(cliOptions) {
|
|
|
168
179
|
allowedHosts: cliOptions.allowedHosts
|
|
169
180
|
},
|
|
170
181
|
capabilities: cliOptions.caps,
|
|
182
|
+
network: {
|
|
183
|
+
allowedOrigins: cliOptions.allowedOrigins,
|
|
184
|
+
blockedOrigins: cliOptions.blockedOrigins
|
|
185
|
+
},
|
|
171
186
|
saveSession: cliOptions.saveSession,
|
|
172
187
|
saveTrace: cliOptions.saveTrace,
|
|
173
188
|
saveVideo: cliOptions.saveVideo,
|
|
@@ -186,6 +201,8 @@ function configFromCLIOptions(cliOptions) {
|
|
|
186
201
|
function configFromEnv() {
|
|
187
202
|
const options = {};
|
|
188
203
|
options.allowedHosts = commaSeparatedList(process.env.PLAYWRIGHT_MCP_ALLOWED_HOSTNAMES);
|
|
204
|
+
options.allowedOrigins = semicolonSeparatedList(process.env.PLAYWRIGHT_MCP_ALLOWED_ORIGINS);
|
|
205
|
+
options.blockedOrigins = semicolonSeparatedList(process.env.PLAYWRIGHT_MCP_BLOCKED_ORIGINS);
|
|
189
206
|
options.blockServiceWorkers = envToBoolean(process.env.PLAYWRIGHT_MCP_BLOCK_SERVICE_WORKERS);
|
|
190
207
|
options.browser = envToString(process.env.PLAYWRIGHT_MCP_BROWSER);
|
|
191
208
|
options.caps = commaSeparatedList(process.env.PLAYWRIGHT_MCP_CAPS);
|
|
@@ -285,6 +302,10 @@ function mergeConfig(base, overrides) {
|
|
|
285
302
|
...pickDefined(base),
|
|
286
303
|
...pickDefined(overrides),
|
|
287
304
|
browser,
|
|
305
|
+
network: {
|
|
306
|
+
...pickDefined(base.network),
|
|
307
|
+
...pickDefined(overrides.network)
|
|
308
|
+
},
|
|
288
309
|
server: {
|
|
289
310
|
...pickDefined(base.server),
|
|
290
311
|
...pickDefined(overrides.server)
|
|
@@ -295,6 +316,11 @@ function mergeConfig(base, overrides) {
|
|
|
295
316
|
}
|
|
296
317
|
};
|
|
297
318
|
}
|
|
319
|
+
function semicolonSeparatedList(value) {
|
|
320
|
+
if (!value)
|
|
321
|
+
return void 0;
|
|
322
|
+
return value.split(";").map((v) => v.trim());
|
|
323
|
+
}
|
|
298
324
|
function commaSeparatedList(value) {
|
|
299
325
|
if (!value)
|
|
300
326
|
return void 0;
|
|
@@ -364,5 +390,6 @@ function sanitizeForFilePath(s) {
|
|
|
364
390
|
outputFile,
|
|
365
391
|
resolutionParser,
|
|
366
392
|
resolveCLIConfig,
|
|
367
|
-
resolveConfig
|
|
393
|
+
resolveConfig,
|
|
394
|
+
semicolonSeparatedList
|
|
368
395
|
});
|
|
@@ -75,7 +75,6 @@ class Context {
|
|
|
75
75
|
const { browserContext } = await this._ensureBrowserContext();
|
|
76
76
|
const page = await browserContext.newPage();
|
|
77
77
|
this._currentTab = this._tabs.find((t) => t.page === page);
|
|
78
|
-
await this._currentTab.initializedPromise;
|
|
79
78
|
return this._currentTab;
|
|
80
79
|
}
|
|
81
80
|
async selectTab(index) {
|
|
@@ -169,6 +168,17 @@ class Context {
|
|
|
169
168
|
await this.closeBrowserContext();
|
|
170
169
|
Context._allContexts.delete(this);
|
|
171
170
|
}
|
|
171
|
+
async _setupRequestInterception(context) {
|
|
172
|
+
if (this.config.network?.allowedOrigins?.length) {
|
|
173
|
+
await context.route("**", (route) => route.abort("blockedbyclient"));
|
|
174
|
+
for (const origin of this.config.network.allowedOrigins)
|
|
175
|
+
await context.route(originOrHostGlob(origin), (route) => route.continue());
|
|
176
|
+
}
|
|
177
|
+
if (this.config.network?.blockedOrigins?.length) {
|
|
178
|
+
for (const origin of this.config.network.blockedOrigins)
|
|
179
|
+
await context.route(originOrHostGlob(origin), (route) => route.abort("blockedbyclient"));
|
|
180
|
+
}
|
|
181
|
+
}
|
|
172
182
|
async ensureBrowserContext() {
|
|
173
183
|
const { browserContext } = await this._ensureBrowserContext();
|
|
174
184
|
return browserContext;
|
|
@@ -189,6 +199,7 @@ class Context {
|
|
|
189
199
|
import_playwright_core.selectors.setTestIdAttribute(this.config.testIdAttribute);
|
|
190
200
|
const result = await this._browserContextFactory.createContext(this._clientInfo, this._abortController.signal, this._runningToolName);
|
|
191
201
|
const { browserContext } = result;
|
|
202
|
+
await this._setupRequestInterception(browserContext);
|
|
192
203
|
if (this.sessionLog)
|
|
193
204
|
await InputRecorder.create(this, browserContext);
|
|
194
205
|
for (const page of browserContext.pages())
|
|
@@ -213,6 +224,15 @@ class Context {
|
|
|
213
224
|
};
|
|
214
225
|
}
|
|
215
226
|
}
|
|
227
|
+
function originOrHostGlob(originOrHost) {
|
|
228
|
+
try {
|
|
229
|
+
const url = new URL(originOrHost);
|
|
230
|
+
if (url.origin !== "null")
|
|
231
|
+
return `${url.origin}/**`;
|
|
232
|
+
} catch {
|
|
233
|
+
}
|
|
234
|
+
return `*://${originOrHost}/**`;
|
|
235
|
+
}
|
|
216
236
|
class InputRecorder {
|
|
217
237
|
constructor(context, browserContext) {
|
|
218
238
|
this._context = context;
|
package/lib/mcp/browser/tab.js
CHANGED
|
@@ -65,7 +65,7 @@ class Tab extends import_events.EventEmitter {
|
|
|
65
65
|
page.setDefaultNavigationTimeout(this.context.config.timeouts.navigation);
|
|
66
66
|
page.setDefaultTimeout(this.context.config.timeouts.action);
|
|
67
67
|
page[tabSymbol] = this;
|
|
68
|
-
this.
|
|
68
|
+
this._initializedPromise = this._initialize();
|
|
69
69
|
}
|
|
70
70
|
static forPage(page) {
|
|
71
71
|
return page[tabSymbol];
|
|
@@ -151,9 +151,11 @@ class Tab extends import_events.EventEmitter {
|
|
|
151
151
|
return this === this.context.currentTab();
|
|
152
152
|
}
|
|
153
153
|
async waitForLoadState(state, options) {
|
|
154
|
+
await this._initializedPromise;
|
|
154
155
|
await (0, import_utils2.callOnPageNoTrace)(this.page, (page) => page.waitForLoadState(state, options).catch(import_log.logUnhandledError));
|
|
155
156
|
}
|
|
156
157
|
async navigate(url) {
|
|
158
|
+
await this._initializedPromise;
|
|
157
159
|
this._clearCollectedArtifacts();
|
|
158
160
|
const downloadEvent = (0, import_utils2.callOnPageNoTrace)(this.page, (page) => page.waitForEvent("download").catch(import_log.logUnhandledError));
|
|
159
161
|
try {
|
|
@@ -175,14 +177,15 @@ class Tab extends import_events.EventEmitter {
|
|
|
175
177
|
await this.waitForLoadState("load", { timeout: 5e3 });
|
|
176
178
|
}
|
|
177
179
|
async consoleMessages(type) {
|
|
178
|
-
await this.
|
|
180
|
+
await this._initializedPromise;
|
|
179
181
|
return this._consoleMessages.filter((message) => type ? message.type === type : true);
|
|
180
182
|
}
|
|
181
183
|
async requests() {
|
|
182
|
-
await this.
|
|
184
|
+
await this._initializedPromise;
|
|
183
185
|
return this._requests;
|
|
184
186
|
}
|
|
185
187
|
async captureSnapshot() {
|
|
188
|
+
await this._initializedPromise;
|
|
186
189
|
let tabSnapshot;
|
|
187
190
|
const modalStates = await this._raceAgainstModalStates(async () => {
|
|
188
191
|
const snapshot = await this.page._snapshotForAI({ track: "response" });
|
|
@@ -228,12 +231,15 @@ class Tab extends import_events.EventEmitter {
|
|
|
228
231
|
]);
|
|
229
232
|
}
|
|
230
233
|
async waitForCompletion(callback) {
|
|
234
|
+
await this._initializedPromise;
|
|
231
235
|
await this._raceAgainstModalStates(() => (0, import_utils2.waitForCompletion)(this, callback));
|
|
232
236
|
}
|
|
233
237
|
async refLocator(params) {
|
|
238
|
+
await this._initializedPromise;
|
|
234
239
|
return (await this.refLocators([params]))[0];
|
|
235
240
|
}
|
|
236
241
|
async refLocators(params) {
|
|
242
|
+
await this._initializedPromise;
|
|
237
243
|
return Promise.all(params.map(async (param) => {
|
|
238
244
|
try {
|
|
239
245
|
const locator = this.page.locator(`aria-ref=${param.ref}`).describe(param.element);
|
|
@@ -250,7 +256,8 @@ class Tab extends import_events.EventEmitter {
|
|
|
250
256
|
return;
|
|
251
257
|
}
|
|
252
258
|
await (0, import_utils2.callOnPageNoTrace)(this.page, (page) => {
|
|
253
|
-
return page.evaluate(() => new Promise((f) => setTimeout(f, 1e3)))
|
|
259
|
+
return page.evaluate(() => new Promise((f) => setTimeout(f, 1e3))).catch(() => {
|
|
260
|
+
});
|
|
254
261
|
});
|
|
255
262
|
}
|
|
256
263
|
}
|
package/lib/mcp/program.js
CHANGED
|
@@ -42,7 +42,7 @@ var import_proxyBackend = require("./sdk/proxyBackend");
|
|
|
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("--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("--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".').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("--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("--connect-tool", "Allow to switch between different browser connection methods.").hideHelp()).addOption(new import_utilsBundle.ProgramOption("--vision", "Legacy option, use --caps=vision instead").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("--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("--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".').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("--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("--connect-tool", "Allow to switch between different browser connection methods.").hideHelp()).addOption(new import_utilsBundle.ProgramOption("--vision", "Legacy option, use --caps=vision instead").hideHelp()).action(async (options) => {
|
|
46
46
|
(0, import_watchdog.setupExitWatchdog)();
|
|
47
47
|
if (options.vision) {
|
|
48
48
|
console.error("The --vision option is deprecated, use --caps=vision instead");
|
package/lib/mcp/sdk/bundle.js
CHANGED
|
@@ -32,6 +32,7 @@ __export(bundle_exports, {
|
|
|
32
32
|
Client: () => Client,
|
|
33
33
|
ListRootsRequestSchema: () => ListRootsRequestSchema,
|
|
34
34
|
ListToolsRequestSchema: () => ListToolsRequestSchema,
|
|
35
|
+
Loop: () => Loop,
|
|
35
36
|
PingRequestSchema: () => PingRequestSchema,
|
|
36
37
|
ProgressNotificationSchema: () => ProgressNotificationSchema,
|
|
37
38
|
SSEClientTransport: () => SSEClientTransport,
|
|
@@ -60,6 +61,7 @@ const ListRootsRequestSchema = bundle.ListRootsRequestSchema;
|
|
|
60
61
|
const ProgressNotificationSchema = bundle.ProgressNotificationSchema;
|
|
61
62
|
const ListToolsRequestSchema = bundle.ListToolsRequestSchema;
|
|
62
63
|
const PingRequestSchema = bundle.PingRequestSchema;
|
|
64
|
+
const Loop = bundle.Loop;
|
|
63
65
|
const z = bundle.z;
|
|
64
66
|
// Annotate the CommonJS export names for ESM import in node:
|
|
65
67
|
0 && (module.exports = {
|
|
@@ -67,6 +69,7 @@ const z = bundle.z;
|
|
|
67
69
|
Client,
|
|
68
70
|
ListRootsRequestSchema,
|
|
69
71
|
ListToolsRequestSchema,
|
|
72
|
+
Loop,
|
|
70
73
|
PingRequestSchema,
|
|
71
74
|
ProgressNotificationSchema,
|
|
72
75
|
SSEClientTransport,
|
|
@@ -116,7 +116,7 @@ Error: ${error}
|
|
|
116
116
|
});
|
|
117
117
|
client.setRequestHandler(mcpBundle.ListRootsRequestSchema, () => ({ roots: this._clientInfo?.roots || [] }));
|
|
118
118
|
client.setRequestHandler(mcpBundle.PingRequestSchema, () => ({}));
|
|
119
|
-
const transport =
|
|
119
|
+
const transport = factory.connect();
|
|
120
120
|
await client.connect(transport);
|
|
121
121
|
this._currentClient = client;
|
|
122
122
|
return client;
|
package/lib/mcp/sdk/server.js
CHANGED
|
@@ -32,6 +32,7 @@ __export(server_exports, {
|
|
|
32
32
|
createServer: () => createServer,
|
|
33
33
|
firstRootPath: () => firstRootPath,
|
|
34
34
|
start: () => start,
|
|
35
|
+
wrapInClient: () => wrapInClient,
|
|
35
36
|
wrapInProcess: () => wrapInProcess
|
|
36
37
|
});
|
|
37
38
|
module.exports = __toCommonJS(server_exports);
|
|
@@ -46,10 +47,18 @@ async function connect(factory, transport, runHeartbeat) {
|
|
|
46
47
|
const server = createServer(factory.name, factory.version, factory.create(), runHeartbeat);
|
|
47
48
|
await server.connect(transport);
|
|
48
49
|
}
|
|
49
|
-
|
|
50
|
+
function wrapInProcess(backend) {
|
|
50
51
|
const server = createServer("Internal", "0.0.0", backend, false);
|
|
51
52
|
return new import_inProcessTransport.InProcessTransport(server);
|
|
52
53
|
}
|
|
54
|
+
async function wrapInClient(backend, options) {
|
|
55
|
+
const server = createServer("Internal", "0.0.0", backend, false);
|
|
56
|
+
const transport = new import_inProcessTransport.InProcessTransport(server);
|
|
57
|
+
const client = new mcpBundle.Client({ name: options.name, version: options.version });
|
|
58
|
+
await client.connect(transport);
|
|
59
|
+
await client.ping();
|
|
60
|
+
return client;
|
|
61
|
+
}
|
|
53
62
|
function createServer(name, version, backend, runHeartbeat) {
|
|
54
63
|
const server = new mcpBundle.Server({ name, version }, {
|
|
55
64
|
capabilities: {
|
|
@@ -194,5 +203,6 @@ function mergeTextParts(result) {
|
|
|
194
203
|
createServer,
|
|
195
204
|
firstRootPath,
|
|
196
205
|
start,
|
|
206
|
+
wrapInClient,
|
|
197
207
|
wrapInProcess
|
|
198
208
|
});
|
|
@@ -25,13 +25,14 @@ var import_config = require("../browser/config");
|
|
|
25
25
|
var import_browserServerBackend = require("../browser/browserServerBackend");
|
|
26
26
|
var import_tab = require("../browser/tab");
|
|
27
27
|
var import_util = require("../../util");
|
|
28
|
+
var import_browserContextFactory = require("../browser/browserContextFactory");
|
|
28
29
|
function createCustomMessageHandler(testInfo, context) {
|
|
29
30
|
let backend;
|
|
30
31
|
return async (data) => {
|
|
31
32
|
if (data.initialize) {
|
|
32
33
|
if (backend)
|
|
33
34
|
throw new Error("MCP backend is already initialized");
|
|
34
|
-
backend = new import_browserServerBackend.BrowserServerBackend({ ...import_config.defaultConfig, capabilities: ["testing"] },
|
|
35
|
+
backend = new import_browserServerBackend.BrowserServerBackend({ ...import_config.defaultConfig, capabilities: ["testing"] }, (0, import_browserContextFactory.identityBrowserContextFactory)(context));
|
|
35
36
|
await backend.initialize(data.initialize.clientInfo);
|
|
36
37
|
const pausedMessage = await generatePausedMessage(testInfo, context);
|
|
37
38
|
return { initialize: { pausedMessage } };
|
|
@@ -91,17 +92,6 @@ async function generatePausedMessage(testInfo, context) {
|
|
|
91
92
|
lines.push(`### Task`, `Try recovering from the error prior to continuing`);
|
|
92
93
|
return lines.join("\n");
|
|
93
94
|
}
|
|
94
|
-
function identityFactory(browserContext) {
|
|
95
|
-
return {
|
|
96
|
-
createContext: async (clientInfo, abortSignal, toolName) => {
|
|
97
|
-
return {
|
|
98
|
-
browserContext,
|
|
99
|
-
close: async () => {
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
95
|
// Annotate the CommonJS export names for ESM import in node:
|
|
106
96
|
0 && (module.exports = {
|
|
107
97
|
createCustomMessageHandler
|
|
@@ -39,7 +39,7 @@ var plannerTools = __toESM(require("./plannerTools.js"));
|
|
|
39
39
|
var import_tools = require("../browser/tools");
|
|
40
40
|
var import_bundle = require("../sdk/bundle");
|
|
41
41
|
class TestServerBackend {
|
|
42
|
-
constructor(
|
|
42
|
+
constructor(configPath, options) {
|
|
43
43
|
this.name = "Playwright";
|
|
44
44
|
this.version = "0.0.1";
|
|
45
45
|
this._tools = [
|
|
@@ -55,10 +55,10 @@ class TestServerBackend {
|
|
|
55
55
|
...import_tools.browserTools.map((tool) => wrapBrowserTool(tool))
|
|
56
56
|
];
|
|
57
57
|
this._options = options || {};
|
|
58
|
-
this.
|
|
58
|
+
this._configPath = configPath;
|
|
59
59
|
}
|
|
60
60
|
async initialize(clientInfo) {
|
|
61
|
-
this._context = new import_testContext.TestContext(clientInfo, this.
|
|
61
|
+
this._context = new import_testContext.TestContext(clientInfo, this._configPath, this._options);
|
|
62
62
|
}
|
|
63
63
|
async listTools() {
|
|
64
64
|
return this._tools.map((tool) => mcp.toMcpTool(tool.schema));
|
|
@@ -74,7 +74,7 @@ class TestServerBackend {
|
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
serverClosed() {
|
|
77
|
-
void this._context
|
|
77
|
+
void this._context?.close();
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
const typesWithIntent = ["action", "assertion", "input"];
|