UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

78 lines • 2.99 kB
/** * @license * Copyright 2025 Google LLC * SPDX-License-Identifier: Apache-2.0 */ import '../utils/polyfill.js'; import process from 'node:process'; import { BrowserManager } from '../BrowserManager.js'; import { McpServer, logDisclaimers } from '../index.js'; import { ClearcutLogger } from '../telemetry/ClearcutLogger.js'; import { computeFlagUsage } from '../telemetry/flagUtils.js'; import { StdioServerTransport } from '../third_party/index.js'; import { checkForUpdates } from '../utils/check-for-updates.js'; import { logger, saveLogsToFile } from '../utils/logger.js'; import { setupUnhandledRejectionHandler } from '../utils/errorHandling.js'; import { VERSION } from '../version.js'; import { mcpOptions } from '../config/mcp-options.js'; import { ConfigParser } from '../config/ConfigParser.js'; await checkForUpdates('Run `npm install chrome-devtools-mcp@latest` to update.'); const configParser = new ConfigParser(VERSION); export const args = configParser.parse(); const logFile = args.logFile ? saveLogsToFile(args.logFile) : undefined; setupUnhandledRejectionHandler(() => { process.exit(1); }); logger?.(`Starting Chrome DevTools MCP Server v${VERSION}`); const browserManager = new BrowserManager(args, { logFile, }); const serverPromise = McpServer.from(args, { browserManager, }); // Shutdown on stdin EOF (stdio MCP convention — the client closes the // transport to signal exit) and on standard termination signals. Without // this, an active Chrome subprocess keeps the Node event loop ref'd after // stdin closes and the server hangs until something else kills it. let shuttingDown = false; async function shutdown(reason) { if (shuttingDown) { return; } shuttingDown = true; logger?.(`Shutting down (${reason})`); // Backstop in case browser teardown hangs (e.g. unresponsive Chrome, // slow beforeunload handlers, many tabs). Exits 0 because we still // honored the shutdown request; the log line preserves observability. // Unref'd so it doesn't keep the loop alive on the clean path. setTimeout(() => { logger?.('Shutdown timeout exceeded, forcing exit'); process.exit(0); }, 5000).unref(); const server = await serverPromise; await server.close(); process.exit(0); } process.stdin.on('end', () => { void shutdown('stdin end'); }); process.stdin.on('close', () => { void shutdown('stdin close'); }); process.on('SIGTERM', () => { void shutdown('SIGTERM'); }); process.on('SIGINT', () => { void shutdown('SIGINT'); }); process.on('SIGHUP', () => { void shutdown('SIGHUP'); }); const server = await serverPromise; const transport = new StdioServerTransport(); await server.connect(transport); logger?.('Chrome DevTools MCP Server connected'); logDisclaimers(args); void ClearcutLogger.get()?.logDailyActiveIfNeeded(); void ClearcutLogger.get()?.logServerStart(computeFlagUsage(args, mcpOptions)); //# sourceMappingURL=chrome-devtools-mcp-main.js.map