|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +Chrome DevTools MCP is a Model Context Protocol (MCP) server that allows AI coding assistants to control and inspect a live Chrome browser. It provides browser automation, debugging capabilities, and performance analysis through the Chrome DevTools protocol and Puppeteer. |
| 8 | + |
| 9 | +## Development Commands |
| 10 | + |
| 11 | +### Build and Type Checking |
| 12 | + |
| 13 | +- `npm run build` - Compiles TypeScript and runs post-build processing |
| 14 | +- `npm run typecheck` - Type checks without emitting files |
| 15 | +- `npm run format` - Runs ESLint with auto-fix and Prettier |
| 16 | +- `npm run check-format` - Lints and checks formatting without fixes |
| 17 | + |
| 18 | +### Testing |
| 19 | + |
| 20 | +- `npm test` - Builds and runs all tests |
| 21 | +- `npm run test:only` - Builds and runs tests marked with `test.only` |
| 22 | +- `npm run test:only:no-build` - Runs tests with `test.only` without rebuilding |
| 23 | +- `npm run test:update-snapshots` - Updates test snapshots |
| 24 | + |
| 25 | +### Documentation |
| 26 | + |
| 27 | +- `npm run docs` - Builds project and regenerates tool documentation |
| 28 | +- `npm run docs:generate` - Generates tool reference documentation only |
| 29 | + |
| 30 | +### Running the Server |
| 31 | + |
| 32 | +- `npm start` - Builds and starts the MCP server |
| 33 | +- `npm run start-debug` - Starts with debug logging enabled |
| 34 | + |
| 35 | +## Architecture |
| 36 | + |
| 37 | +### Core Components |
| 38 | + |
| 39 | +**Main Entry Point (`src/main.ts`)** |
| 40 | + |
| 41 | +- Sets up the MCP server using `@modelcontextprotocol/sdk` |
| 42 | +- Registers all tools from different categories |
| 43 | +- Uses a mutex to serialize tool execution |
| 44 | +- Handles browser initialization and context management |
| 45 | + |
| 46 | +**Browser Management (`src/browser.ts`, `src/McpContext.ts`)** |
| 47 | + |
| 48 | +- `resolveBrowser()` handles Chrome browser discovery and launching |
| 49 | +- `McpContext` manages browser instance, pages, network/console collectors |
| 50 | +- Supports connecting to existing browser instances or launching new ones |
| 51 | + |
| 52 | +**Tool System (`src/tools/`)** |
| 53 | + |
| 54 | +- Each tool category is in a separate file (input, pages, performance, etc.) |
| 55 | +- Tools use `ToolDefinition` interface with Zod schemas for validation |
| 56 | +- All tools are registered automatically in `main.ts` |
| 57 | +- Tool categories: Input automation, Navigation, Emulation, Performance, Network, Debugging |
| 58 | + |
| 59 | +**DevTools Integration** |
| 60 | + |
| 61 | +- Uses `chrome-devtools-frontend` package for trace processing and performance analysis |
| 62 | +- Heavy integration with Chrome DevTools models for performance insights |
| 63 | +- Custom formatters in `src/formatters/` for console, network, and snapshot data |
| 64 | + |
| 65 | +### Key Patterns |
| 66 | + |
| 67 | +**Page Management** |
| 68 | + |
| 69 | +- Uses `PageCollector` to track pages, network requests, and console messages |
| 70 | +- Maintains selected page state and handles page navigation |
| 71 | +- Each page has its own collectors for network and console data |
| 72 | + |
| 73 | +**Response Handling** |
| 74 | + |
| 75 | +- `McpResponse` class builds structured responses with text, images, and metadata |
| 76 | +- Tools can include page snapshots, network data, console logs automatically |
| 77 | +- Supports pagination for large datasets (network requests, console messages) |
| 78 | + |
| 79 | +**Performance Tracing** |
| 80 | + |
| 81 | +- `src/trace-processing/parse.ts` processes Chrome DevTools traces |
| 82 | +- Uses Chrome DevTools frontend models for analysis and insights |
| 83 | +- Stores trace results in context for later analysis |
| 84 | + |
| 85 | +### File Structure Highlights |
| 86 | + |
| 87 | +- `src/tools/` - All MCP tool implementations |
| 88 | +- `src/formatters/` - Data formatting utilities for different content types |
| 89 | +- `src/trace-processing/` - Performance trace analysis |
| 90 | +- `tests/` - Comprehensive test suite with snapshots |
| 91 | +- `scripts/` - Build and documentation generation scripts |
| 92 | + |
| 93 | +## Configuration |
| 94 | + |
| 95 | +The project uses modern TypeScript with ES modules (`"type": "module"` in package.json). Key configurations: |
| 96 | + |
| 97 | +- **Node.js**: Requires >= 22.12.0 |
| 98 | +- **TypeScript**: Targets ES2023 with bundler module resolution |
| 99 | +- **ESLint**: Flat config with TypeScript, import, and stylistic rules |
| 100 | +- **Testing**: Node.js test runner with custom setup and snapshots |
| 101 | + |
| 102 | +## Extension Support |
| 103 | + |
| 104 | +The server now supports loading Chrome extensions during browser launch: |
| 105 | + |
| 106 | +- **EXTENSION_PATH** - Set this environment variable to automatically load an unpacked extension |
| 107 | +- Extensions are loaded with activity logging enabled for debugging |
| 108 | +- Use extension debugging tools: `extension_get_logs`, `extension_simple_test` |
| 109 | + |
| 110 | +## Development Notes |
| 111 | + |
| 112 | +- All tools must be thread-safe due to mutex serialization |
| 113 | +- Heavy use of Chrome DevTools frontend types and utilities |
| 114 | +- Network conditions and CPU throttling are supported for emulation |
| 115 | +- Browser user data is persistent by default (use `--isolated` for temporary) |
| 116 | +- Debug logging available via `DEBUG=*` environment variable |
0 commit comments