返回源码地图

packages/experimental/browser-use-chrome-devtools-mcp/src/index.ts

main snapshot · da00f7f5358f · 正文引用章节 12;完整原文可核对,不声称全文件人工逐行审计

完整原文供逐行核对;页面收录不代表每行都经过人工语义审核。MIT 许可见 许可证。

1/** Chromium inspection and automation through the pinned Chrome DevTools MCP server. @module */
2
3import { fileURLToPath } from 'node:url'
4import type { Context } from '@deepseek-ai/cordis'
5import { BrowserMcpConfig, mountSessionMcp, validateBrowserMcpConfig } from '@deepseek-ai/dsh-experimental-browser-use-runtime/mcp'
6
7/** Cordis identity for the Chrome DevTools MCP browser provider. */
8export const name = 'experimental-browser-use-chrome-devtools-mcp'
9
10/** Services required for scoped MCP startup and prompt readiness checks. */
11export const inject = ['browserUse', 'agents', 'tools', 'systemPrompt']
12
13/** Fixed Chromium launch or existing-browser attachment settings. */
14export type Config = BrowserMcpConfig
15
16/** Validate the launch or attachment configuration before activation. */
17export const Config: typeof BrowserMcpConfig = BrowserMcpConfig
18
19/**
20 * Expose Chrome DevTools' upstream catalog through one MCP process per live Session.
21 * Attached browsers remain externally owned; the server disables usage statistics.
22 * @param ctx - provider context supplying browser use, Agents, and tools.
23 * @param config - validated browser choice and optional tool timeout.
24 */
25export function apply(ctx: Context, config: Config): void {
26 validateBrowserMcpConfig(config)
27 const cli = fileURLToPath(import.meta.resolve('chrome-devtools-mcp/build/src/bin/chrome-devtools-mcp.js'))
28 const args = [cli, '--no-usage-statistics']
29 if (config.mode === 'attach') {
30 args.push(/^wss?:/u.test(config.endpoint) ? '--ws-endpoint' : '--browser-url', config.endpoint)
31 } else {
32 args.push('--isolated', `--headless=${String(config.headless)}`)
33 if (config.executablePath !== undefined) args.push('--executable-path', config.executablePath)
34 }
35 mountSessionMcp(ctx, {
36 name: 'chrome-devtools-mcp',
37 exclusive: config.mode === 'attach',
38 command: process.execPath,
39 args,
40 ...config.toolCallTimeoutMs === undefined ? {} : { toolCallTimeoutMs: config.toolCallTimeoutMs },
41 })
42}