5.9 KiB
Firefox MCP Bridge
An MCP (Model Context Protocol) server that lets an LLM control a local Firefox instance through a browser extension. Uses a Bridge Architecture — no remote debugging, no automation flags — all interactions go through a Firefox extension's content scripts to mimic human behavior.
Architecture
LLM (MCP Client)
│ SSE + HTTP POST (port 8008)
▼
Python Bridge (FastAPI/Starlette)
│ WebSocket (ws://127.0.0.1:8008/ws)
▼
Firefox Extension (Background Script)
│ browser.tabs.sendMessage
▼
Content Script (DOM interaction in web pages)
Directory Layout
mcp-firefox-extension/
├── bridge/ # Python MCP server
│ ├── main.py # Starlette app (SSE + WebSocket)
│ ├── mcp_logic.py # MCP protocol + extension correlation
│ ├── config.py # Configuration (port 8008, etc.)
│ ├── requirements.txt # Python deps
│ └── tools/ # MCP tool handlers
│ ├── __init__.py # Tool registry
│ ├── utils.py # Shared helpers
│ ├── page_summary.py
│ ├── element_details.py
│ ├── click_element.py
│ ├── type_text.py
│ ├── press_key.py
│ ├── scroll_page.py
│ ├── execute_script.py
│ ├── take_screenshot.py
│ ├── read_page_text.py
│ ├── list_tabs.py
│ ├── switch_tab.py
│ ├── navigate_to.py
│ ├── open_new_tab.py
│ ├── get_current_url.py
│ └── get_page_cookies.py
├── extension/ # Firefox WebExtension
│ ├── manifest.json
│ ├── background.js # WebSocket client + browser.* APIs
│ └── content.js # DOM scanning + interaction
└── README.md
Setup
1. Create a Python virtual environment
Since your Python is system-managed, create a venv:
cd /home/matt/code/mcp-firefox-extension
python3 -m venv bridge/venv
source bridge/venv/bin/activate
pip install -r bridge/requirements.txt
2. Start the Bridge server
cd /home/matt/code/mcp-firefox-extension/bridge
source venv/bin/activate # if not already activated
python main.py
The server will listen on http://127.0.0.1:8008 and expose:
GET /sse— MCP SSE endpointPOST /messages— MCP message endpointWS /ws— WebSocket for the Firefox extension
3. Load the Firefox Extension
- Open Firefox and go to
about:debugging - Click "This Firefox" in the left sidebar
- Click "Load Temporary Add-on..."
- Select the
extension/manifest.jsonfile from this project - The extension will attempt to connect to
ws://127.0.0.1:8008/wsautomatically
You should see "Firefox extension connected via WebSocket" in the bridge server logs.
Note: Temporary add-ons are cleared when Firefox restarts. You'll need to reload the add-on via
about:debuggingafter each browser restart.
4. Connect your LLM client
Point your MCP client at the SSE endpoint:
- SSE URL:
http://127.0.0.1:8008/sse - Message URL:
http://127.0.0.1:8008/messages?session_id=<session-id>
The session ID is provided in the first SSE event (event: endpoint).
Available MCP Tools
| Tool | Description |
|---|---|
get_page_summary |
Scans the page and indexes interactive elements (buttons, links, inputs, etc.) with data-mcp-id attributes |
get_element_details(id) |
Returns detailed attributes, HTML, bounding box, and computed style for an element |
click_element(id) |
Clicks the element with the given mcp-id |
type_text(id, text) |
Focuses an element and types text into it |
press_key(key) |
Simulates a keyboard key press (Enter, Escape, Tab, etc.) |
scroll_page(direction, amount) |
Scrolls up/down/left/right by pixels or percentage |
execute_script(js_code) |
Executes arbitrary JavaScript in the page (God Mode) |
take_screenshot() |
Captures a PNG screenshot of the viewport |
read_page_text() |
Returns reader-mode text content of the page |
list_tabs() |
Lists all open Firefox tabs |
switch_tab(tab_id) |
Switches to a specific tab by ID |
navigate_to(url) |
Navigates the active tab to a URL |
open_new_tab(url) |
Opens a new tab |
get_current_url() |
Returns the current active tab's URL |
get_page_cookies() |
Returns cookies for the current domain |
How Element Indexing Works
When get_page_summary is called, the content script:
- Queries all interactive elements (
button,a,input,select,textarea, elements withroleattributes,onclickhandlers, orcontenteditable) - Assigns each a unique
data-mcp-idattribute (e.g.,data-mcp-id="1") - Returns a list with id, role, visible text, tag name, and other attributes
All subsequent interaction tools reference elements by this mcp-id, so you never need fragile CSS selectors.
Stealth
- No
remote-debugging-portis used - No
automationflags are set - All DOM interactions are triggered by the extension's content scripts, which run in the same context as normal page scripts
- The extension appears as a normal Firefox add-on
Troubleshooting
| Issue | Solution |
|---|---|
| "Firefox extension is not connected" | Make sure the bridge is running (python main.py) and the extension is loaded via about:debugging. Check the bridge logs for WebSocket connection messages. |
| "Content script not available in this tab" | Refresh the page or navigate to a different URL. Content scripts are injected on page load. |
| Extension won't load | Make sure you're using Firefox (not Chrome). Manifest V2 is used for better Firefox compatibility. |
port 8008 already in use |
Change config.PORT in bridge/config.py to another free port. |
License
MIT — "vibe-coded" prototype, use at your own risk.