Files
makelore/electron/opencode/playwright-mcp.ts

32 lines
992 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';
type ResolvePackageJson = () => string;
export function resolvePlaywrightMcpServer(
resolvePackageJson: ResolvePackageJson = () => moduleRequire.resolve(`${PLAYWRIGHT_MCP_PACKAGE}/package.json`),
): OpencodeMcpServerEntry {
try {
const packageJsonPath = resolvePackageJson();
return {
type: 'local',
command: [process.execPath, join(dirname(packageJsonPath), 'cli.js')],
enabled: true,
env: {
ELECTRON_RUN_AS_NODE: '1',
},
};
} catch (error) {
throw new Error(
`Bundled ${PLAYWRIGHT_MCP_PACKAGE} is missing; Makelore does not download runtime dependencies with npx`,
{ cause: error },
);
}
}