@ejazullah/browser-mcp 0.0.60 → 0.0.61
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/mcp/transport.js +13 -0
- package/lib/program.js +26 -0
- package/package.json +1 -1
package/lib/mcp/transport.js
CHANGED
|
@@ -168,6 +168,19 @@ async function handleStreamable(serverBackendFactory, req, res, sessions, sessio
|
|
|
168
168
|
res.end('Session not found');
|
|
169
169
|
return;
|
|
170
170
|
}
|
|
171
|
+
if (cdpSessionKey) {
|
|
172
|
+
const matchedSessionId = findSessionIdByCdpKey(sessionCdpKeys, sessions, cdpSessionKey);
|
|
173
|
+
if (matchedSessionId) {
|
|
174
|
+
const matchedTransport = sessions.get(matchedSessionId);
|
|
175
|
+
testDebug(`stale mcp-session-id ${sessionId}, reusing cdp-matched session: ${matchedSessionId} (${cdpSessionKey})`);
|
|
176
|
+
return await matchedTransport.handleRequest(req, res);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if (sessions.size === 1) {
|
|
180
|
+
const [singleSessionId, singleTransport] = sessions.entries().next().value;
|
|
181
|
+
testDebug(`stale mcp-session-id ${sessionId}, reusing single active session: ${singleSessionId}`);
|
|
182
|
+
return await singleTransport.handleRequest(req, res);
|
|
183
|
+
}
|
|
171
184
|
delete req.headers['mcp-session-id'];
|
|
172
185
|
testDebug(`stale http session id: ${sessionId}, creating a new session`);
|
|
173
186
|
}
|
package/lib/program.js
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
import { program, Option } from 'commander';
|
|
17
17
|
// @ts-ignore
|
|
18
18
|
import { startTraceViewerServer } from 'playwright-core/lib/server';
|
|
19
|
+
import debug from 'debug';
|
|
19
20
|
import * as mcpTransport from './mcp/transport.js';
|
|
20
21
|
import { commaSeparatedList, resolveCLIConfig, semicolonSeparatedList } from './config.js';
|
|
21
22
|
import { buildAuthConfig } from './auth.js';
|
|
@@ -25,6 +26,28 @@ import { BrowserServerBackend } from './browserServerBackend.js';
|
|
|
25
26
|
import { Context } from './context.js';
|
|
26
27
|
import { contextFactory } from './browserContextFactory.js';
|
|
27
28
|
import { runLoopTools } from './loopTools/main.js';
|
|
29
|
+
const mcpDebugNamespace = 'pw:mcp:*';
|
|
30
|
+
function setMcpDebugLogging(enabled) {
|
|
31
|
+
if (enabled === undefined)
|
|
32
|
+
return;
|
|
33
|
+
const current = process.env.DEBUG ?? '';
|
|
34
|
+
const namespaces = current.split(',').map(token => token.trim()).filter(Boolean);
|
|
35
|
+
if (enabled) {
|
|
36
|
+
if (!namespaces.includes(mcpDebugNamespace)) {
|
|
37
|
+
namespaces.push(mcpDebugNamespace);
|
|
38
|
+
process.env.DEBUG = namespaces.join(',');
|
|
39
|
+
debug.enable(process.env.DEBUG);
|
|
40
|
+
}
|
|
41
|
+
// eslint-disable-next-line no-console
|
|
42
|
+
console.error(`[mcp] verbose logs enabled (${mcpDebugNamespace})`);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const filtered = namespaces.filter(ns => ns !== mcpDebugNamespace && !ns.startsWith('pw:mcp:'));
|
|
46
|
+
process.env.DEBUG = filtered.join(',');
|
|
47
|
+
debug.enable(process.env.DEBUG);
|
|
48
|
+
// eslint-disable-next-line no-console
|
|
49
|
+
console.error('[mcp] verbose logs disabled');
|
|
50
|
+
}
|
|
28
51
|
program
|
|
29
52
|
.version('Version ' + packageJSON.version)
|
|
30
53
|
.name(packageJSON.name)
|
|
@@ -53,6 +76,8 @@ program
|
|
|
53
76
|
.option('--user-agent <ua string>', 'specify user agent string')
|
|
54
77
|
.option('--user-data-dir <path>', 'path to the user data directory. If not specified, a temporary directory will be created.')
|
|
55
78
|
.option('--viewport-size <size>', 'specify browser viewport size in pixels, for example "1280, 720"')
|
|
79
|
+
.option('--mcp-logs', 'Enable verbose MCP/session transport logs in CLI output')
|
|
80
|
+
.option('--no-mcp-logs', 'Disable verbose MCP/session transport logs in CLI output')
|
|
56
81
|
.option('--mongodb-url <url>', 'MongoDB connection URL. Example: mongodb://localhost:27017')
|
|
57
82
|
.option('--mongodb-db <name>', 'MongoDB database name. Default: playwright_mcp')
|
|
58
83
|
.option('--mongodb-collection <name>', 'MongoDB collection name. Default: element_interactions')
|
|
@@ -67,6 +92,7 @@ program
|
|
|
67
92
|
.addOption(new Option('--vision', 'Legacy option, use --caps=vision instead').hideHelp())
|
|
68
93
|
.action(async (options) => {
|
|
69
94
|
setupExitWatchdog();
|
|
95
|
+
setMcpDebugLogging(options.mcpLogs);
|
|
70
96
|
if (options.vision) {
|
|
71
97
|
// eslint-disable-next-line no-console
|
|
72
98
|
console.error('The --vision option is deprecated, use --caps=vision instead');
|