Pipe MCP subprocess stderr to logger and fix bin lookup key
Two review followups: - Consume the piped stderr from @playwright/mcp so browser-launch failures surface in our own logs (was set to "pipe" but never read). - Drop the wrong ["mcp-server-playwright"] lookup; the actual bin key is "playwright-mcp". Falling through Object.values worked but was dead code.
This commit is contained in:
@@ -43,7 +43,7 @@ export interface McpCallResult {
|
||||
|
||||
export async function createPlaywrightMcpBridge(opts: PlaywrightMcpOptions): Promise<PlaywrightMcpBridge> {
|
||||
const argv = buildArgs(opts);
|
||||
const factory = opts.clientFactory ?? defaultClientFactory;
|
||||
const factory = opts.clientFactory ?? ((a) => defaultClientFactory(a, opts.logger));
|
||||
const client = await factory(argv);
|
||||
const { tools: mcpTools } = await client.listTools();
|
||||
const tools: CustomTools = mcpTools.map((t) => wrapTool(t, client));
|
||||
@@ -83,13 +83,13 @@ function buildArgs(opts: PlaywrightMcpOptions): string[] {
|
||||
return args;
|
||||
}
|
||||
|
||||
async function defaultClientFactory(argv: string[]): Promise<McpClientLike> {
|
||||
async function defaultClientFactory(argv: string[], logger: Logger): Promise<McpClientLike> {
|
||||
// Resolve the bin from our own node_modules so we never depend on `npx` at
|
||||
// runtime and always get the pinned @playwright/mcp version.
|
||||
const require = createRequire(import.meta.url);
|
||||
const pkgPath = require.resolve("@playwright/mcp/package.json");
|
||||
const pkg = require("@playwright/mcp/package.json") as { bin?: string | Record<string, string> };
|
||||
const binField = typeof pkg.bin === "string" ? pkg.bin : pkg.bin?.["mcp-server-playwright"] ?? Object.values(pkg.bin ?? {})[0];
|
||||
const binField = typeof pkg.bin === "string" ? pkg.bin : Object.values(pkg.bin ?? {})[0];
|
||||
if (!binField) throw new Error("@playwright/mcp package.json has no bin entry");
|
||||
const path = await import("node:path");
|
||||
const binAbs = path.resolve(path.dirname(pkgPath), binField);
|
||||
@@ -101,6 +101,10 @@ async function defaultClientFactory(argv: string[]): Promise<McpClientLike> {
|
||||
});
|
||||
const client = new Client({ name: "volcanic-secretary", version: "0.1.0" });
|
||||
await client.connect(transport);
|
||||
transport.stderr?.on("data", (buf: Buffer | string) => {
|
||||
const line = (typeof buf === "string" ? buf : buf.toString("utf8")).trimEnd();
|
||||
if (line) logger.warn(`playwright mcp: ${line}`);
|
||||
});
|
||||
return client as unknown as McpClientLike;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user