This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
# Build the main package
npm run build
# Build and watch for changes
npm run watch
# Clean build artifacts
npm run clean
# Build the extension (in extension/ directory)
cd extension && npm run build# Run all tests
npm test
# Run tests for specific browser
npm run ctest # Chrome
npm run ftest # Firefox
npm run wtest # WebKit
# Run specific test file
npx playwright test tests/core.spec.ts
# Run tests with specific browser project
npx playwright test --project=chrome# Lint and typecheck (includes README update)
npm run lint
# Fix linting issues
npm run lint-fix
# Type checking only
tsc --noEmit# Run the MCP server locally
npm run run-server
# Full publish flow (clean, build, test, publish)
npm run npm-publishThis is a Model Context Protocol (MCP) server that provides browser automation via Playwright. The codebase consists of:
-
MCP Server Implementation (
src/mcp/)server.ts: Main MCP server with tool registrationserverStdio.ts: STDIO transport implementationserverSSE.ts: SSE/HTTP transport implementation
-
Browser Management (
src/)browserContextFactory.ts: Creates and manages browser contextscontext.ts: Wrapper around Playwright context with MCP-specific featuresbrowserServerBackend.ts: Backend logic for browser operations
-
Tool System (
src/loopTools/)- Each tool (click, navigate, snapshot, etc.) is a separate module
- Tools implement the
Toolinterface with validation and execution logic - Tools use Zod schemas for input validation
-
Extension (
extension/)- Browser extension for enhanced automation capabilities
- Separate TypeScript config and build process
- UI components in
src/ui/
- Tool Registration: Tools are dynamically registered in the MCP server based on capabilities
- Context Management: Browser contexts can be persistent (with profile) or isolated
- Transport Modes: Supports both STDIO (for direct CLI) and SSE (for HTTP server mode)
- Accessibility-First: Uses Playwright's accessibility tree instead of screenshots for element interaction
- Tests use custom fixtures defined in
tests/fixtures.ts - Each test spawns an MCP server instance to test against
- Tests are parallelized and support multiple browser configurations
- Browser projects: chrome, msedge, chromium, firefox, webkit
The server accepts configuration through:
- Command-line arguments (parsed in
src/program.ts) - JSON config file (loaded via
--config) - Environment variables for profile locations
Configuration schema includes browser settings, capabilities, network restrictions, and output options.
- Always use
.jsextension for TypeScript imports (per ESLint config) - Order imports: builtin → external → internal → parent/sibling → type imports
- Tools return structured responses with success/error states
- Browser errors are caught and returned as tool errors
- Network failures and timeouts are handled gracefully
- Strict TypeScript configuration
- Zod schemas for runtime validation of tool inputs
- Explicit typing for MCP protocol messages