@cotestdev/mcp_playwright 0.0.2 → 0.0.4
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/cli.d.ts +8 -0
- package/lib/cli.d.ts.map +1 -0
- package/lib/cli.js +11 -0
- package/lib/cli.js.map +1 -0
- package/lib/index.d.ts +4 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +27 -4
- package/lib/index.js.map +1 -1
- package/lib/mcp/browser/actions.d.js +16 -0
- package/lib/mcp/browser/browserContextFactory.js +285 -0
- package/lib/mcp/browser/browserServerBackend.js +74 -0
- package/lib/mcp/browser/codegen.js +66 -0
- package/lib/mcp/browser/config.js +346 -0
- package/lib/mcp/browser/context.js +260 -0
- package/lib/mcp/browser/processUtils.js +102 -0
- package/lib/mcp/browser/response.js +169 -0
- package/lib/mcp/browser/sessionLog.js +160 -0
- package/lib/mcp/browser/tab.js +301 -0
- package/lib/mcp/browser/tools/common.js +71 -0
- package/lib/mcp/browser/tools/console.js +41 -0
- package/lib/mcp/browser/tools/dialogs.js +61 -0
- package/lib/mcp/browser/tools/evaluate.js +71 -0
- package/lib/mcp/browser/tools/files.js +54 -0
- package/lib/mcp/browser/tools/form.js +75 -0
- package/lib/mcp/browser/tools/install.js +69 -0
- package/lib/mcp/browser/tools/keyboard.js +85 -0
- package/lib/mcp/browser/tools/mouse.js +107 -0
- package/lib/mcp/browser/tools/navigate.js +63 -0
- package/lib/mcp/browser/tools/network.js +49 -0
- package/lib/mcp/browser/tools/pdf.js +59 -0
- package/lib/mcp/browser/tools/screenshot.js +95 -0
- package/lib/mcp/browser/tools/script.js +60 -0
- package/lib/mcp/browser/tools/snapshot.js +183 -0
- package/lib/mcp/browser/tools/tabs.js +71 -0
- package/lib/mcp/browser/tools/tool.js +49 -0
- package/lib/mcp/browser/tools/tracing.js +74 -0
- package/lib/mcp/browser/tools/utils.js +96 -0
- package/lib/mcp/browser/tools/verify.js +155 -0
- package/lib/mcp/browser/tools/wait.js +64 -0
- package/lib/mcp/browser/tools.js +79 -0
- package/lib/mcp/browser/watchdog.js +44 -0
- package/lib/mcp/sdk/bundle.js +75 -0
- package/lib/mcp/sdk/exports.js +32 -0
- package/lib/mcp/sdk/http.js +165 -0
- package/lib/mcp/sdk/inProcessTransport.js +71 -0
- package/lib/mcp/sdk/mdb.js +208 -0
- package/lib/mcp/sdk/proxyBackend.js +128 -0
- package/lib/mcp/sdk/server.js +155 -0
- package/lib/mcp/sdk/tool.js +46 -0
- package/lib/server.d.ts +8 -0
- package/lib/server.d.ts.map +1 -0
- package/lib/server.js +27 -0
- package/lib/server.js.map +1 -0
- package/package.json +10 -4
|
@@ -0,0 +1,64 @@
|
|
|
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 wait_exports = {};
|
|
20
|
+
__export(wait_exports, {
|
|
21
|
+
default: () => wait_default
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(wait_exports);
|
|
24
|
+
var import_bundle = require("../../sdk/bundle");
|
|
25
|
+
var import_common = require("./common");
|
|
26
|
+
var import_tool = require("./tool");
|
|
27
|
+
const wait = (0, import_tool.defineTool)({
|
|
28
|
+
capability: "core",
|
|
29
|
+
schema: {
|
|
30
|
+
name: "browser_wait_for",
|
|
31
|
+
title: "Wait for",
|
|
32
|
+
description: "Wait for text to appear or disappear or a specified time to pass",
|
|
33
|
+
inputSchema: import_common.baseSchema.extend({
|
|
34
|
+
time: import_bundle.z.number().optional().describe("The time to wait in seconds"),
|
|
35
|
+
text: import_bundle.z.string().optional().describe("The text to wait for"),
|
|
36
|
+
textGone: import_bundle.z.string().optional().describe("The text to wait for to disappear")
|
|
37
|
+
}),
|
|
38
|
+
type: "readOnly"
|
|
39
|
+
},
|
|
40
|
+
handle: async (context, params, response) => {
|
|
41
|
+
if (!params.text && !params.textGone && !params.time)
|
|
42
|
+
throw new Error("Either time, text or textGone must be provided");
|
|
43
|
+
if (params.time) {
|
|
44
|
+
response.addCode(`await new Promise(f => setTimeout(f, ${params.time} * 1000));`);
|
|
45
|
+
await new Promise((f) => setTimeout(f, Math.min(3e4, params.time * 1e3)));
|
|
46
|
+
}
|
|
47
|
+
const tab = context.currentTabOrDie();
|
|
48
|
+
const locator = params.text ? tab.page.getByText(params.text).first() : void 0;
|
|
49
|
+
const goneLocator = params.textGone ? tab.page.getByText(params.textGone).first() : void 0;
|
|
50
|
+
if (goneLocator) {
|
|
51
|
+
response.addCode(`await page.getByText(${JSON.stringify(params.textGone)}).first().waitFor({ state: 'hidden' });`);
|
|
52
|
+
await goneLocator.waitFor({ state: "hidden" });
|
|
53
|
+
}
|
|
54
|
+
if (locator) {
|
|
55
|
+
response.addCode(`await page.getByText(${JSON.stringify(params.text)}).first().waitFor({ state: 'visible' });`);
|
|
56
|
+
await locator.waitFor({ state: "visible" });
|
|
57
|
+
}
|
|
58
|
+
response.addResult(`Waited for ${params.text || params.textGone || params.time}`);
|
|
59
|
+
response.setIncludeSnapshot();
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
var wait_default = [
|
|
63
|
+
wait
|
|
64
|
+
];
|
|
@@ -0,0 +1,79 @@
|
|
|
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 __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
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
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var tools_exports = {};
|
|
30
|
+
__export(tools_exports, {
|
|
31
|
+
browserTools: () => browserTools,
|
|
32
|
+
filteredTools: () => filteredTools
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(tools_exports);
|
|
35
|
+
var import_common = __toESM(require("./tools/common"));
|
|
36
|
+
var import_dialogs = __toESM(require("./tools/dialogs"));
|
|
37
|
+
var import_evaluate = __toESM(require("./tools/evaluate"));
|
|
38
|
+
var import_files = __toESM(require("./tools/files"));
|
|
39
|
+
var import_form = __toESM(require("./tools/form"));
|
|
40
|
+
var import_keyboard = __toESM(require("./tools/keyboard"));
|
|
41
|
+
var import_mouse = __toESM(require("./tools/mouse"));
|
|
42
|
+
var import_navigate = __toESM(require("./tools/navigate"));
|
|
43
|
+
var import_pdf = __toESM(require("./tools/pdf"));
|
|
44
|
+
var import_snapshot = __toESM(require("./tools/snapshot"));
|
|
45
|
+
var import_screenshot = __toESM(require("./tools/screenshot"));
|
|
46
|
+
var import_script = __toESM(require("./tools/script"));
|
|
47
|
+
var import_tabs = __toESM(require("./tools/tabs"));
|
|
48
|
+
var import_tracing = __toESM(require("./tools/tracing"));
|
|
49
|
+
var import_wait = __toESM(require("./tools/wait"));
|
|
50
|
+
var import_verify = __toESM(require("./tools/verify"));
|
|
51
|
+
const browserTools = [
|
|
52
|
+
...import_common.default,
|
|
53
|
+
// ...console,
|
|
54
|
+
...import_dialogs.default,
|
|
55
|
+
...import_evaluate.default,
|
|
56
|
+
...import_files.default,
|
|
57
|
+
...import_form.default,
|
|
58
|
+
// ...install,
|
|
59
|
+
...import_keyboard.default,
|
|
60
|
+
...import_navigate.default,
|
|
61
|
+
// ...network,
|
|
62
|
+
...import_mouse.default,
|
|
63
|
+
...import_pdf.default,
|
|
64
|
+
...import_screenshot.default,
|
|
65
|
+
...import_snapshot.default,
|
|
66
|
+
...import_script.default,
|
|
67
|
+
...import_tabs.default,
|
|
68
|
+
...import_tracing.default,
|
|
69
|
+
...import_wait.default,
|
|
70
|
+
...import_verify.default
|
|
71
|
+
];
|
|
72
|
+
function filteredTools(config) {
|
|
73
|
+
return browserTools.filter((tool) => tool.capability.startsWith("core") || tool.capability === "testing" || config.capabilities?.includes(tool.capability));
|
|
74
|
+
}
|
|
75
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
76
|
+
0 && (module.exports = {
|
|
77
|
+
browserTools,
|
|
78
|
+
filteredTools
|
|
79
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
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 watchdog_exports = {};
|
|
20
|
+
__export(watchdog_exports, {
|
|
21
|
+
setupExitWatchdog: () => setupExitWatchdog
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(watchdog_exports);
|
|
24
|
+
var import_browserContextFactory = require("./browserContextFactory");
|
|
25
|
+
var import_context = require("./context");
|
|
26
|
+
function setupExitWatchdog() {
|
|
27
|
+
let isExiting = false;
|
|
28
|
+
const handleExit = async () => {
|
|
29
|
+
if (isExiting)
|
|
30
|
+
return;
|
|
31
|
+
isExiting = true;
|
|
32
|
+
setTimeout(() => process.exit(0), 15e3);
|
|
33
|
+
await import_context.Context.disposeAll();
|
|
34
|
+
await import_browserContextFactory.SharedContextFactory.dispose();
|
|
35
|
+
process.exit(0);
|
|
36
|
+
};
|
|
37
|
+
process.stdin.on("close", handleExit);
|
|
38
|
+
process.on("SIGINT", handleExit);
|
|
39
|
+
process.on("SIGTERM", handleExit);
|
|
40
|
+
}
|
|
41
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
42
|
+
0 && (module.exports = {
|
|
43
|
+
setupExitWatchdog
|
|
44
|
+
});
|
|
@@ -0,0 +1,75 @@
|
|
|
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 __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
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
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var bundle_exports = {};
|
|
30
|
+
__export(bundle_exports, {
|
|
31
|
+
CallToolRequestSchema: () => CallToolRequestSchema,
|
|
32
|
+
Client: () => Client,
|
|
33
|
+
ListRootsRequestSchema: () => ListRootsRequestSchema,
|
|
34
|
+
ListToolsRequestSchema: () => ListToolsRequestSchema,
|
|
35
|
+
PingRequestSchema: () => PingRequestSchema,
|
|
36
|
+
SSEServerTransport: () => SSEServerTransport,
|
|
37
|
+
Server: () => Server,
|
|
38
|
+
StdioClientTransport: () => StdioClientTransport,
|
|
39
|
+
StdioServerTransport: () => StdioServerTransport,
|
|
40
|
+
StreamableHTTPClientTransport: () => StreamableHTTPClientTransport,
|
|
41
|
+
StreamableHTTPServerTransport: () => StreamableHTTPServerTransport,
|
|
42
|
+
z: () => z,
|
|
43
|
+
zodToJsonSchema: () => zodToJsonSchema
|
|
44
|
+
});
|
|
45
|
+
module.exports = __toCommonJS(bundle_exports);
|
|
46
|
+
var bundle = __toESM(require("../../mcpBundleImpl"));
|
|
47
|
+
const zodToJsonSchema = bundle.zodToJsonSchema;
|
|
48
|
+
const Client = bundle.Client;
|
|
49
|
+
const Server = bundle.Server;
|
|
50
|
+
const SSEServerTransport = bundle.SSEServerTransport;
|
|
51
|
+
const StdioClientTransport = bundle.StdioClientTransport;
|
|
52
|
+
const StdioServerTransport = bundle.StdioServerTransport;
|
|
53
|
+
const StreamableHTTPServerTransport = bundle.StreamableHTTPServerTransport;
|
|
54
|
+
const StreamableHTTPClientTransport = bundle.StreamableHTTPClientTransport;
|
|
55
|
+
const CallToolRequestSchema = bundle.CallToolRequestSchema;
|
|
56
|
+
const ListRootsRequestSchema = bundle.ListRootsRequestSchema;
|
|
57
|
+
const ListToolsRequestSchema = bundle.ListToolsRequestSchema;
|
|
58
|
+
const PingRequestSchema = bundle.PingRequestSchema;
|
|
59
|
+
const z = bundle.z;
|
|
60
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
61
|
+
0 && (module.exports = {
|
|
62
|
+
CallToolRequestSchema,
|
|
63
|
+
Client,
|
|
64
|
+
ListRootsRequestSchema,
|
|
65
|
+
ListToolsRequestSchema,
|
|
66
|
+
PingRequestSchema,
|
|
67
|
+
SSEServerTransport,
|
|
68
|
+
Server,
|
|
69
|
+
StdioClientTransport,
|
|
70
|
+
StdioServerTransport,
|
|
71
|
+
StreamableHTTPClientTransport,
|
|
72
|
+
StreamableHTTPServerTransport,
|
|
73
|
+
z,
|
|
74
|
+
zodToJsonSchema
|
|
75
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var exports_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(exports_exports);
|
|
18
|
+
__reExport(exports_exports, require("./inProcessTransport"), module.exports);
|
|
19
|
+
__reExport(exports_exports, require("./proxyBackend"), module.exports);
|
|
20
|
+
__reExport(exports_exports, require("./server"), module.exports);
|
|
21
|
+
__reExport(exports_exports, require("./tool"), module.exports);
|
|
22
|
+
__reExport(exports_exports, require("./http"), module.exports);
|
|
23
|
+
__reExport(exports_exports, require("./mdb"), module.exports);
|
|
24
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
25
|
+
0 && (module.exports = {
|
|
26
|
+
...require("./inProcessTransport"),
|
|
27
|
+
...require("./proxyBackend"),
|
|
28
|
+
...require("./server"),
|
|
29
|
+
...require("./tool"),
|
|
30
|
+
...require("./http"),
|
|
31
|
+
...require("./mdb")
|
|
32
|
+
});
|
|
@@ -0,0 +1,165 @@
|
|
|
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 __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
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
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var http_exports = {};
|
|
30
|
+
__export(http_exports, {
|
|
31
|
+
httpAddressToString: () => httpAddressToString,
|
|
32
|
+
installHttpTransport: () => installHttpTransport,
|
|
33
|
+
startHttpServer: () => startHttpServer
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(http_exports);
|
|
36
|
+
var import_assert = __toESM(require("assert"));
|
|
37
|
+
var import_http = __toESM(require("http"));
|
|
38
|
+
var import_crypto = __toESM(require("crypto"));
|
|
39
|
+
var import_utilsBundle = require("playwright-core/lib/utilsBundle");
|
|
40
|
+
var mcpBundle = __toESM(require("./bundle"));
|
|
41
|
+
var mcpServer = __toESM(require("./server"));
|
|
42
|
+
const testDebug = (0, import_utilsBundle.debug)("pw:mcp:test");
|
|
43
|
+
async function startHttpServer(config, abortSignal) {
|
|
44
|
+
const { host, port } = config;
|
|
45
|
+
const httpServer = import_http.default.createServer();
|
|
46
|
+
decorateServer(httpServer);
|
|
47
|
+
await new Promise((resolve, reject) => {
|
|
48
|
+
httpServer.on("error", reject);
|
|
49
|
+
abortSignal?.addEventListener("abort", () => {
|
|
50
|
+
httpServer.close();
|
|
51
|
+
reject(new Error("Aborted"));
|
|
52
|
+
});
|
|
53
|
+
httpServer.listen(port, host, () => {
|
|
54
|
+
resolve();
|
|
55
|
+
httpServer.removeListener("error", reject);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
return httpServer;
|
|
59
|
+
}
|
|
60
|
+
function httpAddressToString(address) {
|
|
61
|
+
(0, import_assert.default)(address, "Could not bind server socket");
|
|
62
|
+
if (typeof address === "string")
|
|
63
|
+
return address;
|
|
64
|
+
const resolvedPort = address.port;
|
|
65
|
+
let resolvedHost = address.family === "IPv4" ? address.address : `[${address.address}]`;
|
|
66
|
+
if (resolvedHost === "0.0.0.0" || resolvedHost === "[::]")
|
|
67
|
+
resolvedHost = "localhost";
|
|
68
|
+
return `http://${resolvedHost}:${resolvedPort}`;
|
|
69
|
+
}
|
|
70
|
+
async function installHttpTransport(httpServer, serverBackendFactory) {
|
|
71
|
+
const sseSessions = /* @__PURE__ */ new Map();
|
|
72
|
+
const streamableSessions = /* @__PURE__ */ new Map();
|
|
73
|
+
httpServer.on("request", async (req, res) => {
|
|
74
|
+
const url = new URL(`http://localhost${req.url}`);
|
|
75
|
+
if (url.pathname === "/killkillkill" && req.method === "GET") {
|
|
76
|
+
res.statusCode = 200;
|
|
77
|
+
res.end("Killing process");
|
|
78
|
+
process.emit("SIGINT");
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (url.pathname.startsWith("/sse"))
|
|
82
|
+
await handleSSE(serverBackendFactory, req, res, url, sseSessions);
|
|
83
|
+
else
|
|
84
|
+
await handleStreamable(serverBackendFactory, req, res, streamableSessions);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
async function handleSSE(serverBackendFactory, req, res, url, sessions) {
|
|
88
|
+
if (req.method === "POST") {
|
|
89
|
+
const sessionId = url.searchParams.get("sessionId");
|
|
90
|
+
if (!sessionId) {
|
|
91
|
+
res.statusCode = 400;
|
|
92
|
+
return res.end("Missing sessionId");
|
|
93
|
+
}
|
|
94
|
+
const transport = sessions.get(sessionId);
|
|
95
|
+
if (!transport) {
|
|
96
|
+
res.statusCode = 404;
|
|
97
|
+
return res.end("Session not found");
|
|
98
|
+
}
|
|
99
|
+
return await transport.handlePostMessage(req, res);
|
|
100
|
+
} else if (req.method === "GET") {
|
|
101
|
+
const transport = new mcpBundle.SSEServerTransport("/sse", res);
|
|
102
|
+
sessions.set(transport.sessionId, transport);
|
|
103
|
+
testDebug(`create SSE session: ${transport.sessionId}`);
|
|
104
|
+
await mcpServer.connect(serverBackendFactory, transport, false);
|
|
105
|
+
res.on("close", () => {
|
|
106
|
+
testDebug(`delete SSE session: ${transport.sessionId}`);
|
|
107
|
+
sessions.delete(transport.sessionId);
|
|
108
|
+
});
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
res.statusCode = 405;
|
|
112
|
+
res.end("Method not allowed");
|
|
113
|
+
}
|
|
114
|
+
async function handleStreamable(serverBackendFactory, req, res, sessions) {
|
|
115
|
+
const sessionId = req.headers["mcp-session-id"];
|
|
116
|
+
if (sessionId) {
|
|
117
|
+
const transport = sessions.get(sessionId);
|
|
118
|
+
if (!transport) {
|
|
119
|
+
res.statusCode = 404;
|
|
120
|
+
res.end("Session not found");
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
return await transport.handleRequest(req, res);
|
|
124
|
+
}
|
|
125
|
+
if (req.method === "POST") {
|
|
126
|
+
const transport = new mcpBundle.StreamableHTTPServerTransport({
|
|
127
|
+
sessionIdGenerator: () => import_crypto.default.randomUUID(),
|
|
128
|
+
onsessioninitialized: async (sessionId2) => {
|
|
129
|
+
testDebug(`create http session: ${transport.sessionId}`);
|
|
130
|
+
await mcpServer.connect(serverBackendFactory, transport, true);
|
|
131
|
+
sessions.set(sessionId2, transport);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
transport.onclose = () => {
|
|
135
|
+
if (!transport.sessionId)
|
|
136
|
+
return;
|
|
137
|
+
sessions.delete(transport.sessionId);
|
|
138
|
+
testDebug(`delete http session: ${transport.sessionId}`);
|
|
139
|
+
};
|
|
140
|
+
await transport.handleRequest(req, res);
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
res.statusCode = 400;
|
|
144
|
+
res.end("Invalid request");
|
|
145
|
+
}
|
|
146
|
+
function decorateServer(server) {
|
|
147
|
+
const sockets = /* @__PURE__ */ new Set();
|
|
148
|
+
server.on("connection", (socket) => {
|
|
149
|
+
sockets.add(socket);
|
|
150
|
+
socket.once("close", () => sockets.delete(socket));
|
|
151
|
+
});
|
|
152
|
+
const close = server.close;
|
|
153
|
+
server.close = (callback) => {
|
|
154
|
+
for (const socket of sockets)
|
|
155
|
+
socket.destroy();
|
|
156
|
+
sockets.clear();
|
|
157
|
+
return close.call(server, callback);
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
161
|
+
0 && (module.exports = {
|
|
162
|
+
httpAddressToString,
|
|
163
|
+
installHttpTransport,
|
|
164
|
+
startHttpServer
|
|
165
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
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 inProcessTransport_exports = {};
|
|
20
|
+
__export(inProcessTransport_exports, {
|
|
21
|
+
InProcessTransport: () => InProcessTransport
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(inProcessTransport_exports);
|
|
24
|
+
class InProcessTransport {
|
|
25
|
+
constructor(server) {
|
|
26
|
+
this._connected = false;
|
|
27
|
+
this._server = server;
|
|
28
|
+
this._serverTransport = new InProcessServerTransport(this);
|
|
29
|
+
}
|
|
30
|
+
async start() {
|
|
31
|
+
if (this._connected)
|
|
32
|
+
throw new Error("InprocessTransport already started!");
|
|
33
|
+
await this._server.connect(this._serverTransport);
|
|
34
|
+
this._connected = true;
|
|
35
|
+
}
|
|
36
|
+
async send(message, options) {
|
|
37
|
+
if (!this._connected)
|
|
38
|
+
throw new Error("Transport not connected");
|
|
39
|
+
this._serverTransport._receiveFromClient(message);
|
|
40
|
+
}
|
|
41
|
+
async close() {
|
|
42
|
+
if (this._connected) {
|
|
43
|
+
this._connected = false;
|
|
44
|
+
this.onclose?.();
|
|
45
|
+
this._serverTransport.onclose?.();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
_receiveFromServer(message, extra) {
|
|
49
|
+
this.onmessage?.(message, extra);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
class InProcessServerTransport {
|
|
53
|
+
constructor(clientTransport) {
|
|
54
|
+
this._clientTransport = clientTransport;
|
|
55
|
+
}
|
|
56
|
+
async start() {
|
|
57
|
+
}
|
|
58
|
+
async send(message, options) {
|
|
59
|
+
this._clientTransport._receiveFromServer(message);
|
|
60
|
+
}
|
|
61
|
+
async close() {
|
|
62
|
+
this.onclose?.();
|
|
63
|
+
}
|
|
64
|
+
_receiveFromClient(message) {
|
|
65
|
+
this.onmessage?.(message);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
69
|
+
0 && (module.exports = {
|
|
70
|
+
InProcessTransport
|
|
71
|
+
});
|