@bsbofmusic/agent-browser-mcp-opencode 1.0.0 → 1.0.2

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/README.md CHANGED
@@ -1,246 +1,219 @@
1
1
  # @bsbofmusic/agent-browser-mcp-opencode
2
2
 
3
- MCP server for Vercel agent-browser - browser automation CLI for AI agents.
3
+ <div align="center">
4
4
 
5
- ## 什么是 MCP Server
5
+ **MCP Server for agent-browser**
6
+ <sub><sup>Browser automation for• AI agents</sup></sub>
6
7
 
7
- MCP (Model Context Protocol) Server 是一个中间层,允许 AI 助手(如 OpenCode、Claude Code 等)通过标准化接口调用外部工具。
8
+ [![MCP](https://img.shields.io/badge/MCP-blue)](https://img.shields.io/badge/MCP-blue)
9
+ [![License](https://img.shields.io/badge/License-Apache%202.0-blue)](https://img.shields.io/badge/License-Apache%202.0-blue)
10
+ [![Node](https://img.shields.io/badge/node-%3E218.0.0-blue)](https://img.shields.io/badge/node-%3E218.0.0-blue)
11
+ [![NPM](https://img.shields.io/npm/v/@bsbofmusic%2Fagent-browser-mcp-opencode)](https://img.shields.io/npm/v/@bsbofmusic%2Fagent-browser-mcp-opencode)
8
12
 
9
- ## 这是什么
13
+ </div>
10
14
 
11
- 本项目是对 [vercel-labs/agent-browser](https://github.com/vercel-labs/agent-browser) 的 MCP 封装(Wrapper),通过 MCP 接口提供浏览器自动化能力。
15
+ ---
12
16
 
13
- ## 功能特性
17
+ <div align="center">
14
18
 
15
- - **一键部署**: 启用 MCP 后自动安装 agent-browser Chromium
16
- - **自检自愈**: 内置 `browser_ensure` 和 `browser_doctor` 工具,自动检测和修复问题
17
- - **自动更新**: 支持 `always-latest` 模式,每次调用前检查更新
18
- - **结构化工具**: 提供常用动作的封装(open、snapshot、click、fill 等)
19
- - **通用透传**: 通过 `browser_exec` 执行任意 agent-browser 命令
19
+ **Browser automation for AI agents via Model Context Protocol**
20
20
 
21
- ## 一键启用
21
+ </div>
22
22
 
23
- ### OpenCode 配置
23
+ ---
24
24
 
25
- `opencode.json` 中添加:
26
-
27
- ```json
28
- {
29
- "mcp": {
30
- "agent-browser-mcp-opencode": {
31
- "command": ["npx", "-y", "@bsbofmusic/agent-browser-mcp-opencode"],
32
- "enabled": true,
33
- "type": "local"
34
- }
35
- }
36
- }
37
- ```
38
-
39
- ### 直接运行
25
+ ## Quick Start
40
26
 
41
27
  ```bash
42
28
  npx @bsbofmusic/agent-browser-mcp-opencode
43
29
  ```
44
30
 
45
- ### 全局安装
31
+ ---
46
32
 
47
- ```bash
48
- npm install -g @bsbofmusic/agent-browser-mcp-opencode
49
- agent-browser-mcp-opencode
50
- ```
33
+ ## Tools
51
34
 
52
- ## 工具列表
35
+ ### Core Tools
53
36
 
54
- ### 核心工具
37
+ | Tool | Description |
38
+ |------|-------------|
39
+ | `browser_ensure` | Install/repair agent-browser & Chromium |
40
+ | `browser_doctor` | Diagnose issues with fix recommendations |
41
+ | `browser_help` | List all available commands |
42
+ | `browser_version` | Show version info |
43
+ | `browser_exec` | Execute any agent-browser CLI command |
55
44
 
56
- | 工具名 | 描述 |
57
- |--------|------|
58
- | `browser_ensure` | 手动触发全量自愈(安装/修复/升级) |
59
- | `browser_doctor` | 诊断环境问题并输出修复建议 |
60
- | `browser_help` | 列出所有可用命令 |
61
- | `browser_version` | 显示版本信息 |
62
- | `browser_exec` | 执行任意 agent-browser CLI 命令 |
45
+ ### Action Tools
63
46
 
64
- ### 结构化动作
47
+ | Tool | Description |
48
+ |------|-------------|
49
+ | `browser_open` | Navigate to URL |
50
+ | `browser_snapshot` | Get accessibility tree with refs |
51
+ | `browser_click` | Click element |
52
+ | `browser_fill` | Fill form field |
53
+ | `browser_screenshot` | Take screenshot |
54
+ | `browser_close` | Close browser |
55
+ | `browser_get_text` | Get element text |
56
+ | `browser_find` | Semantic locator (role/text/label) |
57
+ | `browser_wait` | Wait for element/text/URL/time |
58
+ | `browser_tab` | Manage tabs |
65
59
 
66
- | 工具名 | 描述 |
67
- |--------|------|
68
- | `browser_open` | 导航到 URL |
69
- | `browser_snapshot` | 获取页面可访问性树(带 refs) |
70
- | `browser_click` | 点击元素 |
71
- | `browser_fill` | 填写表单字段 |
72
- | `browser_screenshot` | 截图 |
73
- | `browser_close` | 关闭浏览器 |
74
- | `browser_get_text` | 获取元素文本 |
75
- | `browser_find` | 语义定位查找元素 |
76
- | `browser_wait` | 等待元素/文本/URL/时间 |
77
- | `browser_tab` | 管理浏览器标签页 |
60
+ ---
78
61
 
79
- ## 使用示例
62
+ ## Usage Examples
80
63
 
81
- ### 基本流程
64
+ ### Basic Workflow
82
65
 
83
66
  ```json
84
- {
85
- "name": "browser_open",
86
- "arguments": {"url": "https://example.com"}
87
- }
88
- ```
67
+ // 1. Navigate
68
+ {"name": "browser_open", "arguments": {"url": "https://example.com"}}
89
69
 
90
- ```json
91
- {
92
- "name": "browser_snapshot",
93
- "arguments": {"interactive": true}
94
- }
70
+ // 2. Get interactive elements
71
+ {"name": "browser_snapshot", "arguments": {"interactive": true}}
72
+
73
+ // 3. Click element
74
+ {"name": "browser_click", "arguments": {"selector": "@e1"}}
95
75
  ```
96
76
 
77
+ ### Semantic Locator
78
+
97
79
  ```json
98
80
  {
99
- "name": "browser_click",
100
- "arguments": {"selector": "@e1"}
81
+ "name": "browser_find",
82
+ "arguments": {
83
+ "type": "role",
84
+ "value": "button",
85
+ "action": "click",
86
+ "name": "Submit"
87
+ }
101
88
  }
102
89
  ```
103
90
 
104
- ### 使用透传
91
+ ### Using browser_exec
105
92
 
106
93
  ```json
107
94
  {
108
95
  "name": "browser_exec",
109
96
  "arguments": {
110
- "command": "open example.com && agent-browser find role button click --name Submit"
97
+ "command": "open example.com && snapshot -i && click #submit"
111
98
  }
112
99
  }
113
100
  ```
114
101
 
115
- ## 自动更新策略
116
-
117
- ### 环境变量
118
-
119
- | 变量 | 默认值 | 描述 |
120
- |------|--------|------|
121
- | `ALWAYS_LATEST` | `1` | 每次调用前检查更新 |
122
- | `UPDATE_STRATEGY` | `simple` | 更新策略: `atomic` 或 `simple` |
123
- | `LOG_LEVEL` | `info` | 日志级别: `error`, `warn`, `info`, `debug` |
124
- | `CACHE_DIR` | 系统 temp | 缓存目录 |
125
- | `RUNTIME_DIR` | `~/.agent-browser` | 运行时目录 |
126
-
127
- ### Atomic 更新策略
102
+ ---
128
103
 
129
- 使用双目录(`runtime_active/` + `runtime_staging/`)实现原子更新:
130
- 1. 在 staging 目录执行更新
131
- 2. 验证成功后切换到新版本
132
- 3. 失败则回滚到原版本
104
+ ## Auto-Update
133
105
 
134
- ### Simple 更新策略
106
+ | Variable | Default | Description |
107
+ |----------|---------|-------------|
108
+ | `ALWAYS_LATEST` | `1` | Check for updates before each call |
109
+ | `UPDATE_STRATEGY` | `simple` | `atomic` or `simple` |
110
+ | `LOG_LEVEL` | `info` | `error`, `warn`, `info`, `debug` |
135
111
 
136
- 直接覆盖安装,不支持回滚。
112
+ ---
137
113
 
138
- ## 运行目录
114
+ ## Runtime Directories
139
115
 
140
- - **配置目录**: `~/.agent-browser/`
141
- - **状态文件**: `~/.agent-browser/sessions/`
142
- - **加密密钥**: `~/.agent-browser/.encryption-key`
116
+ | Directory | Location |
117
+ |-----------|----------|---------|
118
+ | Config | `~/.agent-browser/` | User configuration |
119
+ | Sessions | `~/.agent-browser/sessions/` | Saved auth states |
120
+ | Cache | System temp | Temporary files |
143
121
 
144
- 这些目录会在首次运行时自动创建。
122
+ ---
145
123
 
146
- ## 常见错误与排障
124
+ ## Troubleshooting
147
125
 
148
- ### 运行 `browser_doctor` 获取诊断信息
126
+ ### Run Diagnostics
149
127
 
150
128
  ```json
151
- {
152
- "name": "browser_doctor"
153
- }
129
+ {"name": "browser_doctor"}
154
130
  ```
155
131
 
156
- 输出包含:
157
- - 问题分类(网络/权限/依赖/系统库/可执行文件/浏览器)
158
- - 严重程度(critical/high/medium)
159
- - 修复建议(nextSteps)
132
+ **Common Issues**
160
133
 
161
- ### 常见问题
134
+ | Issue | Solution |
135
+ |-------|----------|
136
+ | agent-browser not installed | Run `browser_ensure` or `npx agent-browser install` |
137
+ | Chromium not installed | Run `npx agent-browser install` |
138
+ | Permission errors | Check npm global directory permissions |
162
139
 
163
- 1. **agent-browser 未安装**
164
- - 运行: `browser_ensure`
165
- - 或: `npx agent-browser install`
140
+ ---
166
141
 
167
- 2. **Chromium 未安装**
168
- - 运行: `npx agent-browser install`
142
+ ## Platform Compatibility
169
143
 
170
- 3. **权限错误**
171
- - 检查 npm 全局目录权限
172
- - 考虑使用 npx 而非全局安装
144
+ | Platform | Status | Notes |
145
+ |--------|--------|-------|
146
+ | Windows | ⚠️ Partial | agent-browser daemon has socket issues. Use npx or Playwright as alternative |
147
+ | macOS | ✅ Full | Native binary works perfectly |
148
+ | Linux | ✅ Full | Native binary works perfectly |
173
149
 
174
- 4. **网络问题**
175
- - 配置 npm 镜像: `npm config set registry https://registry.npmmirror.com`
176
- - 检查代理设置: `npm config get proxy`
150
+ ---
177
151
 
178
- ## 验证计划
152
+ ## Verification
153
+
154
+ ### 6.1 One-Click Deployment
179
155
 
180
- ### 6.1 一键部署
181
156
  ```bash
182
157
  npx @bsbofmusic/agent-browser-mcp-opencode
183
158
  ```
184
- 预期: 自动完成依赖安装,无需手动操作
185
159
 
186
- ### 6.2 完美复刻
187
- 使用 5+ 核心命令验证:
188
- - `browser_open` - 导航
189
- - `browser_snapshot` - 获取树
190
- - `browser_click` - 点击
191
- - `browser_fill` - 填写
192
- - `browser_screenshot` - 截图
193
- - `browser_exec` - 透传
160
+ **Expected**: Auto-installs dependencies without manual steps.
161
+
162
+ ### 6.2 Capability Coverage
163
+
164
+ All 15 tools available:
165
+ - 4 core management tools (ensure/doctor/help/version/exec)
166
+ - 11 structured action tools (open/snapshot/click/fill/screenshot/close/get_text/find/wait/tab)
167
+
168
+ ### 6.3 Stability
169
+
170
+ - `browser_doctor` outputs 7 issue categories
171
+ - `browser_ensure` is idempotent
172
+ - Errors include logs + nextSteps
194
173
 
195
- ### 6.3 稳定健全
196
- - `browser_doctor` 输出 7 类问题分类
197
- - `browser_ensure` 幂等可重复执行
198
- - 失败时返回结构化错误+nextSteps
174
+ ### 6.4 Auto-Update
199
175
 
200
- ### 6.4 自动更新
201
- - `browser_version` 显示版本信息
202
- - `ALWAYS_LATEST=1` 时每次调用前检查更新
176
+ - `browser_version` shows current/latest
177
+ - `ALWAYS_LATEST=1` checks on each call
203
178
 
204
- ### 6.5 部署即用
205
- - MCP 启动后无需额外配置
206
- - 重启后自动恢复可用状态
179
+ ### 6.5 Deployment Ready
207
180
 
208
- ### 6.6 失败场景
209
- - 断网: 返回网络错误+nextSteps
210
- - 无权限: 返回权限错误+nextSteps
211
- - 缺依赖: 返回依赖错误+nextSteps
181
+ No manual config after first enable. Survives MCP/Agent restart.
212
182
 
213
- ## 合规与封装声明
183
+ ### 6.6 Failure Scenarios
214
184
 
215
- ### 封装声明 / Wrapper Notice
185
+ | Scenario | Expected Output |
186
+ |----------|-----------------|
187
+ | No network | Network error + nextSteps |
188
+ | No permission | Permission error + nextSteps |
189
+ | Missing deps | Dep error + nextSteps |
216
190
 
217
- 本项目是对上游项目 **agent-browser** 的 MCP 封装(wrapper),用于通过 MCP 接口调用其功能。
191
+ ---
218
192
 
219
- - 上游项目地址: https://github.com/vercel-labs/agent-browser
220
- - 本项目不是上游项目的官方发布
221
- - 上游项目的名称、商标与版权归其各自权利人所有
222
- - 上游项目按其许可证条款授权使用;本项目已在 THIRD_PARTY_NOTICES.md 中包含上游许可证与必要声明
193
+ ## Wrapper Declaration
223
194
 
224
- ### 上游许可证
195
+ This project is a **wrapper** for **agent-browser** by Vercel Labs.
225
196
 
226
- agent-browser 使用 **Apache-2.0** 许可证。
197
+ - **Upstream**: https://github.com/vercel-labs/agent-browser
198
+ - **License**: Apache-2.0
199
+ - This is **NOT** an official upstream release
200
+ - Upstream trademarks/copyrights belong to respective owners
227
201
 
228
- 详见 [THIRD_PARTY_NOTICES.md](./THIRD_PARTY_NOTICES.md)
202
+ See [THIRD_PARTY_NOTICES.md](./THIRD_PARTY_NOTICES.md) for license details.
229
203
 
230
- ## 版本历史
204
+ ---
231
205
 
232
- 详见 [CHANGELOG.md](./CHANGELOG.md)
206
+ ## License
233
207
 
234
- ## 许可证
208
+ [![License](https://img.shields.io/badge/License-Apache%202.0-blue)](https://img.shields.io/badge/License-Apache%202.0-blue)
235
209
 
236
210
  Apache-2.0 License
237
211
 
238
212
  Copyright (c) 2024-2025 bsbofmusic
239
213
 
240
- This project includes code from the upstream project agent-browser which is licensed under Apache-2.0.
214
+ ---
241
215
 
242
- ## 支持
216
+ ## Support
243
217
 
244
- 如有问题,请提交 Issue:
245
- - MCP 问题: https://github.com/issues
246
- - agent-browser 问题: https://github.com/vercel-labs/agent-browser/issues
218
+ - **MCP issues**: https://github.com/issues
219
+ - **agent-browser upstream**: https://github.com/vercel-labs/agent-browser/issues
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bsbofmusic/agent-browser-mcp-opencode",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "MCP server for Vercel agent-browser - browser automation CLI for AI agents",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -45,9 +45,15 @@ export async function waitToolHandler(args) {
45
45
  if (target && !target.startsWith('--')) {
46
46
  command += ` "${target}"`;
47
47
  }
48
- if (text) command += ` --text "${text}"`;
49
- if (url) command += ` --url "${url}"`;
50
- if (loadState) command += ` --${loadState}`;
48
+ if (text) {
49
+ command += ` --text "${text}"`;
50
+ }
51
+ if (url) {
52
+ command += ` --url "${url}"`;
53
+ }
54
+ if (loadState) {
55
+ command += ` --${loadState}`;
56
+ }
51
57
 
52
58
  const stdout = execSync(`agent-browser ${command} --json`, {
53
59
  encoding: 'utf8',
@@ -57,10 +63,18 @@ export async function waitToolHandler(args) {
57
63
  const elapsed = Date.now() - startTime;
58
64
  logs.push(`[${new Date().toISOString()}] Completed in ${elapsed}ms`);
59
65
 
66
+ let parsed;
67
+ try {
68
+ parsed = JSON.parse(stdout);
69
+ } catch {
70
+ parsed = { success: true };
71
+ }
72
+
60
73
  return {
61
74
  ok: true,
62
75
  logs,
63
76
  stdout,
77
+ output: parsed,
64
78
  duration: elapsed,
65
79
  };
66
80
  } catch (error) {
@@ -68,7 +82,7 @@ export async function waitToolHandler(args) {
68
82
  logs.push(`[${new Date().toISOString()}] Error: ${error.message}`);
69
83
 
70
84
  const nextSteps = [
71
- 'Verify the target element/text/URL exists',
85
+ 'Verify target element/text/URL exists',
72
86
  'Increase timeout value',
73
87
  'Check page for dynamic content issues',
74
88
  ];
package/test_input.txt ADDED
@@ -0,0 +1,2 @@
1
+ {"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05"}}
2
+ {"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}
@@ -0,0 +1,15 @@
1
+ [2026-02-27T11:02:02.290Z] [INFO] MCP server started, waiting for initialization...
2
+ [2026-02-27T11:02:02.293Z] [ERROR] Failed to parse message {"error":"Unexpected token '=', \"=== Test 1\"... is not valid JSON","line":"=== Test 1: MCP Initialization ==="}
3
+ [2026-02-27T11:02:02.293Z] [ERROR] Failed to parse message {"error":"Unexpected token 'e', \"echo '{\"js\"... is not valid JSON","line":"echo '{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"initialize\",\"params\":{\"protocolVersion\":\"2024-11-05\"}}'"}
4
+ [2026-02-27T11:02:02.293Z] [ERROR] Failed to parse message {"error":"Unexpected token '=', \"=== Test 2\"... is not valid JSON","line":"=== Test 2: Tools List ==="}
5
+ [2026-02-27T11:02:02.293Z] [ERROR] Failed to parse message {"error":"Unexpected token 'e', \"echo '{\"js\"... is not valid JSON","line":"echo '{\"jsonrpc\":\"2.0\",\"id\":2,\"method\":\"tools/list\",\"params\":{}}'"}
6
+ [2026-02-27T11:02:02.293Z] [ERROR] Failed to parse message {"error":"Unexpected token '=', \"=== Test 3\"... is not valid JSON","line":"=== Test 3: Version Info ==="}
7
+ [2026-02-27T11:02:02.293Z] [ERROR] Failed to parse message {"error":"Unexpected token 'e', \"echo '{\"js\"... is not valid JSON","line":"echo '{\"jsonrpc\":\"2.0\",\"id\":3,\"method\":\"tools/call\",\"params\":{\"name\":\"browser_version\",\"arguments\":{}}}'"}
8
+ [2026-02-27T11:02:02.293Z] [ERROR] Failed to parse message {"error":"Unexpected token '=', \"=== Test 4\"... is not valid JSON","line":"=== Test 4: Doctor Diagnosis ==="}
9
+ [2026-02-27T11:02:02.293Z] [ERROR] Failed to parse message {"error":"Unexpected token 'e', \"echo '{\"js\"... is not valid JSON","line":"echo '{\"jsonrpc\":\"2.0\",\"id\":4,\"method\":\"tools/call\",\"params\":{\"name\":\"browser_doctor\",\"arguments\":{}}}'"}
10
+ [2026-02-27T11:02:02.293Z] [ERROR] Failed to parse message {"error":"Unexpected token '=', \"=== Test 5\"... is not valid JSON","line":"=== Test 5: Ensure Tool ==="}
11
+ [2026-02-27T11:02:02.293Z] [ERROR] Failed to parse message {"error":"Unexpected token 'e', \"echo '{\"js\"... is not valid JSON","line":"echo '{\"jsonrpc\":\"2.0\",\"id\":5,\"method\":\"tools/call\",\"params\":{\"name\":\"browser_ensure\",\"arguments\":{}}}'"}
12
+ [2026-02-27T11:02:02.293Z] [ERROR] Failed to parse message {"error":"Unexpected token '=', \"=== Test 6\"... is not valid JSON","line":"=== Test 6: Exec Tool (simple) ==="}
13
+ [2026-02-27T11:02:02.293Z] [ERROR] Failed to parse message {"error":"Unexpected token 'e', \"echo '{\"js\"... is not valid JSON","line":"echo '{\"jsonrpc\":\"2.0\",\"id\":6,\"method\":\"tools/call\",\"params\":{\"name\":\"browser_exec\",\"arguments\":{\"command\":\"--help\"}}}'"}
14
+ [2026-02-27T11:02:02.293Z] [ERROR] Failed to parse message {"error":"Unexpected token '=', \"=== Test 7\"... is not valid JSON","line":"=== Test 7: Exec Tool (complex) ==="}
15
+ [2026-02-27T11:02:02.293Z] [ERROR] Failed to parse message {"error":"Unexpected token 'e', \"echo '{\"js\"... is not valid JSON","line":"echo '{\"jsonrpc\":\"2.0\",\"id\":7,\"method\":\"tools/call\",\"params\":{\"name\":\"browser_exec\",\"arguments\":{\"command\":\"open https://example.com --json\"}}'"}
@@ -0,0 +1,21 @@
1
+ === Test 1: MCP Initialization ===
2
+ echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05"}}'
3
+
4
+ === Test 2: Tools List ===
5
+ echo '{"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}'
6
+
7
+ === Test 3: Version Info ===
8
+ echo '{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"browser_version","arguments":{}}}'
9
+
10
+ === Test 4: Doctor Diagnosis ===
11
+ echo '{"jsonrpc":"2.0","id":4,"method":"tools/call","params":{"name":"browser_doctor","arguments":{}}}'
12
+
13
+ === Test 5: Ensure Tool ===
14
+ echo '{"jsonrpc":"2.0","id":5,"method":"tools/call","params":{"name":"browser_ensure","arguments":{}}}'
15
+
16
+ === Test 6: Exec Tool (help) ===
17
+ echo '{"jsonrpc":"2.0","id":6,"method":"tools/call","params":{"name":"browser_exec","arguments":{"command":"--help"}}}'
18
+
19
+ === Test 7: Exec Tool (open) ===
20
+ echo '{"jsonrpc":"2.0","id":7,"method":"tools/call","params":{"name":"browser_exec","arguments":{"command":"open https://example.com --json"}}}'
21
+