index.ts 2.0 KB

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