
formfill-broker
io.github.gamai-io/formfill-broker
Isolated browser for form filling: open, snapshot, fill, verify and read OTP, with evidence.
Documentation
FormFill Broker
An isolated browser API: Chromium runs in a locked-down container and a small FastAPI service drives it over CDP, so an agent can fill web forms without ever holding the browser session itself. It also ships an MCP (stdio) server, so any MCP-capable client can call the same open / fill / verify / egress / OTP / upload primitives as tools. Field values are passed per request and are never stored by the broker:
docker build -t ff-browser . && bash scripts/slot_up.sh 0 && pip install -r requirements.txt && uvicorn app.broker:app --host 127.0.0.1 --port 8030
Broker listens on http://127.0.0.1:8030.
HTTP API
| Method | Path | Purpose |
|---|---|---|
| GET | /health | Broker and CDP health |
| POST | /open | Open a URL ({"url": "...", "slot"?: 0}) |
| GET | /snapshot | List visible interactive elements with refs |
| POST | /click | Click a snapshot ref ({"ref": "e3"}) |
| POST | /fill | Fill by ref/label/selector, optional submit ref |
| POST | /verify | Check text/url_contains, save screenshot evidence |
| POST | /otp | Read a verification code from an IMAP inbox (read-only) |
| POST | /upload | Decode base64 to a 0600 file under FF_UPLOADS, return sha256 |
| POST | /press, /type | Send a key or type text into the page |
| POST | /egress | Report browser public IP and geolocation |
| POST | /close | Close page and browser context |
MCP server
mcp_server.py is a stdio Model Context Protocol server (JSON-RPC 2.0,
one JSON object per line) that wraps the HTTP API. It uses only the Python
standard library and writes logs to stderr only, so stdout stays clean.
Tools:
formfill_open{url}formfill_snapshot{}formfill_fill{fields: [{ref|label|selector, value}], submit?}formfill_click{ref}formfill_verify{text?, url_contains?}formfill_egress{}formfill_close{}formfill_health{}
The broker URL defaults to http://127.0.0.1:8030 and can be overridden with
FF_BROKER_URL. Requests time out after 60 seconds.
opencode MCP config
{"mcp": {"formfill": {"type": "local", "command": ["python3","/path/to/formfill-broker/mcp_server.py"], "enabled": true}}}
Run and verify
# broker must already be running on 127.0.0.1:8030
python3 -m pytest tests -q
bash scripts/mcp_smoke.sh
scripts/mcp_smoke.sh sends initialize, notifications/initialized,
tools/list, and a formfill_health call, then prints every response.
OTP retrieval
Codes are read from an IMAP inbox with BODY.PEEK[], so messages stay unread.
FF_MAIL_ACCOUNTS=./mail_accounts.json python3 -m app.otp --account demo --timeout 60
mail_accounts.json is not part of this repo; supply your own:
{"accounts": [{"id": "demo", "email": "demo@example.com",
"imap": {"host": "imap.example.com", "port": 993, "tls": "SSL"},
"app_password": "<app password>"}]}
Browser slots
bash scripts/slot_up.sh 0 # start ff-slot0, CDP on 127.0.0.1:9330
bash scripts/slot_down.sh 0 # guarded: needs FF_ALLOW_SLOT0=1
Configuration
| Variable | Default | Meaning |
|---|---|---|
FF_CDP | http://127.0.0.1:9330 | Chrome DevTools endpoint |
FF_EVIDENCE | evidence | Screenshot output directory |
FF_UPLOADS | /tmp/ff_uploads | Upload directory (0700, files 0600) |
FF_MAIL_ACCOUNTS | mail_accounts.json | IMAP accounts file |
FF_MAIL_ACCOUNT | default | Default account id for /otp |
FF_SLOTS | 0,1,2 | Slots slot_up.sh may start |
FF_PROXY | socks5://172.17.0.1:1080 | Proxy passed to the container |
FF_EGRESS_HOST | — | user@host for scripts/egress_up.sh |
Screenshots in evidence/ are runtime output and are git-ignored.
Deployment (systemd)
Three units make the stack survive reboots. Unit files live in
/etc/systemd/system/.
| Unit | Type | Role |
|---|---|---|
ffbroker.service | simple, Restart=always | uvicorn app.broker:app on 127.0.0.1:8030 |
ff-iptables.service | oneshot, RemainAfterExit=yes, Before=docker.service | re-adds the rule that lets containers reach the SOCKS5 egress on 172.17.0.1:1080 (idempotent iptables -C ... || iptables -I ...) |
ff-slot0.service | oneshot, RemainAfterExit=yes, After=docker.service ff-iptables.service | scripts/slot_up.sh 0, ExecStop=docker rm -f ff-slot0 |
Install / enable (once):
systemctl daemon-reload
systemctl enable ff-iptables.service ffbroker.service ff-slot0.service
systemctl start ff-iptables.service
systemctl start ff-slot0.service
systemctl start ffbroker.service
Prerequisite for egress (not a unit; the SSH tunnel is external):
FF_EGRESS_HOST=user@egress-host.example bash scripts/egress_up.sh
Verify:
systemctl is-enabled ff-iptables ffbroker ff-slot0 # enabled enabled enabled
systemctl is-active ff-iptables ffbroker ff-slot0 # active active active
iptables -C INPUT -i docker0 -s 172.17.0.0/16 -p tcp --dport 1080 -j ACCEPT && echo rule-ok
curl -s http://127.0.0.1:8030/health # {"ok":true,...}
curl -s http://127.0.0.1:9330/json/version | jq -r .Browser
Restart cycle (container is recreated by the unit, not by docker alone):
systemctl stop ff-slot0 && systemctl start ff-slot0
curl -s http://127.0.0.1:9330/json/version # 200 after ~2 s
Notes:
- The container runs with
--restart unless-stoppedand no--removeflag, so a docker daemon restart brings it back without losing the name. ff-slot0.serviceis idempotent: ifff-slot0is already running the script exits 0 and leaves it alone; usedocker rm -f ff-slot0(orsystemctl restart ff-slot0) to apply new flags.iptablesis persisted byff-iptables.service. A snapshot is also kept at/etc/iptables/rules.v4(iptables-save), butnetfilter-persistentis not installed, so that file is a reference/restore artifact only.- Broker environment overrides: drop
KEY=valuelines in/etc/ffbroker.env(loaded viaEnvironmentFile=-/etc/ffbroker.env).
License
MIT — see LICENSE.
formfill-brokerpip install formfill-brokerRelated Servers
io.github.gamai-io/gama-decision-os
Decide before acting: allow/sandbox/ask/deny verdict with a decision hash, under 5 ms, no LLM call.
io.github.gamai-io/gama-fastpath
0-LLM pre-LLM gate: blocks destructive shell/SQL, answers money math offline.
io.github.gamai-io/gama-mandate
Signed, verifiable business commitments for AI agents: one-shot redeem, offline verify.