Skip to content

Commit 7db417d

Browse files
committed
feat: add extension support
1 parent ddeacfe commit 7db417d

14 files changed

Lines changed: 980 additions & 238 deletions

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,5 @@ build/
145145

146146
log.txt
147147

148-
.DS_Store
148+
.DS_Store
149+
.idea

AGENTS.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Repository Guidelines
2+
3+
## Project Structure & Module Organization
4+
5+
TypeScript sources for the MCP server live in `src/`; `src/main.ts` bootstraps the server and `src/tools/` exposes Model Context Protocol tools. Shared helpers for logging, mutex control, trace processing, and formatting sit at the top level to keep concerns isolated. Tests belong in `tests/`, mirroring the source layout; `npm run build` emits JavaScript into `build/`, which should stay generated. Long-form docs live in `docs/`, and automation scripts sit in `scripts/`—always invoke them through npm scripts.
6+
7+
## Build, Test, and Development Commands
8+
9+
- `npm run build` — type-checks with `tsc` and writes output to `build/`.
10+
- `npm run start` — builds then runs `build/src/index.js`.
11+
- `npm run start-debug` — mirrors start with `DEBUG=mcp:*` enabled.
12+
- `npm run test` — builds and runs Node tests at `build/tests/**/*.test.js`.
13+
- `npm run test:only` — reruns only `.only` tests after a build.
14+
- `npm run format` — runs ESLint fixes plus Prettier.
15+
- `npm run docs` — rebuilds, regenerates docs, and formats results.
16+
17+
## Coding Style & Naming Conventions
18+
19+
Write strict TypeScript with ES modules and two-space indentation enforced by Prettier. Prettier also applies single quotes, no bracket spacing, trailing commas, and LF endings; run `npm run format` before committing. ESLint (`eslint.config.mjs`) requires license headers, consistent type-only imports/exports, alphabetized import blocks, and treats unused symbols without `_` prefixes as errors. Prefer named exports; reserve default exports for entry points such as `src/cli.ts`.
20+
21+
## Testing Guidelines
22+
23+
Place tests in `tests/**` with the `.test.ts` suffix to pick up the test-specific lint rules. Use `npm run test` for full runs, `npm run test:only` or `npm run test:only:no-build` when iterating, and `npm run test:update-snapshots` to refresh snapshots. Commit snapshot updates with their corresponding code.
24+
25+
## Commit & Pull Request Guidelines
26+
27+
Follow Conventional Commits (`feat:`, `fix:`, `docs:`, `chore:`) as seen in history, keeping each change scoped with matching tests or docs. PRs should include a concise summary, linked issues, and notes on how you tested; attach screenshots or CLI transcripts when user-visible behavior shifts.
28+
29+
## Environment & Configuration Tips
30+
31+
Use Node.js v22 per `.nvmrc` and the `engines` field. Manage dependencies with `npm`, avoid editing `node_modules/` or `build/` manually, and reach for `npm run start-debug` when you need verbose server logs.

CLAUDE.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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

Comments
 (0)