This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
- Node.js >=22.12 (recommended: 24.3.0 per .nvmrc)
- pnpm ^10
- Chrome browser for extension development
pnpm install- Install all dependencies across the monorepopnpm build:shared- Build all shared internal packagespnpm build:apps- Build all applications (extension, backend, native-server)pnpm dev- Start all development servers with automatic native messaging registrationpnpm dev:apps- Start development servers for all appspnpm dev:mcp- Start only extension and native-server (useful for MCP development)
pnpm build- Build all projects in the monorepo (runs build:packages first, then builds apps)pnpm typecheck- Type-check all TypeScript files across the workspacepnpm lint- Run Biome linter with auto-fixpnpm format- Format code with Biomepnpm check- Run both linting and formatting checkspnpm check-all- Complete quality check (typecheck + biome ci)
pnpm test- Run all tests across the monorepo with Turbo (uses Vitest for unit tests)pnpm test:e2e- Run end-to-end tests using Playwrightpnpm --filter @mcp-b/e2e-tests test:ui- Run E2E tests with UIpnpm --filter @mcp-b/e2e-tests test:debug- Debug E2E testspnpm --filter @mcp-b/e2e-tests test:headed- Run tests with browser visible- For specific e2e tests:
cd e2e-tests && pnpm test:basicorpnpm test:mcp
pnpm --filter @mcp-b/extension dev:firefox- Run extension in Firefoxpnpm --filter @mcp-b/extension build:firefox- Build for Firefoxpnpm --filter @mcp-b/extension zip- Create extension zip for distributionpnpm --filter @mcp-b/extension test:ui- Run tests with UIpnpm --filter @mcp-b/extension compile- Type check without emit
pnpm --filter @mcp-b/backend deploy- Deploy backend to Cloudflare Workerspnpm --filter @mcp-b/backend cf-typegen- Generate Cloudflare typespnpm changeset- Create a changeset for version managementpnpm changeset:version- Update versions based on changesetspnpm changeset:publish- Publish packages to npm
pnpm clean- Clean git artifacts (.cache, .turbo, node_modules)pnpm clear-configs- Clear native messaging configurations
NPM packages have been moved to a separate repository: https://github.com/WebMCP-org/npm-packages
Examples have been moved to a separate repository: https://github.com/WebMCP-org/examples
To run examples, clone the examples repository and follow the instructions there.
This is MCP-B: a browser-native implementation of the Model Context Protocol (MCP) that allows websites to expose functionality as tools that AI agents can call directly.
- Traditional browser automation: AI parses screenshots/DOM to "click" elements (slow, brittle)
- MCP-B approach: Websites expose structured tools that AI calls directly (fast, reliable)
1. Transport Layer (@mcp-b/transports)
The heart of MCP-B, providing browser-specific transport implementations:
- TabServerTransport/TabClientTransport: Uses
postMessagefor same-tab communication - ExtensionServerTransport/ExtensionClientTransport: Uses Chrome runtime messaging for extension communication
- NativeServerTransport/NativeClientTransport: Bridges browser to local MCP clients
Built with WXT framework, acts as MCP client:
- Background service: Manages connections to websites and native hosts
- Sidepanel: React-based UI with chat interface and tool inspector
- Content scripts: Inject MCP clients into web pages
- Uses Assistant UI (@assistant-ui/react) for chat interfaces
3. Web Tools & Extension Tools (NPM Packages)
- @mcp-b/web-tools: MCP tools for web APIs (like Prompt API)
- @mcp-b/extension-tools: Auto-generated MCP tools for Chrome Extension APIs
- @mcp-b/mcp-react-hooks: React hooks for MCP integration
4. Demo Website (WebMCP-org/web)
Full-stack demo showcasing MCP-B capabilities:
- Frontend: React with MCP server exposing todo management tools
- Backend: Cloudflare Workers with Hono.js and PostgreSQL
- Real-time sync: ElectricSQL for live data updates
Node.js server that bridges browser extension to local MCP clients:
- HTTP server on port 12306
- Proxies requests from desktop apps (Claude Desktop, Cursor) to browser
- Native Messaging Setup: Automatically registers native messaging host manifests for both regular Chrome and Chrome for Testing during development
- Website registers MCP server with tools using
TabServerTransport - Extension injects client that discovers available tools
- User interacts via extension's chat or calls tools directly
- Tools execute in website context with full authentication
- Results flow back to AI with visual feedback in UI
- Browser-first: Leverages existing web security model and user authentication
- Deterministic: Tools return structured data, not visual parsing
- Scoped: Tools are page-specific and respect user sessions
- Auditable: All tool calls visible in extension UI
Transport implementations live in the @mcp-b/transports package and must implement the MCP transport interface.
- For websites: Use
@mcp-b/transportswithTabServerTransport - For extensions: Use
@mcp-b/extension-toolsor extendBaseApiTools - Always use Zod schemas for input validation
- Built with WXT (extension framework)
- Uses React with Tailwind CSS and Shadcn UI
- Background scripts manage MCP connections
- Sidepanel provides user interface
- Extension environment configuration via
apps/extension/.envfile - Production extension ID:
daohopfhkdelnpemnhlekblhnikhdhfa(Chrome Web Store)
- Unit tests with Vitest for extension code
- E2E tests with Playwright testing real extension functionality
- Test libraries:
@testing-library/react,jsdomfor extension tests - Manual testing with example applications
- Run
pnpm testfor all tests or filter specific packages
- Biome for linting and formatting (replaces ESLint/Prettier)
- Turbo for monorepo task orchestration
- Husky for git hooks (commit-msg, pre-commit)
- Commitlint for conventional commit messages
- Automated quality checks on commit via git hooks
Uses changesets for version management:
- Make changes
- Run
pnpm changesetto document changes - Run
pnpm changeset:versionto update versions - Run
pnpm changeset:publishto publish to npm - Native-server is published as
@mcp-b/native-serveron npm
The development workflow is fully automated with configurable extension IDs:
-
New Developer Setup:
git clone <repo-url> cd WebMCP pnpm install # Optional: Configure your development extension ID cp apps/native-server/.env.example apps/native-server/.env # Edit apps/native-server/.env with your extension ID if different pnpm dev
-
Finding Your Extension ID:
- Run
pnpm devfirst (uses default ID) - Open Chrome at
chrome://extensions/ - Enable "Developer mode"
- Find your MCP-B extension and copy the ID
- Update
apps/native-server/.envwithDEV_EXTENSION_ID=your-extension-id - Restart
pnpm dev
- Run
-
What
pnpm devdoes automatically:- Builds all packages and the native server
- Loads extension ID from
apps/native-server/.env(git-ignored) - Registers native messaging host for both production and dev extension IDs
- Starts WXT with a persistent profile (
apps/extension/.wxt/chrome-data) - Launches the extension in Chrome
-
Extension ID Management:
- Production extension ID:
mhipkdochajohklmmjinmicahanmldbj(hardcoded) - Development extension ID: Configurable via
apps/native-server/.env(git-ignored) - Default dev ID:
oeidgnbdmdjeacgmfhemhpngaplpkiel - Both IDs are included in all native messaging manifests
- Production extension ID:
-
Persistent Profile Benefits:
- Browser data persists between dev sessions
- Native messaging manifests are found correctly
- Can install devtools extensions and remember logins
- Configured via
apps/extension/web-ext.config.ts
- Run
pnpm --filter @mcp-b/native-server run register:dev - Registers manifests in all Chrome variants and the persistent WXT profile
If you still get "Access to the specified native messaging host is forbidden":
- Ensure
pnpm devcompleted successfully - Check that manifests exist in the persistent profile directory:
apps/extension/.wxt/chrome-data/NativeMessagingHosts/com.chromemcp.nativehost.json
WebMCP/
├── apps/ # Application packages
│ ├── extension/ # Browser extension (Chrome/Firefox)
│ ├── backend/ # Backend server (Cloudflare Workers)
│ └── native-server/ # Native messaging host (Node.js, port 12306)
├── shared/ # Internal shared packages
│ └── utils/ # Shared utility functions
├── e2e-tests/ # End-to-end tests with Playwright
└── scripts/ # Build and maintenance scripts
- npm-packages - Published NPM packages (@mcp-b/transports, @mcp-b/web-tools, etc.)
- examples - Example applications
- web - Demo website with todo app
- webmcp-userscripts - Tampermonkey userscripts
- Uses pnpm workspaces with Turbo for task orchestration
- Apps and shared packages have interdependencies requiring proper build order
- Critical:
build:sharedorbuild:packagesmust run before building apps - Workspace uses pnpm catalog for centralized dependency version management
Extension requires broad permissions for Chrome API access. Tools are scoped appropriately in implementation.
- Respects browser same-origin policy
- Tools execute in website context using existing user authentication
- No data leaves browser except through explicit tool calls
Recent migration to domain-prefixed tool names (e.g., domain_com_toolName) for multi-tab disambiguation.
- Cloudflare Workers with Hono.js framework
- PostgreSQL database for persistent storage
- ElectricSQL for real-time data synchronization
- Deploy with
pnpm --filter @mcp-b/backend deploy