@playwright/mcp 0.0.19 → 0.0.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/README.md +84 -9
- package/config.d.ts +14 -14
- package/index.d.ts +8 -2
- package/index.js +2 -2
- package/lib/config.js +14 -16
- package/lib/{server.js → connection.js} +31 -28
- package/lib/context.js +36 -2
- package/lib/index.js +2 -51
- package/lib/program.js +15 -9
- package/lib/tab.js +18 -1
- package/lib/tools/common.js +6 -0
- package/lib/tools/console.js +2 -0
- package/lib/tools/dialogs.js +2 -0
- package/lib/tools/files.js +2 -0
- package/lib/tools/install.js +6 -2
- package/lib/tools/keyboard.js +2 -0
- package/lib/tools/navigate.js +6 -0
- package/lib/tools/network.js +2 -0
- package/lib/tools/pdf.js +2 -0
- package/lib/tools/screen.js +10 -0
- package/lib/tools/snapshot.js +15 -1
- package/lib/tools/tabs.js +8 -0
- package/lib/tools/testing.js +2 -0
- package/lib/tools.js +56 -0
- package/lib/transport.js +23 -15
- package/package.json +3 -3
package/lib/transport.js
CHANGED
|
@@ -16,14 +16,16 @@
|
|
|
16
16
|
import http from 'node:http';
|
|
17
17
|
import assert from 'node:assert';
|
|
18
18
|
import crypto from 'node:crypto';
|
|
19
|
-
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
20
19
|
import { SSEServerTransport } from '@modelcontextprotocol/sdk/server/sse.js';
|
|
21
20
|
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
22
|
+
import { createConnection } from './connection.js';
|
|
23
|
+
export async function startStdioTransport(config, connectionList) {
|
|
24
|
+
const connection = await createConnection(config);
|
|
25
|
+
await connection.connect(new StdioServerTransport());
|
|
26
|
+
connectionList.push(connection);
|
|
25
27
|
}
|
|
26
|
-
async function handleSSE(req, res, url,
|
|
28
|
+
async function handleSSE(config, req, res, url, sessions, connectionList) {
|
|
27
29
|
if (req.method === 'POST') {
|
|
28
30
|
const sessionId = url.searchParams.get('sessionId');
|
|
29
31
|
if (!sessionId) {
|
|
@@ -40,20 +42,22 @@ async function handleSSE(req, res, url, serverList, sessions) {
|
|
|
40
42
|
else if (req.method === 'GET') {
|
|
41
43
|
const transport = new SSEServerTransport('/sse', res);
|
|
42
44
|
sessions.set(transport.sessionId, transport);
|
|
43
|
-
const
|
|
45
|
+
const connection = await createConnection(config);
|
|
46
|
+
await connection.connect(transport);
|
|
47
|
+
connectionList.push(connection);
|
|
44
48
|
res.on('close', () => {
|
|
45
49
|
sessions.delete(transport.sessionId);
|
|
46
|
-
|
|
50
|
+
connection.close().catch(e => {
|
|
47
51
|
// eslint-disable-next-line no-console
|
|
48
52
|
console.error(e);
|
|
49
53
|
});
|
|
50
54
|
});
|
|
51
|
-
return
|
|
55
|
+
return;
|
|
52
56
|
}
|
|
53
57
|
res.statusCode = 405;
|
|
54
58
|
res.end('Method not allowed');
|
|
55
59
|
}
|
|
56
|
-
async function handleStreamable(req, res,
|
|
60
|
+
async function handleStreamable(config, req, res, sessions, connectionList) {
|
|
57
61
|
const sessionId = req.headers['mcp-session-id'];
|
|
58
62
|
if (sessionId) {
|
|
59
63
|
const transport = sessions.get(sessionId);
|
|
@@ -75,22 +79,26 @@ async function handleStreamable(req, res, serverList, sessions) {
|
|
|
75
79
|
if (transport.sessionId)
|
|
76
80
|
sessions.delete(transport.sessionId);
|
|
77
81
|
};
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
82
|
+
const connection = await createConnection(config);
|
|
83
|
+
connectionList.push(connection);
|
|
84
|
+
await Promise.all([
|
|
85
|
+
connection.connect(transport),
|
|
86
|
+
transport.handleRequest(req, res),
|
|
87
|
+
]);
|
|
88
|
+
return;
|
|
81
89
|
}
|
|
82
90
|
res.statusCode = 400;
|
|
83
91
|
res.end('Invalid request');
|
|
84
92
|
}
|
|
85
|
-
export function startHttpTransport(port, hostname,
|
|
93
|
+
export function startHttpTransport(config, port, hostname, connectionList) {
|
|
86
94
|
const sseSessions = new Map();
|
|
87
95
|
const streamableSessions = new Map();
|
|
88
96
|
const httpServer = http.createServer(async (req, res) => {
|
|
89
97
|
const url = new URL(`http://localhost${req.url}`);
|
|
90
98
|
if (url.pathname.startsWith('/mcp'))
|
|
91
|
-
await handleStreamable(req, res,
|
|
99
|
+
await handleStreamable(config, req, res, streamableSessions, connectionList);
|
|
92
100
|
else
|
|
93
|
-
await handleSSE(req, res, url,
|
|
101
|
+
await handleSSE(config, req, res, url, sseSessions, connectionList);
|
|
94
102
|
});
|
|
95
103
|
httpServer.listen(port, hostname, () => {
|
|
96
104
|
const address = httpServer.address();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@playwright/mcp",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.22",
|
|
4
4
|
"description": "Playwright Tools for MCP",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"license": "Apache-2.0",
|
|
18
18
|
"scripts": {
|
|
19
19
|
"build": "tsc",
|
|
20
|
-
"lint": "npm run update-readme && eslint .",
|
|
20
|
+
"lint": "npm run update-readme && eslint . && tsc --noEmit",
|
|
21
21
|
"update-readme": "node utils/update-readme.js",
|
|
22
22
|
"watch": "tsc --watch",
|
|
23
23
|
"test": "playwright test",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@modelcontextprotocol/sdk": "^1.
|
|
38
|
+
"@modelcontextprotocol/sdk": "^1.11.0",
|
|
39
39
|
"commander": "^13.1.0",
|
|
40
40
|
"playwright": "1.53.0-alpha-1746218818000",
|
|
41
41
|
"yaml": "^2.7.1",
|