1
/** Chromium browser tools from the pinned Playwright MCP server. @module */3
import { dirname, join } from 'node:path'4
import { fileURLToPath } from 'node:url'5
import type { Context } from '@deepseek-ai/cordis'6
import { BrowserMcpConfig, mountSessionMcp, validateBrowserMcpConfig } from '@deepseek-ai/dsh-experimental-browser-use-runtime/mcp'8
/** Cordis identity for the Playwright MCP browser provider. */9
export const name = 'experimental-browser-use-playwright-mcp'11
/** Services required for scoped MCP startup and prompt readiness checks. */12
export const inject = ['browserUse', 'agents', 'tools', 'systemPrompt']14
/** Fixed Chromium launch or existing-browser attachment settings. */15
export type Config = BrowserMcpConfig17
/** Validate the launch or attachment configuration before activation. */18
export const Config: typeof BrowserMcpConfig = BrowserMcpConfig20
/**21
* Expose Playwright's upstream tools in each live Session's scope.22
* The pinned npm server runs under the current Node executable; browser state is not persisted by DSH.23
* @param ctx - provider context supplying browser use, Agents, and tools.24
* @param config - validated browser choice and optional tool timeout.25
*/26
export function apply(ctx: Context, config: Config): void {27
validateBrowserMcpConfig(config)28
const cli = join(dirname(fileURLToPath(import.meta.resolve('@playwright/mcp/package.json'))), 'cli.js')29
// Upstream environment options can otherwise replace the configured browser30
// mode or import an unrelated profile. Empty values mean absent to its parser.31
const env = Object.fromEntries(Object.keys(process.env)32
.filter(key => key.toUpperCase().startsWith('PLAYWRIGHT_MCP_'))33
.map(key => [key, '']))34
const args = [cli, '--browser', 'chromium']35
if (config.mode === 'attach') {36
args.push('--cdp-endpoint', config.endpoint)37
} else {38
args.push('--isolated')39
if (config.headless) args.push('--headless')40
if (config.executablePath !== undefined) args.push('--executable-path', config.executablePath)41
}42
mountSessionMcp(ctx, {43
name: 'playwright-mcp',44
exclusive: config.mode === 'attach',45
command: process.execPath,46
args,47
env,48
...config.toolCallTimeoutMs === undefined ? {} : { toolCallTimeoutMs: config.toolCallTimeoutMs },49
})50
}