moltbrowser-mcp-server 1.0.0

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/cli.js ADDED
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env node
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
+
18
+ const { program } = require('playwright-core/lib/utilsBundle');
19
+ const { decorateCommand } = require('playwright/lib/mcp/program');
20
+
21
+ const packageJSON = require('./package.json');
22
+ const p = program.version('Version ' + packageJSON.version).name('Playwright MCP');
23
+ decorateCommand(p, packageJSON.version)
24
+ void program.parseAsync(process.argv);
package/config.d.ts ADDED
@@ -0,0 +1,241 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import type * as playwright from 'playwright';
18
+
19
+ export type ToolCapability =
20
+ 'config' |
21
+ 'core' |
22
+ 'core-navigation' |
23
+ 'core-tabs' |
24
+ 'core-input' |
25
+ 'core-install' |
26
+ 'network' |
27
+ 'pdf' |
28
+ 'storage' |
29
+ 'testing' |
30
+ 'vision' |
31
+ 'devtools';
32
+
33
+ export type Config = {
34
+ /**
35
+ * The browser to use.
36
+ */
37
+ browser?: {
38
+ /**
39
+ * The type of browser to use.
40
+ */
41
+ browserName?: 'chromium' | 'firefox' | 'webkit';
42
+
43
+ /**
44
+ * Keep the browser profile in memory, do not save it to disk.
45
+ */
46
+ isolated?: boolean;
47
+
48
+ /**
49
+ * Path to a user data directory for browser profile persistence.
50
+ * Temporary directory is created by default.
51
+ */
52
+ userDataDir?: string;
53
+
54
+ /**
55
+ * Launch options passed to
56
+ * @see https://playwright.dev/docs/api/class-browsertype#browser-type-launch-persistent-context
57
+ *
58
+ * This is useful for settings options like `channel`, `headless`, `executablePath`, etc.
59
+ */
60
+ launchOptions?: playwright.LaunchOptions;
61
+
62
+ /**
63
+ * Context options for the browser context.
64
+ *
65
+ * This is useful for settings options like `viewport`.
66
+ */
67
+ contextOptions?: playwright.BrowserContextOptions;
68
+
69
+ /**
70
+ * Chrome DevTools Protocol endpoint to connect to an existing browser instance in case of Chromium family browsers.
71
+ */
72
+ cdpEndpoint?: string;
73
+
74
+ /**
75
+ * CDP headers to send with the connect request.
76
+ */
77
+ cdpHeaders?: Record<string, string>;
78
+
79
+ /**
80
+ * Timeout in milliseconds for connecting to CDP endpoint. Defaults to 30000 (30 seconds). Pass 0 to disable timeout.
81
+ */
82
+ cdpTimeout?: number;
83
+
84
+ /**
85
+ * Remote endpoint to connect to an existing Playwright server.
86
+ */
87
+ remoteEndpoint?: string;
88
+
89
+ /**
90
+ * Paths to TypeScript files to add as initialization scripts for Playwright page.
91
+ */
92
+ initPage?: string[];
93
+
94
+ /**
95
+ * Paths to JavaScript files to add as initialization scripts.
96
+ * The scripts will be evaluated in every page before any of the page's scripts.
97
+ */
98
+ initScript?: string[];
99
+ },
100
+
101
+ /**
102
+ * Connect to a running browser instance (Edge/Chrome only). If specified, `browser`
103
+ * config is ignored.
104
+ * Requires the "Playwright MCP Bridge" browser extension to be installed.
105
+ */
106
+ extension?: boolean;
107
+
108
+ server?: {
109
+ /**
110
+ * The port to listen on for SSE or MCP transport.
111
+ */
112
+ port?: number;
113
+
114
+ /**
115
+ * The host to bind the server to. Default is localhost. Use 0.0.0.0 to bind to all interfaces.
116
+ */
117
+ host?: string;
118
+
119
+ /**
120
+ * The hosts this server is allowed to serve from. Defaults to the host server is bound to.
121
+ * This is not for CORS, but rather for the DNS rebinding protection.
122
+ */
123
+ allowedHosts?: string[];
124
+ },
125
+
126
+ /**
127
+ * List of enabled tool capabilities. Possible values:
128
+ * - 'core': Core browser automation features.
129
+ * - 'pdf': PDF generation and manipulation.
130
+ * - 'vision': Coordinate-based interactions.
131
+ * - 'devtools': Developer tools features.
132
+ */
133
+ capabilities?: ToolCapability[];
134
+
135
+ /**
136
+ * Whether to save the Playwright session into the output directory.
137
+ */
138
+ saveSession?: boolean;
139
+
140
+ /**
141
+ * Whether to save the Playwright trace of the session into the output directory.
142
+ */
143
+ saveTrace?: boolean;
144
+
145
+ /**
146
+ * If specified, saves the Playwright video of the session into the output directory.
147
+ */
148
+ saveVideo?: {
149
+ width: number;
150
+ height: number;
151
+ };
152
+
153
+ /**
154
+ * Reuse the same browser context between all connected HTTP clients.
155
+ */
156
+ sharedBrowserContext?: boolean;
157
+
158
+ /**
159
+ * Secrets are used to prevent LLM from getting sensitive data while
160
+ * automating scenarios such as authentication.
161
+ * Prefer the browser.contextOptions.storageState over secrets file as a more secure alternative.
162
+ */
163
+ secrets?: Record<string, string>;
164
+
165
+ /**
166
+ * The directory to save output files.
167
+ */
168
+ outputDir?: string;
169
+
170
+ /**
171
+ * Whether to save snapshots, console messages, network logs and other session logs to a file or to the standard output. Defaults to "stdout".
172
+ */
173
+ outputMode?: 'file' | 'stdout';
174
+
175
+ console?: {
176
+ /**
177
+ * The level of console messages to return. Each level includes the messages of more severe levels. Defaults to "info".
178
+ */
179
+ level?: 'error' | 'warning' | 'info' | 'debug';
180
+ },
181
+
182
+ network?: {
183
+ /**
184
+ * List of origins to allow the browser to request. Default is to allow all. Origins matching both `allowedOrigins` and `blockedOrigins` will be blocked.
185
+ *
186
+ * Supported formats:
187
+ * - Full origin: `https://example.com:8080` - matches only that origin
188
+ * - Wildcard port: `http://localhost:*` - matches any port on localhost with http protocol
189
+ */
190
+ allowedOrigins?: string[];
191
+
192
+ /**
193
+ * List of origins to block the browser to request. Origins matching both `allowedOrigins` and `blockedOrigins` will be blocked.
194
+ *
195
+ * Supported formats:
196
+ * - Full origin: `https://example.com:8080` - matches only that origin
197
+ * - Wildcard port: `http://localhost:*` - matches any port on localhost with http protocol
198
+ */
199
+ blockedOrigins?: string[];
200
+ };
201
+
202
+ /**
203
+ * Specify the attribute to use for test ids, defaults to "data-testid".
204
+ */
205
+ testIdAttribute?: string;
206
+
207
+ timeouts?: {
208
+ /*
209
+ * Configures default action timeout: https://playwright.dev/docs/api/class-page#page-set-default-timeout. Defaults to 5000ms.
210
+ */
211
+ action?: number;
212
+
213
+ /*
214
+ * Configures default navigation timeout: https://playwright.dev/docs/api/class-page#page-set-default-navigation-timeout. Defaults to 60000ms.
215
+ */
216
+ navigation?: number;
217
+ };
218
+
219
+ /**
220
+ * Whether to send image responses to the client. Can be "allow", "omit", or "auto". Defaults to "auto", which sends images if the client can display them.
221
+ */
222
+ imageResponses?: 'allow' | 'omit';
223
+
224
+ snapshot?: {
225
+ /**
226
+ * When taking snapshots for responses, specifies the mode to use.
227
+ */
228
+ mode?: 'incremental' | 'full' | 'none';
229
+ };
230
+
231
+ /**
232
+ * Whether to allow file uploads from anywhere on the file system.
233
+ * By default (false), file uploads are restricted to paths within the MCP roots only.
234
+ */
235
+ allowUnrestrictedFileAccess?: boolean;
236
+
237
+ /**
238
+ * Specify the language to use for code generation.
239
+ */
240
+ codegen?: 'typescript' | 'none';
241
+ };
package/hub-cli.js ADDED
@@ -0,0 +1,72 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Playwright WebMCP Hub — CLI Entry Point
4
+ *
5
+ * Starts the proxy MCP server that wraps upstream Playwright MCP
6
+ * with WebMCP Hub integration for dynamic, per-site tools.
7
+ *
8
+ * Usage:
9
+ * npx moltbrowser-mcp [options]
10
+ *
11
+ * Hub options:
12
+ * --hub-url=<url> Override hub URL (default: https://webmcp-hub.com)
13
+ * --hub-api-key=<key> API key for hub write operations (also HUB_API_KEY env)
14
+ * --no-hub Disable hub integration (behaves as vanilla Playwright MCP)
15
+ *
16
+ * All standard Playwright MCP options are also supported and passed through:
17
+ * --browser=<name> Browser to use (chromium, firefox, webkit, chrome, msedge)
18
+ * --headless Run in headless mode
19
+ * --caps=<list> Comma-separated list of capabilities
20
+ * --config=<path> Path to config JSON file
21
+ * --port=<number> Port for SSE transport
22
+ * --host=<host> Host for SSE transport
23
+ * etc.
24
+ */
25
+
26
+ const { startProxy } = require('./src/proxy-server.js');
27
+ const hubClient = require('./src/hub-client.js');
28
+
29
+ // Parse our custom args, pass the rest through to upstream
30
+ const args = process.argv.slice(2);
31
+
32
+ let noHub = false;
33
+ const upstreamArgs = [];
34
+
35
+ for (const arg of args) {
36
+ if (arg === '--no-hub') {
37
+ noHub = true;
38
+ } else if (arg.startsWith('--hub-url=')) {
39
+ process.env.HUB_URL = arg.split('=').slice(1).join('=');
40
+ } else if (arg.startsWith('--hub-api-key=')) {
41
+ process.env.HUB_API_KEY = arg.split('=').slice(1).join('=');
42
+ } else {
43
+ // Pass through to upstream Playwright MCP
44
+ upstreamArgs.push(arg);
45
+ }
46
+ }
47
+
48
+ (async () => {
49
+ let keyWarning = null;
50
+
51
+ if (!noHub) {
52
+ if (!process.env.HUB_API_KEY) {
53
+ keyWarning = 'No HUB_API_KEY is configured. Contribution and reading your own configs and tools will fail until you add one. Get a free API key at https://www.webmcp-hub.com and add it to your MCP config.';
54
+ process.stderr.write(`[moltbrowser-mcp] Warning: ${keyWarning}\n`);
55
+ } else {
56
+ const verification = await hubClient.verifyApiKey();
57
+ if (verification.unreachable) {
58
+ process.stderr.write('[moltbrowser-mcp] Warning: Hub unreachable, could not verify API key. Proceeding anyway.\n');
59
+ } else if (!verification.valid) {
60
+ keyWarning = `Your HUB_API_KEY is invalid or expired (${verification.error}). Contribution and reading your own configs and tools will fail until you fix it. Check or regenerate your key at https://www.webmcp-hub.com.`;
61
+ process.stderr.write(`[moltbrowser-mcp] Warning: ${keyWarning}\n`);
62
+ } else {
63
+ process.stderr.write(`[moltbrowser-mcp] Authenticated as ${verification.username}.\n`);
64
+ }
65
+ }
66
+ }
67
+
68
+ await startProxy({ upstreamArgs, noHub, keyWarning });
69
+ })().catch(err => {
70
+ process.stderr.write(`[moltbrowser-mcp] Fatal error: ${err.message}\n${err.stack}\n`);
71
+ process.exit(1);
72
+ });
package/index.d.ts ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env node
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
+
18
+ import type { Server } from '@modelcontextprotocol/sdk/server/index.js';
19
+ import type { Config } from './config';
20
+ import type { BrowserContext } from 'playwright';
21
+
22
+ export declare function createConnection(config?: Config, contextGetter?: () => Promise<BrowserContext>): Promise<Server>;
23
+ export {};
package/index.js ADDED
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env node
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
+
18
+ const { createConnection } = require('playwright/lib/mcp/index');
19
+ module.exports = { createConnection };
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "moltbrowser-mcp-server",
3
+ "version": "1.0.0",
4
+ "description": "Playwright MCP with WebMCP Hub integration — dynamic, per-site tools for browser agents",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/Joakim-Sael/moltbrowser-mcp.git"
8
+ },
9
+ "homepage": "https://webmcp-hub.com",
10
+ "engines": {
11
+ "node": ">=18"
12
+ },
13
+ "author": {
14
+ "name": "Joakim Saelemyr"
15
+ },
16
+ "license": "Apache-2.0",
17
+ "files": [
18
+ "index.js",
19
+ "index.d.ts",
20
+ "config.d.ts",
21
+ "cli.js",
22
+ "hub-cli.js",
23
+ "src/**/*.js",
24
+ "README.md",
25
+ "LICENSE"
26
+ ],
27
+ "scripts": {
28
+ "lint": "node update-readme.js",
29
+ "test": "playwright test",
30
+ "ctest": "playwright test --project=chrome",
31
+ "ftest": "playwright test --project=firefox",
32
+ "wtest": "playwright test --project=webkit",
33
+ "build": "echo OK",
34
+ "npm-publish": "npm run lint && npm run test && npm publish"
35
+ },
36
+ "exports": {
37
+ "./package.json": "./package.json",
38
+ ".": {
39
+ "types": "./index.d.ts",
40
+ "default": "./index.js"
41
+ }
42
+ },
43
+ "dependencies": {
44
+ "@modelcontextprotocol/sdk": "^1.26.0",
45
+ "playwright": "^1.58.2",
46
+ "playwright-core": "^1.58.2"
47
+ },
48
+ "bin": {
49
+ "playwright-mcp": "cli.js",
50
+ "moltbrowser-mcp": "hub-cli.js"
51
+ }
52
+ }