agentbridge 0.3.0

Connect AI brains to local coding agents through MCP
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
# AgentBridge

**Use one AI to think and another AI to code.**

AgentBridge connects AI reasoning environments to local coding agents through **MCP (Model Context Protocol)**, allowing a web-based AI to understand and plan changes while a local coding agent executes them in your workspace.

> **Let the AI with the best reasoning access think. Let the coding agent you already use execute.**

[πŸ‡¨πŸ‡³ δΈ­ζ–‡](README_zh.md) Β· [πŸ“¦ crates.io](https://crates.io/crates/agentbridge) Β· [πŸ™ GitHub](https://github.com/IndexFlowing/AgentBridge)

[![Crates.io](https://img.shields.io/crates/v/agentbridge.svg)](https://crates.io/crates/agentbridge)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
[![Rust](https://img.shields.io/badge/rust-1.88%2B-orange.svg)](https://www.rust-lang.org/)

---

## Why AgentBridge?

AI coding tools increasingly combine two different jobs:

* **Reasoning** β€” understanding a codebase, investigating problems, designing solutions, and reviewing changes.
* **Execution** β€” editing files, running commands, running tests, and applying changes.

These two jobs do not necessarily need to be performed by the same AI.

You may have a web AI with generous usage and strong reasoning capabilities (such as Claude 3.7 Sonnet, o3-mini, or Gemini 2.5 Pro), while your local coding CLI has a more limited subscription quota.

Without a bridge, the coding agent has to spend its quota on everything:

```text
Understand β†’ Explore β†’ Reason β†’ Plan β†’ Code β†’ Test β†’ Review
```

AgentBridge separates the workflow:

```text
                 BRAIN
          Web-based AI
       Gemini / Claude / ...
                 β”‚
          Reason / Plan
                 β”‚
                MCP
                 β–Ό
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚   AgentBridge   β”‚ (Port 8030)
        β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                 β”‚
             C2C PLAN
                 β”‚
                 β–Ό
             EXECUTOR
          Local coding agent
             OpenCode
                 β”‚
        Edit / Run / Test
                 β”‚
                 β–Ό
       Local project(s)
```

The result is simple:

> **Use the AI that is best at thinking, and the coding agent that is best at doing.**

---

## The Core Idea

AgentBridge introduces two explicit roles.

### 🧠 Brain

The **Brain** is the AI responsible for reasoning.

It can:

* list and switch among mounted local projects;
* inspect the project and directory structure;
* search the codebase;
* read files;
* understand architecture and investigate bugs;
* create structured implementation plans (C2C PLAN);
* trigger execution via `task_start`;
* inspect Git diffs and test results;
* review the Executor's work.

The Brain interacts with the workspace through AgentBridge's **read-only MCP interface**. It does not directly execute arbitrary shell commands or overwrite files.

### πŸ› οΈ Executor

The **Executor** is the local coding agent responsible for execution.

It can:

* modify and create files;
* run build and test commands;
* implement the Brain's plan;
* report execution results.

AgentBridge currently features **OpenCode** as its primary Executor. The architecture is designed so additional coding agents (Claude Code, Aider, Codex) can be supported in the future.

### πŸŒ‰ AgentBridge

AgentBridge connects the two.

It provides:

* Streamable HTTP MCP server;
* MCP OAuth 2.1 for ChatGPT / Gemini custom MCP connections;
* multi-project workspace hosting in a single process;
* safe read-only project inspection (sandboxed per project);
* structured task delegation (C2C Protocol);
* autonomous task supervisor (`task_start`, `task_status`, `task_cancel`);
* live terminal output streaming (`mode = "stream"`);
* automatic reasoning token (`<think>`) stripping;
* Git diff & untracked file capture;
* test status reporting.

---

## How It Works

A typical workflow looks like this:

```text
User
 β”‚
 β–Ό
Brain (Claude / ChatGPT / Gemini)
 β”‚
 β”œβ”€β”€ list_projects / switch_project (when several repos are mounted)
 β”œβ”€β”€ Inspect workspace (workspace_info, search_workspace, read_file)
 β”œβ”€β”€ Understand architecture & formulate PLAN
 └── Call task_start
          β”‚
          β–Ό
     AgentBridge (v0.3.0)
          β”‚
       C2C PLAN
          β”‚
          β–Ό
      Executor (OpenCode CLI)
          β”‚
   β”œβ”€β”€ Edit files
   β”œβ”€β”€ Run commands
   └── Run tests
          β”‚
          β–Ό
    Git Diff / Result
          β”‚
          β–Ό
        Brain
          β”‚
       Review (git_diff / test_status)
          β”‚
     β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”
     β”‚         β”‚
    DONE    PLAN AGAIN
```

This creates an autonomous feedback loop:

```text
PLAN β†’ EXECUTE β†’ REVIEW β†’ DONE
             ↑            β”‚
             └── PLAN β”€β”€β”€β”€β”˜
```

---

## MCP: Giving the Brain Access to Your Workspace

AgentBridge uses the **Model Context Protocol (MCP)** to expose your local project and task controls to the Brain.

### Inspection Tools (Read-Only & Safe)

| Tool                | Description                                                  |
| ------------------- | ------------------------------------------------------------ |
| `list_projects`     | List mounted workspaces (name, path, description, active)    |
| `switch_project`    | Change this session's active project                         |
| `workspace_info`    | Inspect workspace path, project types (Rust, Node, Python, Go), and Git repository state |
| `list_directory`    | Traversal-safe structured directory listing                  |
| `read_file`         | Read UTF-8 files (size-capped, binaries & secrets denied)    |
| `search_workspace`  | High-speed keyword search with smart ignores (`node_modules`, `target`, `.git`) |
| `git_status`        | Inspect branch, changed, staged, and untracked files         |
| `git_diff`          | Working tree or staged diff (automatically formats newly-created untracked files) |
| `test_status`       | Read the latest recorded test execution result               |
| `execution_summary` | Read structured summary of the latest iteration              |

### Execution & Control Tools (Autonomous)

| Tool          | Description                                                  |
| ------------- | ------------------------------------------------------------ |
| `task_start`  | Spawns local OpenCode with a validated `C2cPlan`             |
| `task_status` | Polls task lifecycle: `running` \| `success` \| `failed` \| `cancelled` |
| `task_cancel` | Terminates the running executor process tree safely          |

Inspection and executor tools accept an optional `project` argument. If omitted, they use the session's active project (set by `switch_project`, or the configured default). Paths cannot escape that project's root.

---

## C2C: Brain-to-Executor Communication

AgentBridge standardizes agent communication using lightweight **C2C (Context-to-Context)** messages:

```text
[C2C]
STATE: PLAN
TASK_ID: c2c_20260830_001
ITERATION: 1

GOAL:
Add URL inspection support to the GSC client.

ACTIONS:
1. Inspect the existing GSC client.
2. Add URL inspection support.
3. Add tests for indexed and non-indexed URLs.

TESTS:
cargo test

SUCCESS_CRITERIA:
Tests pass and the API correctly reports indexed / non-indexed.
```

The source code remains in the local workspace. Only the structured task contract crosses the boundary, minimizing context token consumption.

---

## Quick Start

### 1. Install

Install via Cargo:

```bash
cargo install agentbridge
```

Verify the installation:

```bash
agentbridge --version
```

You can also download pre-built binaries from [GitHub Releases](https://github.com/IndexFlowing/AgentBridge/releases).

#### Build from source:

```bash
git clone https://github.com/IndexFlowing/AgentBridge.git
cd AgentBridge

cargo install --path .
```

### 2. Initialize Your Project

```bash
cd /path/to/your/project
agentbridge init . --port 8030
```

Check your environment:

```bash
agentbridge doctor
```

### 3. Start AgentBridge

```bash
agentbridge serve
```

By default, AgentBridge listens on:

```text
http://127.0.0.1:8030/mcp
```

OAuth 2.1 is enabled by default. The startup banner prints the mounted workspaces, the auth mode, and (if you did not set one) a generated **Admin PIN** for `/oauth/authorize`.

```text
➜  Workspaces  : [default] (1 mounted)
➜  MCP Endpoint: http://127.0.0.1:8030/mcp (Streamable HTTP)
➜  Auth        : OAuth 2.1 Enabled (/oauth/authorize)
➜  Admin PIN   : a1b2-c3d4-e5f6
```

Use `--dev` / `--no-auth` only for trusted localhost debugging.

---

## Multi-project workspaces

A single AgentBridge process can host several local repositories.

### Single directory

```bash
agentbridge serve D:\Project\MyProject
```

That directory becomes a project named `default`.

### Several repositories

Create `agentbridge.config.json` (see `examples/agentbridge.config.json`):

```json
{
  "projects": [
    {
      "name": "indexflow-core",
      "path": "D:\\Project\\IndexFlow\\IndexFlow-core",
      "description": "IndexFlow core backend and engine",
      "readonly": false
    },
    {
      "name": "mandarin-clips",
      "path": "D:\\Project\\MandarinClips",
      "description": "MandarinClips web platform and media tools",
      "readonly": false
    }
  ],
  "default_project": "indexflow-core"
}
```

Then:

```bash
agentbridge serve --workspaces agentbridge.config.json
```

If `agentbridge.config.json` is in the current directory, `agentbridge serve` picks it up automatically.

The Brain should call `list_projects` first, then either `switch_project` or pass `project` on individual tools. Each call is sandboxed to that project's root; `../` cannot reach a sibling repo. `task_start` is rejected on `readonly` projects.

---

## Authentication (OAuth 2.1)

ChatGPT and Gemini Web custom MCP connections expect the MCP OAuth 2.1 protected-resource flow. AgentBridge implements it in-process:

| Endpoint | Role |
| -------- | ---- |
| `GET /.well-known/oauth-protected-resource` | RFC 9728 resource metadata (`resource`, `authorization_servers`, `mcp:read` / `mcp:write`) |
| `GET /.well-known/oauth-authorization-server` | RFC 8414 discovery (`/oauth/authorize`, `/oauth/token`, PKCE S256) |
| `GET/POST /oauth/authorize` | Browser consent page (Admin PIN) β†’ redirect with `code` and `state` |
| `POST /oauth/token` | Exchange `code` + `code_verifier` for `access_token` / `refresh_token` |
| `POST /oauth/register` | RFC 7591 dynamic client registration (used by ChatGPT / Gemini) |

Unauthenticated requests to `/mcp` return:

```http
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer realm="mcp", resource_metadata="https://<host>/.well-known/oauth-protected-resource"
```

A valid `Authorization: Bearer <token>` (OAuth access token **or** static `--auth-token`) grants access.

### Configuration

CLI flags override environment variables and `.env` / `.agentbridge.env` in the current directory:

| Flag / env | Purpose |
| ---------- | ------- |
| `--admin-password` / `AGENTBRIDGE_ADMIN_PASSWORD` | PIN shown on the authorize page (generated if unset) |
| `--client-id` / `AGENTBRIDGE_CLIENT_ID` | Optional pre-registered OAuth client |
| `--client-secret` / `AGENTBRIDGE_CLIENT_SECRET` | Optional client secret |
| `--auth-token` / `AGENTBRIDGE_AUTH_TOKEN` | Extra static Bearer token (ChatGPT can use this instead of OAuth) |
| `--no-auth` / `--dev` / `AGENTBRIDGE_NO_AUTH` | Disable the 401 challenge (localhost only) |
| `--allow-any-host` | Required for Cloudflare Tunnel `Host` headers |

---

## Connecting Your Brain

### Option A: Claude Desktop (Zero-API, 100% Free)

Open `%APPDATA%\Claude\claude_desktop_config.json` (Windows) or `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS):

```json
{
  "mcpServers": {
    "agentbridge": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-remote",
        "http://127.0.0.1:8030/mcp"
      ]
    }
  }
}
```

*Restart Claude Desktop. The πŸ”¨ icon will appear with all AgentBridge tools loaded.*

For local Claude Desktop you can start with `agentbridge serve --dev` so the proxy does not need a Bearer token.

### Option B: Remote Web AI via Cloudflare Tunnel (Gemini / ChatGPT)

```bash
agentbridge serve --allow-any-host
```

In another terminal, expose port 8030:

```bash
cloudflared tunnel --url http://127.0.0.1:8030
```

Point the remote MCP client at:

```text
https://<your-tunnel-id>.trycloudflare.com/mcp
```

1. ChatGPT / Gemini will receive `401` and start OAuth discovery.
2. Complete the in-browser `/oauth/authorize` page with the **Admin PIN** from the AgentBridge banner.
3. Alternatively, start with `--auth-token` and paste `Authorization: Bearer <token>` in the client.

Paste `skill/SKILL.md` into the system instructions / skill slot so the model behaves as the Brain (`list_projects`, inspect, `task_start` β€” never edit files itself).

---

## Configuration (`.agentbridge.toml`)

`agentbridge init` generates a project-level configuration:

```toml
workspace = "D:\\Project\\MyProject"
host = "127.0.0.1"
port = 8030
allow_any_host = false                    # Set true when routing via Cloudflare Tunnel
auth_token = "optional_bearer_token"      # Optional static Bearer; OAuth 2.1 is on by default

[executor]
type = "opencode"
command = "opencode"                      # On Windows with global npm, use "opencode.cmd"
mode = "stream"                           # "stream" (live terminal output) or "silent" (quiet background)

[security]
max_file_size = 1048576                   # 1MB
deny_sensitive_files = true               # Denies .env, *.pem, *.key, id_rsa
max_diff_bytes = 65536                    # Truncates diffs over 64KB
```

Server listen settings still come from `.agentbridge.toml` (or `~/.agentbridge/config.toml`). Mounted repositories come from `agentbridge.config.json`, `--workspaces`, or `agentbridge serve <dir>`.

> πŸ’‘ **Windows Tip**: If OpenCode is installed globally via npm, set `command = "opencode.cmd"` (or the absolute path) to ensure Windows invokes the batch wrapper rather than the POSIX shell script (preventing `os error 193`).

---

## CLI Reference

```bash
# Initialize project workspace
agentbridge init <workspace> --port 8030

# Start MCP server (loads .agentbridge.toml / agentbridge.config.json)
agentbridge serve

# Single directory as project `default`
agentbridge serve D:\Project\MyProject --allow-any-host

# Multiple repositories
agentbridge serve --workspaces agentbridge.config.json

# Skip OAuth on localhost
agentbridge serve --dev

# Set the authorize-page PIN and an extra static Bearer token
agentbridge serve --admin-password "my-pin" --auth-token "$TOKEN"

# Inspect workspace, git, and executor status
agentbridge status

# Diagnose environment, git, and OpenCode installation
agentbridge doctor

# Manually start a task from CLI and execute synchronously
agentbridge task start --goal "..." --execute

# Cancel running executor task
agentbridge task cancel
```

---

## Security

AgentBridge is built with defensive defaults:

* **Explicit Read-Only View**: The remote Brain cannot execute arbitrary shell commands or overwrite files.
* **Deny-by-Default File Access**: Restricts path traversal (`../`) and sensitive file patterns (`.env`, `credentials`, `id_rsa`, `*.pem`).
* **Per-project sandbox**: Every tool call is confined to the selected project's root. Sibling workspaces are not reachable via `../` or an absolute path.
* **Process isolation**: The Executor is started with cwd set to that project directory.
* **Authentication**: MCP OAuth 2.1 (authorization code + PKCE, dynamic client registration) for ChatGPT / Gemini custom MCP, plus optional static Bearer `auth_token`. Unauthenticated `/mcp` returns `401` with `WWW-Authenticate`.
* **Public URLs**: Leave OAuth enabled (or set `--auth-token`) whenever you tunnel the endpoint. Use `--no-auth` / `--dev` only on trusted loopback.

See [docs/security.md](docs/security.md) for the full model.

---

## License

MIT License Β© [AgentBridge Contributors](LICENSE)