@playwright/mcp 0.0.36-alpha-2025-09-02 → 0.0.36-alpha-2025-09-04
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/README.md +1 -1
- package/cli.js +1 -1
- package/index.d.ts +1 -1
- package/index.js +2 -2
- package/lib/{browserContextFactory.js → browser/browserContextFactory.js} +76 -36
- package/lib/{browserServerBackend.js → browser/browserServerBackend.js} +24 -22
- package/lib/{utils → browser}/codegen.js +8 -3
- package/lib/{config.js → browser/config.js} +43 -26
- package/lib/{context.js → browser/context.js} +27 -30
- package/lib/{response.js → browser/response.js} +14 -14
- package/lib/{sessionLog.js → browser/sessionLog.js} +23 -18
- package/lib/{tab.js → browser/tab.js} +29 -27
- package/lib/{tools → browser/tools}/common.js +11 -9
- package/lib/{tools → browser/tools}/console.js +7 -5
- package/lib/{tools → browser/tools}/dialogs.js +9 -7
- package/lib/browser/tools/evaluate.js +88 -0
- package/lib/{tools → browser/tools}/files.js +8 -6
- package/lib/browser/tools/form.js +92 -0
- package/lib/{tools → browser/tools}/install.js +18 -14
- package/lib/browser/tools/keyboard.js +113 -0
- package/lib/{tools → browser/tools}/mouse.js +18 -16
- package/lib/{tools → browser/tools}/navigate.js +10 -8
- package/lib/{tools → browser/tools}/network.js +7 -5
- package/lib/browser/tools/pdf.js +76 -0
- package/lib/browser/tools/screenshot.js +115 -0
- package/lib/browser/tools/snapshot.js +175 -0
- package/lib/{tools → browser/tools}/tabs.js +9 -7
- package/lib/{tools → browser/tools}/tool.js +6 -2
- package/lib/{tools → browser/tools}/utils.js +10 -5
- package/lib/{tools → browser/tools}/verify.js +59 -24
- package/lib/{tools → browser/tools}/wait.js +10 -8
- package/lib/browser/tools.js +61 -0
- package/lib/extension/cdpRelay.js +85 -48
- package/lib/extension/extensionContextFactory.js +48 -11
- package/lib/extension/protocol.js +4 -1
- package/lib/index.js +47 -12
- package/lib/{utils/log.js → log.js} +11 -4
- package/lib/{utils/package.js → package.js} +9 -5
- package/lib/program.js +68 -39
- package/lib/sdk/bundle.js +79 -0
- package/lib/{mcp → sdk}/http.js +57 -17
- package/lib/{mcp → sdk}/inProcessTransport.js +15 -20
- package/lib/{mcp → sdk}/manualPromise.js +11 -9
- package/lib/{mcp → sdk}/mdb.js +77 -38
- package/lib/{mcp → sdk}/proxyBackend.js +53 -16
- package/lib/sdk/server.js +164 -0
- package/lib/{mcp → sdk}/tool.js +8 -4
- package/lib/vscode/host.js +64 -35
- package/lib/vscode/main.js +48 -13
- package/package.json +6 -7
- package/lib/loop/loop.js +0 -69
- package/lib/loop/loopClaude.js +0 -152
- package/lib/loop/loopOpenAI.js +0 -141
- package/lib/loop/main.js +0 -60
- package/lib/loopTools/context.js +0 -67
- package/lib/loopTools/main.js +0 -54
- package/lib/loopTools/perform.js +0 -32
- package/lib/loopTools/snapshot.js +0 -29
- package/lib/loopTools/tool.js +0 -18
- package/lib/mcp/server.js +0 -123
- package/lib/tools/evaluate.js +0 -53
- package/lib/tools/form.js +0 -57
- package/lib/tools/keyboard.js +0 -78
- package/lib/tools/pdf.js +0 -40
- package/lib/tools/screenshot.js +0 -79
- package/lib/tools/snapshot.js +0 -139
- package/lib/tools.js +0 -54
- package/lib/utils/fileUtils.js +0 -36
- package/lib/utils/guid.js +0 -22
package/lib/program.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* Copyright (c) Microsoft Corporation.
|
|
3
4
|
*
|
|
@@ -13,25 +14,58 @@
|
|
|
13
14
|
* See the License for the specific language governing permissions and
|
|
14
15
|
* limitations under the License.
|
|
15
16
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
17
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
|
+
if (k2 === undefined) k2 = k;
|
|
19
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
20
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
21
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
22
|
+
}
|
|
23
|
+
Object.defineProperty(o, k2, desc);
|
|
24
|
+
}) : (function(o, m, k, k2) {
|
|
25
|
+
if (k2 === undefined) k2 = k;
|
|
26
|
+
o[k2] = m[k];
|
|
27
|
+
}));
|
|
28
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
29
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
30
|
+
}) : function(o, v) {
|
|
31
|
+
o["default"] = v;
|
|
32
|
+
});
|
|
33
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
34
|
+
var ownKeys = function(o) {
|
|
35
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
36
|
+
var ar = [];
|
|
37
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
38
|
+
return ar;
|
|
39
|
+
};
|
|
40
|
+
return ownKeys(o);
|
|
41
|
+
};
|
|
42
|
+
return function (mod) {
|
|
43
|
+
if (mod && mod.__esModule) return mod;
|
|
44
|
+
var result = {};
|
|
45
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
46
|
+
__setModuleDefault(result, mod);
|
|
47
|
+
return result;
|
|
48
|
+
};
|
|
49
|
+
})();
|
|
50
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
51
|
+
const commander_1 = require("commander");
|
|
52
|
+
const mcpServer = __importStar(require("./sdk/server"));
|
|
53
|
+
const config_1 = require("./browser/config");
|
|
54
|
+
const package_1 = require("./package");
|
|
55
|
+
const context_1 = require("./browser/context");
|
|
56
|
+
const browserContextFactory_1 = require("./browser/browserContextFactory");
|
|
57
|
+
const proxyBackend_1 = require("./sdk/proxyBackend");
|
|
58
|
+
const browserServerBackend_1 = require("./browser/browserServerBackend");
|
|
59
|
+
const extensionContextFactory_1 = require("./extension/extensionContextFactory");
|
|
60
|
+
const host_1 = require("./vscode/host");
|
|
61
|
+
commander_1.program
|
|
62
|
+
.version('Version ' + package_1.packageJSON.version)
|
|
63
|
+
.name(package_1.packageJSON.name)
|
|
64
|
+
.option('--allowed-origins <origins>', 'semicolon-separated list of origins to allow the browser to request. Default is to allow all.', config_1.semicolonSeparatedList)
|
|
65
|
+
.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.', config_1.semicolonSeparatedList)
|
|
32
66
|
.option('--block-service-workers', 'block service workers')
|
|
33
67
|
.option('--browser <browser>', 'browser or chrome channel to use, possible values: chrome, firefox, webkit, msedge.')
|
|
34
|
-
.option('--caps <caps>', 'comma-separated list of additional capabilities to enable, possible values: vision, pdf.', commaSeparatedList)
|
|
68
|
+
.option('--caps <caps>', 'comma-separated list of additional capabilities to enable, possible values: vision, pdf.', config_1.commaSeparatedList)
|
|
35
69
|
.option('--cdp-endpoint <endpoint>', 'CDP endpoint to connect to.')
|
|
36
70
|
.option('--config <path>', 'path to the configuration file.')
|
|
37
71
|
.option('--device <device>', 'device to emulate, for example: "iPhone 15"')
|
|
@@ -53,10 +87,9 @@ program
|
|
|
53
87
|
.option('--user-agent <ua string>', 'specify user agent string')
|
|
54
88
|
.option('--user-data-dir <path>', 'path to the user data directory. If not specified, a temporary directory will be created.')
|
|
55
89
|
.option('--viewport-size <size>', 'specify browser viewport size in pixels, for example "1280, 720"')
|
|
56
|
-
.addOption(new Option('--connect-tool', 'Allow to switch between different browser connection methods.').hideHelp())
|
|
57
|
-
.addOption(new Option('--vscode', 'VS Code tools.').hideHelp())
|
|
58
|
-
.addOption(new Option('--
|
|
59
|
-
.addOption(new Option('--vision', 'Legacy option, use --caps=vision instead').hideHelp())
|
|
90
|
+
.addOption(new commander_1.Option('--connect-tool', 'Allow to switch between different browser connection methods.').hideHelp())
|
|
91
|
+
.addOption(new commander_1.Option('--vscode', 'VS Code tools.').hideHelp())
|
|
92
|
+
.addOption(new commander_1.Option('--vision', 'Legacy option, use --caps=vision instead').hideHelp())
|
|
60
93
|
.action(async (options) => {
|
|
61
94
|
setupExitWatchdog();
|
|
62
95
|
if (options.vision) {
|
|
@@ -64,25 +97,21 @@ program
|
|
|
64
97
|
console.error('The --vision option is deprecated, use --caps=vision instead');
|
|
65
98
|
options.caps = 'vision';
|
|
66
99
|
}
|
|
67
|
-
const config = await resolveCLIConfig(options);
|
|
68
|
-
const browserContextFactory = contextFactory(config);
|
|
69
|
-
const extensionContextFactory = new ExtensionContextFactory(config.browser.launchOptions.channel || 'chrome', config.browser.userDataDir, config.browser.launchOptions.executablePath);
|
|
100
|
+
const config = await (0, config_1.resolveCLIConfig)(options);
|
|
101
|
+
const browserContextFactory = (0, browserContextFactory_1.contextFactory)(config);
|
|
102
|
+
const extensionContextFactory = new extensionContextFactory_1.ExtensionContextFactory(config.browser.launchOptions.channel || 'chrome', config.browser.userDataDir, config.browser.launchOptions.executablePath);
|
|
70
103
|
if (options.extension) {
|
|
71
104
|
const serverBackendFactory = {
|
|
72
105
|
name: 'Playwright w/ extension',
|
|
73
106
|
nameInConfig: 'playwright-extension',
|
|
74
|
-
version: packageJSON.version,
|
|
75
|
-
create: () => new BrowserServerBackend(config, extensionContextFactory)
|
|
107
|
+
version: package_1.packageJSON.version,
|
|
108
|
+
create: () => new browserServerBackend_1.BrowserServerBackend(config, extensionContextFactory)
|
|
76
109
|
};
|
|
77
110
|
await mcpServer.start(serverBackendFactory, config.server);
|
|
78
111
|
return;
|
|
79
112
|
}
|
|
80
113
|
if (options.vscode) {
|
|
81
|
-
await runVSCodeTools(config);
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
if (options.loopTools) {
|
|
85
|
-
await runLoopTools(config);
|
|
114
|
+
await (0, host_1.runVSCodeTools)(config);
|
|
86
115
|
return;
|
|
87
116
|
}
|
|
88
117
|
if (options.connectTool) {
|
|
@@ -90,19 +119,19 @@ program
|
|
|
90
119
|
{
|
|
91
120
|
name: 'default',
|
|
92
121
|
description: 'Starts standalone browser',
|
|
93
|
-
connect: () => mcpServer.wrapInProcess(new BrowserServerBackend(config, browserContextFactory)),
|
|
122
|
+
connect: () => mcpServer.wrapInProcess(new browserServerBackend_1.BrowserServerBackend(config, browserContextFactory)),
|
|
94
123
|
},
|
|
95
124
|
{
|
|
96
125
|
name: 'extension',
|
|
97
126
|
description: 'Connect to a browser using the Playwright MCP extension',
|
|
98
|
-
connect: () => mcpServer.wrapInProcess(new BrowserServerBackend(config, extensionContextFactory)),
|
|
127
|
+
connect: () => mcpServer.wrapInProcess(new browserServerBackend_1.BrowserServerBackend(config, extensionContextFactory)),
|
|
99
128
|
},
|
|
100
129
|
];
|
|
101
130
|
const factory = {
|
|
102
131
|
name: 'Playwright w/ switch',
|
|
103
132
|
nameInConfig: 'playwright-switch',
|
|
104
|
-
version: packageJSON.version,
|
|
105
|
-
create: () => new ProxyBackend(providers),
|
|
133
|
+
version: package_1.packageJSON.version,
|
|
134
|
+
create: () => new proxyBackend_1.ProxyBackend(providers),
|
|
106
135
|
};
|
|
107
136
|
await mcpServer.start(factory, config.server);
|
|
108
137
|
return;
|
|
@@ -110,8 +139,8 @@ program
|
|
|
110
139
|
const factory = {
|
|
111
140
|
name: 'Playwright',
|
|
112
141
|
nameInConfig: 'playwright',
|
|
113
|
-
version: packageJSON.version,
|
|
114
|
-
create: () => new BrowserServerBackend(config, browserContextFactory)
|
|
142
|
+
version: package_1.packageJSON.version,
|
|
143
|
+
create: () => new browserServerBackend_1.BrowserServerBackend(config, browserContextFactory)
|
|
115
144
|
};
|
|
116
145
|
await mcpServer.start(factory, config.server);
|
|
117
146
|
});
|
|
@@ -122,11 +151,11 @@ function setupExitWatchdog() {
|
|
|
122
151
|
return;
|
|
123
152
|
isExiting = true;
|
|
124
153
|
setTimeout(() => process.exit(0), 15000);
|
|
125
|
-
await Context.disposeAll();
|
|
154
|
+
await context_1.Context.disposeAll();
|
|
126
155
|
process.exit(0);
|
|
127
156
|
};
|
|
128
157
|
process.stdin.on('close', handleExit);
|
|
129
158
|
process.on('SIGINT', handleExit);
|
|
130
159
|
process.on('SIGTERM', handleExit);
|
|
131
160
|
}
|
|
132
|
-
void program.parseAsync(process.argv);
|
|
161
|
+
void commander_1.program.parseAsync(process.argv);
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Microsoft Corporation.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
|
+
if (k2 === undefined) k2 = k;
|
|
19
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
20
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
21
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
22
|
+
}
|
|
23
|
+
Object.defineProperty(o, k2, desc);
|
|
24
|
+
}) : (function(o, m, k, k2) {
|
|
25
|
+
if (k2 === undefined) k2 = k;
|
|
26
|
+
o[k2] = m[k];
|
|
27
|
+
}));
|
|
28
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
29
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
30
|
+
}) : function(o, v) {
|
|
31
|
+
o["default"] = v;
|
|
32
|
+
});
|
|
33
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
34
|
+
var ownKeys = function(o) {
|
|
35
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
36
|
+
var ar = [];
|
|
37
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
38
|
+
return ar;
|
|
39
|
+
};
|
|
40
|
+
return ownKeys(o);
|
|
41
|
+
};
|
|
42
|
+
return function (mod) {
|
|
43
|
+
if (mod && mod.__esModule) return mod;
|
|
44
|
+
var result = {};
|
|
45
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
46
|
+
__setModuleDefault(result, mod);
|
|
47
|
+
return result;
|
|
48
|
+
};
|
|
49
|
+
})();
|
|
50
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
51
|
+
exports.z = exports.PingRequestSchema = exports.ListToolsRequestSchema = exports.ListRootsRequestSchema = exports.CallToolRequestSchema = exports.StreamableHTTPServerTransport = exports.StreamableHTTPClientTransport = exports.StdioServerTransport = exports.StdioClientTransport = exports.SSEServerTransport = exports.Server = exports.Client = exports.zodToJsonSchema = void 0;
|
|
52
|
+
// @ts-ignore
|
|
53
|
+
const bundle = __importStar(require("playwright/lib/mcpBundleImpl"));
|
|
54
|
+
const zodToJsonSchema = bundle.zodToJsonSchema;
|
|
55
|
+
exports.zodToJsonSchema = zodToJsonSchema;
|
|
56
|
+
const Client = bundle.Client;
|
|
57
|
+
exports.Client = Client;
|
|
58
|
+
const Server = bundle.Server;
|
|
59
|
+
exports.Server = Server;
|
|
60
|
+
const SSEServerTransport = bundle.SSEServerTransport;
|
|
61
|
+
exports.SSEServerTransport = SSEServerTransport;
|
|
62
|
+
const StdioClientTransport = bundle.StdioClientTransport;
|
|
63
|
+
exports.StdioClientTransport = StdioClientTransport;
|
|
64
|
+
const StdioServerTransport = bundle.StdioServerTransport;
|
|
65
|
+
exports.StdioServerTransport = StdioServerTransport;
|
|
66
|
+
const StreamableHTTPServerTransport = bundle.StreamableHTTPServerTransport;
|
|
67
|
+
exports.StreamableHTTPServerTransport = StreamableHTTPServerTransport;
|
|
68
|
+
const StreamableHTTPClientTransport = bundle.StreamableHTTPClientTransport;
|
|
69
|
+
exports.StreamableHTTPClientTransport = StreamableHTTPClientTransport;
|
|
70
|
+
const CallToolRequestSchema = bundle.CallToolRequestSchema;
|
|
71
|
+
exports.CallToolRequestSchema = CallToolRequestSchema;
|
|
72
|
+
const ListRootsRequestSchema = bundle.ListRootsRequestSchema;
|
|
73
|
+
exports.ListRootsRequestSchema = ListRootsRequestSchema;
|
|
74
|
+
const ListToolsRequestSchema = bundle.ListToolsRequestSchema;
|
|
75
|
+
exports.ListToolsRequestSchema = ListToolsRequestSchema;
|
|
76
|
+
const PingRequestSchema = bundle.PingRequestSchema;
|
|
77
|
+
exports.PingRequestSchema = PingRequestSchema;
|
|
78
|
+
const z = bundle.z;
|
|
79
|
+
exports.z = z;
|
package/lib/{mcp → sdk}/http.js
RENAMED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* Copyright (c) Microsoft Corporation.
|
|
3
4
|
*
|
|
@@ -13,21 +14,60 @@
|
|
|
13
14
|
* See the License for the specific language governing permissions and
|
|
14
15
|
* limitations under the License.
|
|
15
16
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
|
+
if (k2 === undefined) k2 = k;
|
|
19
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
20
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
21
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
22
|
+
}
|
|
23
|
+
Object.defineProperty(o, k2, desc);
|
|
24
|
+
}) : (function(o, m, k, k2) {
|
|
25
|
+
if (k2 === undefined) k2 = k;
|
|
26
|
+
o[k2] = m[k];
|
|
27
|
+
}));
|
|
28
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
29
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
30
|
+
}) : function(o, v) {
|
|
31
|
+
o["default"] = v;
|
|
32
|
+
});
|
|
33
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
34
|
+
var ownKeys = function(o) {
|
|
35
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
36
|
+
var ar = [];
|
|
37
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
38
|
+
return ar;
|
|
39
|
+
};
|
|
40
|
+
return ownKeys(o);
|
|
41
|
+
};
|
|
42
|
+
return function (mod) {
|
|
43
|
+
if (mod && mod.__esModule) return mod;
|
|
44
|
+
var result = {};
|
|
45
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
46
|
+
__setModuleDefault(result, mod);
|
|
47
|
+
return result;
|
|
48
|
+
};
|
|
49
|
+
})();
|
|
50
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
51
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
52
|
+
};
|
|
53
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
+
exports.startHttpServer = startHttpServer;
|
|
55
|
+
exports.httpAddressToString = httpAddressToString;
|
|
56
|
+
exports.installHttpTransport = installHttpTransport;
|
|
57
|
+
const assert_1 = __importDefault(require("assert"));
|
|
58
|
+
const http_1 = __importDefault(require("http"));
|
|
59
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
60
|
+
const debug_1 = __importDefault(require("debug"));
|
|
61
|
+
const mcpBundle = __importStar(require("./bundle"));
|
|
62
|
+
const mcpServer = __importStar(require("./server"));
|
|
63
|
+
const testDebug = (0, debug_1.default)('pw:mcp:test');
|
|
64
|
+
async function startHttpServer(config, abortSignal) {
|
|
25
65
|
const { host, port } = config;
|
|
26
|
-
const httpServer =
|
|
66
|
+
const httpServer = http_1.default.createServer();
|
|
27
67
|
decorateServer(httpServer);
|
|
28
68
|
await new Promise((resolve, reject) => {
|
|
29
69
|
httpServer.on('error', reject);
|
|
30
|
-
abortSignal
|
|
70
|
+
abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.addEventListener('abort', () => {
|
|
31
71
|
httpServer.close();
|
|
32
72
|
reject(new Error('Aborted'));
|
|
33
73
|
});
|
|
@@ -38,8 +78,8 @@ export async function startHttpServer(config, abortSignal) {
|
|
|
38
78
|
});
|
|
39
79
|
return httpServer;
|
|
40
80
|
}
|
|
41
|
-
|
|
42
|
-
|
|
81
|
+
function httpAddressToString(address) {
|
|
82
|
+
(0, assert_1.default)(address, 'Could not bind server socket');
|
|
43
83
|
if (typeof address === 'string')
|
|
44
84
|
return address;
|
|
45
85
|
const resolvedPort = address.port;
|
|
@@ -48,7 +88,7 @@ export function httpAddressToString(address) {
|
|
|
48
88
|
resolvedHost = 'localhost';
|
|
49
89
|
return `http://${resolvedHost}:${resolvedPort}`;
|
|
50
90
|
}
|
|
51
|
-
|
|
91
|
+
async function installHttpTransport(httpServer, serverBackendFactory) {
|
|
52
92
|
const sseSessions = new Map();
|
|
53
93
|
const streamableSessions = new Map();
|
|
54
94
|
httpServer.on('request', async (req, res) => {
|
|
@@ -74,7 +114,7 @@ async function handleSSE(serverBackendFactory, req, res, url, sessions) {
|
|
|
74
114
|
return await transport.handlePostMessage(req, res);
|
|
75
115
|
}
|
|
76
116
|
else if (req.method === 'GET') {
|
|
77
|
-
const transport = new SSEServerTransport('/sse', res);
|
|
117
|
+
const transport = new mcpBundle.SSEServerTransport('/sse', res);
|
|
78
118
|
sessions.set(transport.sessionId, transport);
|
|
79
119
|
testDebug(`create SSE session: ${transport.sessionId}`);
|
|
80
120
|
await mcpServer.connect(serverBackendFactory, transport, false);
|
|
@@ -99,8 +139,8 @@ async function handleStreamable(serverBackendFactory, req, res, sessions) {
|
|
|
99
139
|
return await transport.handleRequest(req, res);
|
|
100
140
|
}
|
|
101
141
|
if (req.method === 'POST') {
|
|
102
|
-
const transport = new StreamableHTTPServerTransport({
|
|
103
|
-
sessionIdGenerator: () =>
|
|
142
|
+
const transport = new mcpBundle.StreamableHTTPServerTransport({
|
|
143
|
+
sessionIdGenerator: () => crypto_1.default.randomUUID(),
|
|
104
144
|
onsessioninitialized: async (sessionId) => {
|
|
105
145
|
testDebug(`create http session: ${transport.sessionId}`);
|
|
106
146
|
await mcpServer.connect(serverBackendFactory, transport, true);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* Copyright (c) Microsoft Corporation.
|
|
3
4
|
*
|
|
@@ -13,11 +14,11 @@
|
|
|
13
14
|
* See the License for the specific language governing permissions and
|
|
14
15
|
* limitations under the License.
|
|
15
16
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
_connected = false;
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.InProcessTransport = void 0;
|
|
19
|
+
class InProcessTransport {
|
|
20
20
|
constructor(server) {
|
|
21
|
+
this._connected = false;
|
|
21
22
|
this._server = server;
|
|
22
23
|
this._serverTransport = new InProcessServerTransport(this);
|
|
23
24
|
}
|
|
@@ -33,23 +34,20 @@ export class InProcessTransport {
|
|
|
33
34
|
this._serverTransport._receiveFromClient(message);
|
|
34
35
|
}
|
|
35
36
|
async close() {
|
|
37
|
+
var _a, _b, _c;
|
|
36
38
|
if (this._connected) {
|
|
37
39
|
this._connected = false;
|
|
38
|
-
this.onclose
|
|
39
|
-
this._serverTransport.onclose
|
|
40
|
+
(_a = this.onclose) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
41
|
+
(_c = (_b = this._serverTransport).onclose) === null || _c === void 0 ? void 0 : _c.call(_b);
|
|
40
42
|
}
|
|
41
43
|
}
|
|
42
|
-
onclose;
|
|
43
|
-
onerror;
|
|
44
|
-
onmessage;
|
|
45
|
-
sessionId;
|
|
46
|
-
setProtocolVersion;
|
|
47
44
|
_receiveFromServer(message, extra) {
|
|
48
|
-
|
|
45
|
+
var _a;
|
|
46
|
+
(_a = this.onmessage) === null || _a === void 0 ? void 0 : _a.call(this, message, extra);
|
|
49
47
|
}
|
|
50
48
|
}
|
|
49
|
+
exports.InProcessTransport = InProcessTransport;
|
|
51
50
|
class InProcessServerTransport {
|
|
52
|
-
_clientTransport;
|
|
53
51
|
constructor(clientTransport) {
|
|
54
52
|
this._clientTransport = clientTransport;
|
|
55
53
|
}
|
|
@@ -59,14 +57,11 @@ class InProcessServerTransport {
|
|
|
59
57
|
this._clientTransport._receiveFromServer(message);
|
|
60
58
|
}
|
|
61
59
|
async close() {
|
|
62
|
-
|
|
60
|
+
var _a;
|
|
61
|
+
(_a = this.onclose) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
63
62
|
}
|
|
64
|
-
onclose;
|
|
65
|
-
onerror;
|
|
66
|
-
onmessage;
|
|
67
|
-
sessionId;
|
|
68
|
-
setProtocolVersion;
|
|
69
63
|
_receiveFromClient(message) {
|
|
70
|
-
|
|
64
|
+
var _a;
|
|
65
|
+
(_a = this.onmessage) === null || _a === void 0 ? void 0 : _a.call(this, message);
|
|
71
66
|
}
|
|
72
67
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* Copyright (c) Microsoft Corporation.
|
|
3
4
|
*
|
|
@@ -13,10 +14,9 @@
|
|
|
13
14
|
* See the License for the specific language governing permissions and
|
|
14
15
|
* limitations under the License.
|
|
15
16
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
_isDone;
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.LongStandingScope = exports.ManualPromise = void 0;
|
|
19
|
+
class ManualPromise extends Promise {
|
|
20
20
|
constructor() {
|
|
21
21
|
let resolve;
|
|
22
22
|
let reject;
|
|
@@ -46,11 +46,12 @@ export class ManualPromise extends Promise {
|
|
|
46
46
|
return 'ManualPromise';
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
exports.ManualPromise = ManualPromise;
|
|
50
|
+
class LongStandingScope {
|
|
51
|
+
constructor() {
|
|
52
|
+
this._terminatePromises = new Map();
|
|
53
|
+
this._isClosed = false;
|
|
54
|
+
}
|
|
54
55
|
reject(error) {
|
|
55
56
|
this._isClosed = true;
|
|
56
57
|
this._terminateError = error;
|
|
@@ -94,6 +95,7 @@ export class LongStandingScope {
|
|
|
94
95
|
}
|
|
95
96
|
}
|
|
96
97
|
}
|
|
98
|
+
exports.LongStandingScope = LongStandingScope;
|
|
97
99
|
function cloneError(error, frames) {
|
|
98
100
|
const clone = new Error();
|
|
99
101
|
clone.name = error.name;
|