rhai-mcp 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +11 -0
- package/.claude-plugin/plugin.json +7 -0
- package/.mcp.json +12 -0
- package/README.md +178 -0
- package/dist/agent.js +542 -0
- package/dist/agent.js.map +1 -0
- package/dist/browser.js +361 -0
- package/dist/browser.js.map +1 -0
- package/dist/cli.js +43 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.js +78 -0
- package/dist/config.js.map +1 -0
- package/dist/login.js +65 -0
- package/dist/login.js.map +1 -0
- package/dist/memory.js +266 -0
- package/dist/memory.js.map +1 -0
- package/dist/run.js +61 -0
- package/dist/run.js.map +1 -0
- package/dist/server.js +96 -0
- package/dist/server.js.map +1 -0
- package/dist/ui.js +206 -0
- package/dist/ui.js.map +1 -0
- package/package.json +34 -0
- package/prisma/schema.prisma +72 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "rhai",
|
|
3
|
+
"description": "A browser agent coding agents delegate manual web tasks to — enabling APIs, creating projects, generating keys in dashboards. Plans, acts, web-searches solutions, and self-corrects on roadblocks. Bundles the rhai MCP server.",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"author": { "name": "Aman Pandit" },
|
|
6
|
+
"keywords": ["mcp", "browser", "automation", "agent", "setup"]
|
|
7
|
+
}
|
package/.mcp.json
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
# Rhai — a browser agent with a brain, for coding agents
|
|
2
|
+
|
|
3
|
+
When you're working with a coding agent (Claude Code, Codex, Cursor) and it says *"now go to the Google Cloud Console and enable the Gmail API"* or *"create a project in Supabase and copy the anon key"* — that's the part where **you** stop and start clicking. Rhai removes that step.
|
|
4
|
+
|
|
5
|
+
Rhai is an **MCP server** that gives your coding agent a second agent: an autonomous browser operator that drives a real, already-logged-in Chrome. The coding agent delegates the manual web task; Rhai observes the page, acts, and **re-reasons on its own when it hits a roadblock** — a moved menu, a missing prerequisite, an error message, a wrong instruction. It reports back a summary plus any values you need (API keys, project IDs, URLs).
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
Claude Code (writing your app)
|
|
9
|
+
│ "user needs to enable the WhatsApp API in Google Cloud Console"
|
|
10
|
+
│ calls MCP tool: delegate_browser_task("Enable the WhatsApp Business API for project X")
|
|
11
|
+
▼
|
|
12
|
+
RHAI (this MCP server)
|
|
13
|
+
├─ drives a real Chrome using a persistent profile (already logged in)
|
|
14
|
+
├─ Claude loop: snapshot → act → snapshot → self-correct on roadblocks
|
|
15
|
+
└─ returns: "Done. API enabled. Here's the new key: ..." ← back to Claude Code
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## How it works
|
|
19
|
+
|
|
20
|
+
- **Delivery: MCP.** One server, usable by any agent that speaks the Model Context Protocol — Claude Code, Codex, Cursor, etc.
|
|
21
|
+
- **Hands: Playwright.** Drives a real Chromium. Rhai reads the page's accessibility/DOM tree, tags interactive elements with refs, and clicks/types by ref — fast and reliable on standard web apps like cloud consoles.
|
|
22
|
+
- **Brain: OpenAI GPT-5** (via the Responses API, with reasoning effort `high`). An agentic loop that follows a deliberate cycle: **recall → plan → act → detect failure → fix → verify → remember**. It writes an explicit plan, checks after each action whether it worked, and revises the plan when reality diverges.
|
|
23
|
+
- **Memory: Prisma + SQLite.** Every task, every action, and every distilled *learning* (the correct navigation path for a service, a non-obvious prerequisite, the fix to a roadblock) is stored in a local SQL database. Before each task it recalls what it learned on that service before; after, it writes new learnings — so run #2 on Google Cloud Console is faster and smarter than run #1.
|
|
24
|
+
- **Self-service research: web search.** When the agent hits a roadblock it can't solve from memory, it uses GPT-5's built-in `web_search` tool to look up how others solved that exact problem (it searches the error text or "how to X in <service>"), then revises its plan and tries the corrected approach.
|
|
25
|
+
- **Auth: a persistent browser profile.** You log into each service **once** (`npm run login`); the session is saved into a profile dir the agent reuses forever. The agent never handles your password or 2FA.
|
|
26
|
+
|
|
27
|
+
### The failure → fix loop
|
|
28
|
+
|
|
29
|
+
This is the core of the "comprehensive brain." After every action the agent asks: *did that do what I expected?* If a button is missing, a setting is greyed out, an error appears, or the page didn't change — that's a roadblock, and it does **not** blindly retry. Instead it:
|
|
30
|
+
|
|
31
|
+
1. Reasons about *why* it's stuck (the coding agent's suggested steps may be wrong/outdated/missing a prerequisite).
|
|
32
|
+
2. Checks **memory** for a known fix.
|
|
33
|
+
3. If still stuck, runs a **web search** for the solution.
|
|
34
|
+
4. Calls `set_plan` again with the corrected approach and continues.
|
|
35
|
+
5. **Verifies** the end state before declaring success, then **remembers** what worked.
|
|
36
|
+
|
|
37
|
+
## Setup
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npm install # downloads Chromium (Playwright) and generates the Prisma client
|
|
41
|
+
cp .env.example .env # then put your OPENAI_API_KEY in .env
|
|
42
|
+
npm run build
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
The memory database (`rhai.db`) is created automatically on first run — no migration step needed.
|
|
46
|
+
|
|
47
|
+
### 1. Log into the services you'll use (one time each)
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
rhai-mcp login https://console.cloud.google.com
|
|
51
|
+
rhai-mcp login https://supabase.com/dashboard
|
|
52
|
+
# (from a clone, before publishing: npm run login -- <url>)
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
A real Chrome window opens. Log in normally (including 2FA). Press **Enter** in the terminal to save the session. The agent reuses these logins from now on. The agent itself runs **headless** (no visible window) — set `RHAI_HEADLESS=false` when you want to watch it work. This `login` step always opens a window regardless, since you need to see it to sign in.
|
|
56
|
+
|
|
57
|
+
> **"This login window has none of my saved passwords!"** Right — Playwright launches an isolated profile by design, and Chrome 136+ blocks automation from touching your *default* profile (anti-cookie-theft). Two ways to fix it:
|
|
58
|
+
>
|
|
59
|
+
> **Quick:** logging in is one-time per service — paste from your password manager once, and the session persists forever. Add `RHAI_BROWSER_CHANNEL=chrome` to use your real Chrome binary (familiar UI, less bot-detection), though the profile is still fresh.
|
|
60
|
+
>
|
|
61
|
+
> **Best — use your real browser (saved passwords + extensions):** attach Rhai to a Chrome *you* launch on a dedicated, synced profile.
|
|
62
|
+
> 1. Launch Chrome with a debug port and a dedicated dir (macOS):
|
|
63
|
+
> ```bash
|
|
64
|
+
> "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" \
|
|
65
|
+
> --remote-debugging-port=9222 --user-data-dir="$HOME/.rhai-chrome"
|
|
66
|
+
> ```
|
|
67
|
+
> 2. In that window, sign into Chrome once and turn on **Sync** (your saved passwords flow in), **or** install your password-manager extension (1Password/Bitwarden) — both work because it's a real Chrome.
|
|
68
|
+
> 3. Set `RHAI_CDP_URL=http://localhost:9222` in `.env`.
|
|
69
|
+
>
|
|
70
|
+
> Now `rhai-mcp login` opens in *your* browser with autofill, and the agent attaches to that same Chrome (it disconnects when done — it never kills your browser).
|
|
71
|
+
|
|
72
|
+
### 2. Install it into your coding agent
|
|
73
|
+
|
|
74
|
+
Rhai is an MCP server, so any agent that speaks MCP can use it. Once installed, the agent **reaches for it automatically** — the server ships proactive `instructions` telling the agent to delegate any "go click through a website" step to Rhai, and it renders as a normal tool call in the agent's output.
|
|
75
|
+
|
|
76
|
+
> The commands below assume Rhai is published to npm as `rhai-mcp` (so `npx -y rhai-mcp` just works). Until then, swap `npx -y rhai-mcp` for `node /Users/amanpandit/Desktop/Rhai/dist/cli.js` to run your local build.
|
|
77
|
+
|
|
78
|
+
**Claude Code — as a plugin (one install, recommended):**
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
/plugin marketplace add amanpandit/rhai # or the path/URL to this repo
|
|
82
|
+
/plugin install rhai@rhai
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
The plugin bundles the MCP server ([.mcp.json](.mcp.json)) and registers it automatically.
|
|
86
|
+
|
|
87
|
+
**Claude Code — as a plain MCP server:**
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
claude mcp add rhai --env OPENAI_API_KEY=$OPENAI_API_KEY -- npx -y rhai-mcp
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
**Cursor** — add to `~/.cursor/mcp.json` (global) or `.cursor/mcp.json` (project):
|
|
94
|
+
|
|
95
|
+
```json
|
|
96
|
+
{
|
|
97
|
+
"mcpServers": {
|
|
98
|
+
"rhai": {
|
|
99
|
+
"command": "npx",
|
|
100
|
+
"args": ["-y", "rhai-mcp"],
|
|
101
|
+
"env": { "OPENAI_API_KEY": "${OPENAI_API_KEY}" }
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
**Codex CLI** — add to `~/.codex/config.toml`:
|
|
108
|
+
|
|
109
|
+
```toml
|
|
110
|
+
[mcp_servers.rhai]
|
|
111
|
+
command = "npx"
|
|
112
|
+
args = ["-y", "rhai-mcp"]
|
|
113
|
+
|
|
114
|
+
[mcp_servers.rhai.env]
|
|
115
|
+
OPENAI_API_KEY = "${OPENAI_API_KEY}"
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
That's it. Now when the agent's work hits a manual web step, it calls Rhai itself instead of telling you to go click — no prompting needed. You can still nudge it explicitly ("use rhai to …") if you want.
|
|
119
|
+
|
|
120
|
+
## Usage
|
|
121
|
+
|
|
122
|
+
Once wired up, your coding agent calls the `delegate_browser_task` tool on its own when it hits a manual web step. You can also nudge it:
|
|
123
|
+
|
|
124
|
+
> "Use the rhai tool to enable the Gmail API for my Google Cloud project `my-app`, then give me the steps to use it."
|
|
125
|
+
|
|
126
|
+
The tool takes:
|
|
127
|
+
- `task` (required) — the **goal** as an outcome, e.g. *"Enable the Gmail API for project my-app"*. Describe the destination, not the clicks — the agent figures out the path even if the suggested steps are slightly off.
|
|
128
|
+
- `start_url` (optional) — a page to open first.
|
|
129
|
+
- `context` (optional) — which account/project, specifics, or steps you think are involved.
|
|
130
|
+
|
|
131
|
+
It returns a status (`success` / `blocked`), a summary, and any concrete values (keys, IDs, URLs) verbatim.
|
|
132
|
+
|
|
133
|
+
## Configuration (`.env`)
|
|
134
|
+
|
|
135
|
+
| Var | Default | Purpose |
|
|
136
|
+
|---|---|---|
|
|
137
|
+
| `OPENAI_API_KEY` | — | **Required.** Powers the reasoning loop (GPT-5). |
|
|
138
|
+
| `RHAI_PROFILE_DIR` | `./.rhai-profile` | Where logged-in sessions are stored. |
|
|
139
|
+
| `RHAI_HEADLESS` | `true` | Agent runs headless. Set `false` to watch it work. |
|
|
140
|
+
| `RHAI_MODEL` | `gpt-5` | Model for the brain. |
|
|
141
|
+
| `RHAI_MAX_STEPS` | `40` | Max reason/act steps before giving up. |
|
|
142
|
+
| `DATABASE_URL` | `file:./rhai.db` | Where the persistent memory (SQLite) lives. |
|
|
143
|
+
|
|
144
|
+
## Safety notes
|
|
145
|
+
|
|
146
|
+
- The profile dir holds live logged-in sessions — it's gitignored; keep it private.
|
|
147
|
+
- The agent will not complete hard 2FA or knowingly take destructive actions without stopping; it reports `blocked` instead.
|
|
148
|
+
- It runs headless by default; set `RHAI_HEADLESS=false` the first few times so you can watch exactly what it does.
|
|
149
|
+
|
|
150
|
+
## Project layout
|
|
151
|
+
|
|
152
|
+
```
|
|
153
|
+
.claude-plugin/
|
|
154
|
+
plugin.json Claude Code plugin manifest
|
|
155
|
+
marketplace.json marketplace entry for one-line install
|
|
156
|
+
.mcp.json bundled MCP server config (used by the plugin / projects)
|
|
157
|
+
prisma/
|
|
158
|
+
schema.prisma Task / Action / Memory tables (SQLite)
|
|
159
|
+
src/
|
|
160
|
+
config.ts env/config + DB location + stderr logging
|
|
161
|
+
browser.ts Playwright persistent context + DOM snapshot + auth gate + actions
|
|
162
|
+
memory.ts Prisma-backed persistent memory (recall / remember / task log)
|
|
163
|
+
agent.ts the GPT-5 reasoning loop: recall → plan → act → fix → verify → remember
|
|
164
|
+
server.ts MCP server (proactive instructions + delegate_browser_task tool)
|
|
165
|
+
cli.ts binary entry: server (default) | login | task
|
|
166
|
+
login.ts one-time interactive login
|
|
167
|
+
run.ts direct single-task runner (for testing)
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## Inspecting memory
|
|
171
|
+
|
|
172
|
+
It's just a SQLite file. Browse it with `npx prisma studio` (opens a local UI), or query `rhai.db` with any SQLite client. The `Memory` table holds the reusable learnings; `Task` + `Action` hold the full transcript of every run.
|
|
173
|
+
|
|
174
|
+
## Roadmap ideas
|
|
175
|
+
|
|
176
|
+
- Screenshot/vision fallback when the DOM is unreadable (canvas-heavy UIs).
|
|
177
|
+
- A `wait_for_human` handoff for unavoidable 2FA/captcha mid-task.
|
|
178
|
+
- Periodic memory compaction (merge near-duplicate learnings per service).
|