# Forged ⚒️ Browser automation that learns. An MCP server that makes AI agents faster at repeated browser tasks by recording what works and replaying deterministic steps via Playwright. **47.4s → 8.8s on the second run. 5.4x faster. Zero config.** [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE) [![Python 3.11+](https://img.shields.io/badge/python-3.11%2B-blue.svg)](https://www.python.org/) [![MCP](https://img.shields.io/badge/MCP-server-7c3aed.svg)](https://modelcontextprotocol.io/) [![Playwright](https://img.shields.io/badge/playwright-1.52-2EAD33.svg)](https://playwright.dev/) ## What it does Every time an AI agent browses a website, it starts from scratch. Login flows, navigation, search bars, all rediscovered through expensive LLM calls. 3 to 5 seconds per step, every single time. Forged fixes this. It sits between your AI assistant and the browser, records successful traces, extracts reusable templates, and replays deterministic steps at millisecond speed. The LLM only handles steps that genuinely need reasoning. ``` Run 1: Full AI agent. Every step through Claude. 47.4s Run 2: 9 Playwright steps + 1 agent step. 8.8s (5.4x faster) Run 5: 80% deterministic, 20% reasoning. ~3s ``` ## Install ```bash git clone https://github.com/sam-siavoshian/forged.git cd forged bash setup_mcp.sh ``` The wizard finds your Python, installs dependencies (`mcp`, `httpx`), and registers Forged with Claude Code at user or project scope. Works with any MCP-compatible assistant (Cursor, Windsurf, etc). After install, start the backend + frontend dev servers: ```bash ./dev.sh # backend on :8000, dashboard on :5173 ``` Set the keys from `.env.example` first: `ANTHROPIC_API_KEY`, `OPENAI_API_KEY`, `BROWSER_USE_API_KEY`, `SUPABASE_URL` / `SUPABASE_KEY` / `SUPABASE_SERVICE_ROLE_KEY` / `SUPABASE_DB_URL`. ## How it works ### The matching pipeline When your AI calls `run_browser_task("Search for keyboards on Amazon")`, three things happen: 1. **Domain extraction**. Regex pulls `amazon.com` from the task. Falls back to Claude Haiku if no URL is present ("Amazon" → `amazon.com`). 2. **Action classification**. Haiku classifies the task into one of 7 categories: `search`, `purchase`, `form_fill`, `navigate`, `extract`, `login`, `interact`. 3. **Vector similarity search**. The task is embedded via OpenAI `text-embedding-3-large` (3072 dimensions) and compared against stored templates using pgvector's `<=>` cosine distance operator. Filtered by domain and action type before the vector search even runs. If similarity is high enough (≥0.50), a template is matched. If not, the full agent runs and Forged learns a template from the trace. ### Confidence bands | Band | Similarity | What happens | | --------- | ---------- | --------------------------------------- | | Very High | ≥ 90% | Execute all rocket steps immediately | | High | 75-89% | Execute all rocket steps | | Medium | 50-74% | LLM verifies the match before executing | | No match | < 50% | Full agent, auto-learn template | Template confidence updates after every execution: success adds `+0.1 * (1 - confidence)`, failure subtracts `0.2 * confidence`. Templates that keep working gain confidence. Templates that break lose it fast. ### Template extraction After a successful agent run, Forged analyzes the trace and classifies each step: - **FIXED**. Same action and target every time. Navigate to URL, click a button, press Enter. Replayed via Playwright. - **PARAMETERIZED**. Same action, different value. Typing a search query into a fixed input field. Playwright fills the extracted parameter. - **DYNAMIC**. Requires reasoning. Choosing a product by price, answering a CAPTCHA, making a subjective decision. Handled by the AI agent. The `handoff_index` marks where Playwright stops and the agent takes over. Everything before it is deterministic. Everything after needs intelligence. ``` Template: "Search for {{query}} on Amazon" Step 0: navigate → amazon.com FIXED (Playwright) Step 1: click → search input FIXED (Playwright) Step 2: fill → search input with {{query}} PARAMETERIZED (Playwright) Step 3: press → Enter FIXED (Playwright) ─── handoff_index = 3 ─── Step 4: click → product matching criteria DYNAMIC (Agent) ``` ### Step filtering When a template has 10 steps but the task only needs 5, Forged doesn't blindly run all 10. Claude Haiku evaluates each step against the specific task and marks them `EXECUTE` or `SKIP`. If a step's parameter is missing from the task, it gets skipped. If the task is a subset of the template, only the relevant prefix executes. One Amazon template handles both "search for keyboards" (steps 0-3) and "search for keyboards and buy the cheapest one" (steps 0-7). ### The rocket engine Playwright connects to a cloud browser via CDP (Chrome DevTools Protocol) and replays template steps: 1. **Primary selector**. CSS selector with full timeout budget (capped at 8s). 2. **Fallback selectors**. Alternative CSS selectors with reduced timeout (1/3 budget, min 800ms). 3. **Role-based fallback**. `get_by_role("option")` for native `