| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- /** Chromium inspection and automation through the pinned Chrome DevTools MCP server. @module */
- import { fileURLToPath } from 'node:url'
- import type { Context } from '@deepseek-ai/cordis'
- import { BrowserMcpConfig, mountSessionMcp, validateBrowserMcpConfig } from '@deepseek-ai/dsh-experimental-browser-use-runtime/mcp'
- /** Cordis identity for the Chrome DevTools MCP browser provider. */
- export const name = 'experimental-browser-use-chrome-devtools-mcp'
- /** Services required for scoped MCP startup and prompt readiness checks. */
- export const inject = ['browserUse', 'agents', 'tools', 'systemPrompt']
- /** Fixed Chromium launch or existing-browser attachment settings. */
- export type Config = BrowserMcpConfig
- /** Validate the launch or attachment configuration before activation. */
- export const Config: typeof BrowserMcpConfig = BrowserMcpConfig
- /**
- * Expose Chrome DevTools' upstream catalog through one MCP process per live Session.
- * Attached browsers remain externally owned; the server disables usage statistics.
- * @param ctx - provider context supplying browser use, Agents, and tools.
- * @param config - validated browser choice and optional tool timeout.
- */
- export function apply(ctx: Context, config: Config): void {
- validateBrowserMcpConfig(config)
- const cli = fileURLToPath(import.meta.resolve('chrome-devtools-mcp/build/src/bin/chrome-devtools-mcp.js'))
- const args = [cli, '--no-usage-statistics']
- if (config.mode === 'attach') {
- args.push(/^wss?:/u.test(config.endpoint) ? '--ws-endpoint' : '--browser-url', config.endpoint)
- } else {
- args.push('--isolated', `--headless=${String(config.headless)}`)
- if (config.executablePath !== undefined) args.push('--executable-path', config.executablePath)
- }
- mountSessionMcp(ctx, {
- name: 'chrome-devtools-mcp',
- exclusive: config.mode === 'attach',
- command: process.execPath,
- args,
- ...config.toolCallTimeoutMs === undefined ? {} : { toolCallTimeoutMs: config.toolCallTimeoutMs },
- })
- }
|