Files
makelore/electron/opencode/playwright-mcp.ts
2026-07-29 17:22:35 +08:00

34 lines
1002 B
TypeScript

import { dirname, join } from 'node:path';
import { createRequire } from 'node:module';
import type { OpencodeMcpServerEntry } from './provider-config';
const moduleRequire = createRequire(import.meta.url);
export const PLAYWRIGHT_MCP_SERVER_ID = 'playwright';
export const PLAYWRIGHT_MCP_PACKAGE = '@playwright/mcp';
export const PLAYWRIGHT_MCP_VERSION = '0.0.78';
function fallbackPlaywrightMcpServer(): OpencodeMcpServerEntry {
return {
type: 'local',
command: ['npx', '-y', `${PLAYWRIGHT_MCP_PACKAGE}@${PLAYWRIGHT_MCP_VERSION}`],
enabled: true,
};
}
export function resolvePlaywrightMcpServer(): OpencodeMcpServerEntry {
try {
const packageJsonPath = moduleRequire.resolve(`${PLAYWRIGHT_MCP_PACKAGE}/package.json`);
return {
type: 'local',
command: [process.execPath, join(dirname(packageJsonPath), 'cli.js')],
enabled: true,
env: {
ELECTRON_RUN_AS_NODE: '1',
},
};
} catch {
return fallbackPlaywrightMcpServer();
}
}