@playwright/mcp 0.0.31 → 0.0.32

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.
Files changed (49) hide show
  1. package/README.md +25 -4
  2. package/config.d.ts +5 -0
  3. package/index.d.ts +1 -6
  4. package/lib/browserServerBackend.js +54 -0
  5. package/lib/config.js +2 -1
  6. package/lib/context.js +48 -171
  7. package/lib/extension/cdpRelay.js +370 -0
  8. package/lib/extension/main.js +33 -0
  9. package/lib/httpServer.js +20 -182
  10. package/lib/index.js +3 -2
  11. package/lib/loop/loop.js +69 -0
  12. package/lib/loop/loopClaude.js +152 -0
  13. package/lib/loop/loopOpenAI.js +141 -0
  14. package/lib/loop/main.js +60 -0
  15. package/lib/loopTools/context.js +66 -0
  16. package/lib/loopTools/main.js +49 -0
  17. package/lib/loopTools/perform.js +32 -0
  18. package/lib/loopTools/snapshot.js +29 -0
  19. package/lib/loopTools/tool.js +18 -0
  20. package/lib/mcp/inProcessTransport.js +72 -0
  21. package/lib/mcp/server.js +88 -0
  22. package/lib/{transport.js → mcp/transport.js} +30 -42
  23. package/lib/package.js +3 -3
  24. package/lib/program.js +38 -9
  25. package/lib/response.js +98 -0
  26. package/lib/sessionLog.js +70 -0
  27. package/lib/tab.js +133 -22
  28. package/lib/tools/common.js +11 -23
  29. package/lib/tools/console.js +4 -15
  30. package/lib/tools/dialogs.js +12 -17
  31. package/lib/tools/evaluate.js +12 -21
  32. package/lib/tools/files.js +10 -16
  33. package/lib/tools/install.js +3 -7
  34. package/lib/tools/keyboard.js +30 -42
  35. package/lib/tools/mouse.js +27 -50
  36. package/lib/tools/navigate.js +15 -35
  37. package/lib/tools/network.js +5 -15
  38. package/lib/tools/pdf.js +8 -15
  39. package/lib/tools/screenshot.js +29 -30
  40. package/lib/tools/snapshot.js +45 -65
  41. package/lib/tools/tabs.js +10 -41
  42. package/lib/tools/tool.js +14 -0
  43. package/lib/tools/utils.js +2 -2
  44. package/lib/tools/wait.js +3 -6
  45. package/lib/tools.js +3 -0
  46. package/package.json +9 -3
  47. package/lib/connection.js +0 -81
  48. package/lib/pageSnapshot.js +0 -43
  49. package/lib/server.js +0 -48
package/lib/tools/wait.js CHANGED
@@ -28,7 +28,7 @@ const wait = defineTool({
28
28
  }),
29
29
  type: 'readOnly',
30
30
  },
31
- handle: async (context, params) => {
31
+ handle: async (context, params, response) => {
32
32
  if (!params.text && !params.textGone && !params.time)
33
33
  throw new Error('Either time, text or textGone must be provided');
34
34
  const code = [];
@@ -47,11 +47,8 @@ const wait = defineTool({
47
47
  code.push(`await page.getByText(${JSON.stringify(params.text)}).first().waitFor({ state: 'visible' });`);
48
48
  await locator.waitFor({ state: 'visible' });
49
49
  }
50
- return {
51
- code,
52
- captureSnapshot: true,
53
- waitForNetwork: false,
54
- };
50
+ response.addResult(`Waited for ${params.text || params.textGone || params.time}`);
51
+ response.setIncludeSnapshot();
55
52
  },
56
53
  });
57
54
  export default [
package/lib/tools.js CHANGED
@@ -45,3 +45,6 @@ export const allTools = [
45
45
  ...tabs,
46
46
  ...wait,
47
47
  ];
48
+ export function filteredTools(config) {
49
+ return allTools.filter(tool => tool.capability.startsWith('core') || config.capabilities?.includes(tool.capability));
50
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@playwright/mcp",
3
- "version": "0.0.31",
3
+ "version": "0.0.32",
4
4
  "description": "Playwright Tools for MCP",
5
5
  "type": "module",
6
6
  "repository": {
@@ -17,15 +17,18 @@
17
17
  "license": "Apache-2.0",
18
18
  "scripts": {
19
19
  "build": "tsc",
20
+ "build:extension": "tsc --project extension",
20
21
  "lint": "npm run update-readme && eslint . && tsc --noEmit",
22
+ "lint-fix": "eslint . --fix",
21
23
  "update-readme": "node utils/update-readme.js",
22
24
  "watch": "tsc --watch",
25
+ "watch:extension": "tsc --watch --project extension",
23
26
  "test": "playwright test",
24
27
  "ctest": "playwright test --project=chrome",
25
28
  "ftest": "playwright test --project=firefox",
26
29
  "wtest": "playwright test --project=webkit",
27
30
  "run-server": "node lib/browserServer.js",
28
- "clean": "rm -rf lib",
31
+ "clean": "rm -rf lib extension/lib",
29
32
  "npm-publish": "npm run clean && npm run build && npm run test && npm publish"
30
33
  },
31
34
  "exports": {
@@ -36,9 +39,10 @@
36
39
  }
37
40
  },
38
41
  "dependencies": {
39
- "@modelcontextprotocol/sdk": "^1.11.0",
42
+ "@modelcontextprotocol/sdk": "^1.16.0",
40
43
  "commander": "^13.1.0",
41
44
  "debug": "^4.4.1",
45
+ "dotenv": "^17.2.0",
42
46
  "mime": "^4.0.7",
43
47
  "playwright": "1.55.0-alpha-1752701791000",
44
48
  "playwright-core": "1.55.0-alpha-1752701791000",
@@ -46,6 +50,7 @@
46
50
  "zod-to-json-schema": "^3.24.4"
47
51
  },
48
52
  "devDependencies": {
53
+ "@anthropic-ai/sdk": "^0.57.0",
49
54
  "@eslint/eslintrc": "^3.2.0",
50
55
  "@eslint/js": "^9.19.0",
51
56
  "@playwright/test": "1.55.0-alpha-1752701791000",
@@ -60,6 +65,7 @@
60
65
  "eslint": "^9.19.0",
61
66
  "eslint-plugin-import": "^2.31.0",
62
67
  "eslint-plugin-notice": "^1.0.0",
68
+ "openai": "^5.10.2",
63
69
  "typescript": "^5.8.2"
64
70
  },
65
71
  "bin": {
package/lib/connection.js DELETED
@@ -1,81 +0,0 @@
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
- import { Server as McpServer } from '@modelcontextprotocol/sdk/server/index.js';
17
- import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js';
18
- import { zodToJsonSchema } from 'zod-to-json-schema';
19
- import { Context } from './context.js';
20
- import { allTools } from './tools.js';
21
- import { packageJSON } from './package.js';
22
- export function createConnection(config, browserContextFactory) {
23
- const tools = allTools.filter(tool => tool.capability.startsWith('core') || config.capabilities?.includes(tool.capability));
24
- const context = new Context(tools, config, browserContextFactory);
25
- const server = new McpServer({ name: 'Playwright', version: packageJSON.version }, {
26
- capabilities: {
27
- tools: {},
28
- }
29
- });
30
- server.setRequestHandler(ListToolsRequestSchema, async () => {
31
- return {
32
- tools: tools.map(tool => ({
33
- name: tool.schema.name,
34
- description: tool.schema.description,
35
- inputSchema: zodToJsonSchema(tool.schema.inputSchema),
36
- annotations: {
37
- title: tool.schema.title,
38
- readOnlyHint: tool.schema.type === 'readOnly',
39
- destructiveHint: tool.schema.type === 'destructive',
40
- openWorldHint: true,
41
- },
42
- })),
43
- };
44
- });
45
- server.setRequestHandler(CallToolRequestSchema, async (request) => {
46
- const errorResult = (...messages) => ({
47
- content: [{ type: 'text', text: messages.join('\n') }],
48
- isError: true,
49
- });
50
- const tool = tools.find(tool => tool.schema.name === request.params.name);
51
- if (!tool)
52
- return errorResult(`Tool "${request.params.name}" not found`);
53
- const modalStates = context.modalStates().map(state => state.type);
54
- if (tool.clearsModalState && !modalStates.includes(tool.clearsModalState))
55
- return errorResult(`The tool "${request.params.name}" can only be used when there is related modal state present.`, ...context.modalStatesMarkdown());
56
- if (!tool.clearsModalState && modalStates.length)
57
- return errorResult(`Tool "${request.params.name}" does not handle the modal state.`, ...context.modalStatesMarkdown());
58
- try {
59
- return await context.run(tool, request.params.arguments);
60
- }
61
- catch (error) {
62
- return errorResult(String(error));
63
- }
64
- });
65
- return new Connection(server, context);
66
- }
67
- export class Connection {
68
- server;
69
- context;
70
- constructor(server, context) {
71
- this.server = server;
72
- this.context = context;
73
- this.server.oninitialized = () => {
74
- this.context.clientVersion = this.server.getClientVersion();
75
- };
76
- }
77
- async close() {
78
- await this.server.close();
79
- await this.context.close();
80
- }
81
- }
@@ -1,43 +0,0 @@
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
- import { callOnPageNoTrace } from './tools/utils.js';
17
- export class PageSnapshot {
18
- _page;
19
- _text;
20
- constructor(page) {
21
- this._page = page;
22
- }
23
- static async create(page) {
24
- const snapshot = new PageSnapshot(page);
25
- await snapshot._build();
26
- return snapshot;
27
- }
28
- text() {
29
- return this._text;
30
- }
31
- async _build() {
32
- const snapshot = await callOnPageNoTrace(this._page, page => page._snapshotForAI());
33
- this._text = [
34
- `- Page Snapshot:`,
35
- '```yaml',
36
- snapshot,
37
- '```',
38
- ].join('\n');
39
- }
40
- refLocator(params) {
41
- return this._page.locator(`aria-ref=${params.ref}`).describe(params.element);
42
- }
43
- }
package/lib/server.js DELETED
@@ -1,48 +0,0 @@
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
- import { createConnection } from './connection.js';
17
- import { contextFactory } from './browserContextFactory.js';
18
- export class Server {
19
- config;
20
- _connectionList = [];
21
- _browserConfig;
22
- _contextFactory;
23
- constructor(config) {
24
- this.config = config;
25
- this._browserConfig = config.browser;
26
- this._contextFactory = contextFactory(this._browserConfig);
27
- }
28
- async createConnection(transport) {
29
- const connection = createConnection(this.config, this._contextFactory);
30
- this._connectionList.push(connection);
31
- await connection.server.connect(transport);
32
- return connection;
33
- }
34
- setupExitWatchdog() {
35
- let isExiting = false;
36
- const handleExit = async () => {
37
- if (isExiting)
38
- return;
39
- isExiting = true;
40
- setTimeout(() => process.exit(0), 15000);
41
- await Promise.all(this._connectionList.map(connection => connection.close()));
42
- process.exit(0);
43
- };
44
- process.stdin.on('close', handleExit);
45
- process.on('SIGINT', handleExit);
46
- process.on('SIGTERM', handleExit);
47
- }
48
- }