This file contains short, actionable guidance for an AI coding agent to be productive in this repository.
-
Purpose (big picture)
- This repo implements an MCP server that exposes Chrome DevTools functionality to MCP clients.
- High-level flow: MCP client ->
McpContext-> tool dispatcher (src/tools/*) ->DevToolsConnectionAdapter/PageCollector-> Puppeteer + DevTools.
-
Key files & why they matter
src/McpContext.ts— request lifecycle, context and quota handling.src/DevToolsConnectionAdapter.ts— adapter between MCP tools and DevTools/Puppeteer.src/tools/ToolDefinition.tsandsrc/tools/*.ts— where each MCP tool is defined; modify here to add/update tools.src/PageCollector.ts— collects and manages trace/pages when recording performance.src/formatters/*— formatting functions for console, network and snapshot outputs.third_party/devtools.ts— mappings and constants derived from DevTools frontend.server.json— server metadata;scripts/verify-server-json-version.tsvalidates this.
-
Build / test / doc workflows (exact commands)
- Node requirement: Node v20.19+ (see
package.json.engines). - Build (compile + post-process):
npm run build(runstscthenscripts/post-build.ts). - Build+bundle (production):
npm run bundle(also runs Rollup). After bundling,build/srcis the runtime output. - Start server (dev):
npm run startornpm run start-debug(setsDEBUG=mcp:*). - Tests: tests run against the transpiled build. Typical sequence:
npm run build && npm run test:no-buildor simplynpm run test. - Generate docs / tool reference:
npm run docs(callsscripts/generate-docs.ts). The README contains an auto-generated tools block; update docs after editingsrc/tools/*.
- Node requirement: Node v20.19+ (see
-
Project-specific conventions & gotchas
- Tests run against
build/tests/*and rely onbuild/tests/setup.jsbeing imported. Always runnpm run buildfirst. - The build pipeline uses
node --experimental-strip-typesin post-build. Do not assume plaintscoutput is fully runnable withoutpost-buildsteps. - The
binentry points tobuild/src/index.js: changes to CLI entry must be reflected in the build output. - Tool definitions are canonical sources for the public MCP surface; changing
src/tools/*often requires regenerating the docs (npm run docs). - Lint/format:
npm run format;eslint_rules/contains custom rules used by CI.
- Tests run against
-
Integration points & external deps
- Puppeteer (
puppeteer) is used to drive Chrome.DevToolsConnectionAdapterandPageCollectorcontain the Puppeteer interactions. - DevTools frontend assets:
chrome-devtools-frontendis a dependency;third_party/devtools.tsreferences generated artifacts. - Many runtime behaviors are controlled by CLI flags (see README for
--browser-url,--ws-endpoint,--isolated, etc.).
- Puppeteer (
-
When editing code, practical examples
- Adding a new tool: add
src/tools/mytool.ts, update exports insrc/tools/tools.ts, runnpm run buildandnpm run docsto update the README tools list. - Fixing a formatter: update
src/formatters/*.tsand run unit tests (npm run build && npm run test:no-build). - Debugging live behavior: use
npm run start-debugand setDEBUG=mcp:* DEBUG_COLORS=falseto reproduce logs similar to CI.
- Adding a new tool: add
-
Useful places to check before changes
README.md— contains overall guidance and auto-generated tools block.docs/tool-reference.md— canonical documentation of tools and their inputs/outputs.scripts/— build/post-build/docs generation behaviors.tests/— examples of how tools are used and what outputs/fixtures look like (snapshots live undertests/*/*.snapshot).
-
Safety & scope
- This project exposes browser content via MCP — avoid adding code that leaks secrets into logs or public responses. Follow existing patterns for masking or avoiding sensitive content.
If any section is unclear or you want more examples (e.g., a walkthrough of adding a tool end-to-end), I can expand specific parts. Please tell me which area you'd like more detail on.