@coofly/agent-browser-mcp 1.0.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.
Files changed (69) hide show
  1. package/.dockerignore +7 -0
  2. package/CLAUDE.md +82 -0
  3. package/Dockerfile +41 -0
  4. package/LICENSE +674 -0
  5. package/README.md +191 -0
  6. package/README_ZH.md +191 -0
  7. package/config.example.yaml +44 -0
  8. package/dist/config.d.ts +43 -0
  9. package/dist/config.d.ts.map +1 -0
  10. package/dist/config.js +21 -0
  11. package/dist/config.js.map +1 -0
  12. package/dist/index.d.ts +3 -0
  13. package/dist/index.d.ts.map +1 -0
  14. package/dist/index.js +15 -0
  15. package/dist/index.js.map +1 -0
  16. package/dist/server.d.ts +43 -0
  17. package/dist/server.d.ts.map +1 -0
  18. package/dist/server.js +334 -0
  19. package/dist/server.js.map +1 -0
  20. package/dist/test-cli.d.ts +2 -0
  21. package/dist/test-cli.d.ts.map +1 -0
  22. package/dist/test-cli.js +22 -0
  23. package/dist/test-cli.js.map +1 -0
  24. package/dist/test.d.ts +2 -0
  25. package/dist/test.d.ts.map +1 -0
  26. package/dist/test.js +17 -0
  27. package/dist/test.js.map +1 -0
  28. package/dist/tools/advanced.d.ts +19 -0
  29. package/dist/tools/advanced.d.ts.map +1 -0
  30. package/dist/tools/advanced.js +40 -0
  31. package/dist/tools/advanced.js.map +1 -0
  32. package/dist/tools/information.d.ts +23 -0
  33. package/dist/tools/information.d.ts.map +1 -0
  34. package/dist/tools/information.js +41 -0
  35. package/dist/tools/information.js.map +1 -0
  36. package/dist/tools/interaction.d.ts +27 -0
  37. package/dist/tools/interaction.d.ts.map +1 -0
  38. package/dist/tools/interaction.js +49 -0
  39. package/dist/tools/interaction.js.map +1 -0
  40. package/dist/tools/navigation.d.ts +21 -0
  41. package/dist/tools/navigation.d.ts.map +1 -0
  42. package/dist/tools/navigation.js +37 -0
  43. package/dist/tools/navigation.js.map +1 -0
  44. package/dist/tools/storage.d.ts +16 -0
  45. package/dist/tools/storage.d.ts.map +1 -0
  46. package/dist/tools/storage.js +28 -0
  47. package/dist/tools/storage.js.map +1 -0
  48. package/dist/utils/configLoader.d.ts +19 -0
  49. package/dist/utils/configLoader.d.ts.map +1 -0
  50. package/dist/utils/configLoader.js +163 -0
  51. package/dist/utils/configLoader.js.map +1 -0
  52. package/dist/utils/executor.d.ts +26 -0
  53. package/dist/utils/executor.d.ts.map +1 -0
  54. package/dist/utils/executor.js +71 -0
  55. package/dist/utils/executor.js.map +1 -0
  56. package/package.json +35 -0
  57. package/src/config.ts +60 -0
  58. package/src/index.ts +16 -0
  59. package/src/server.ts +388 -0
  60. package/src/test-cli.ts +27 -0
  61. package/src/test.ts +20 -0
  62. package/src/tools/advanced.ts +55 -0
  63. package/src/tools/information.ts +54 -0
  64. package/src/tools/interaction.ts +74 -0
  65. package/src/tools/navigation.ts +51 -0
  66. package/src/tools/storage.ts +36 -0
  67. package/src/utils/configLoader.ts +195 -0
  68. package/src/utils/executor.ts +100 -0
  69. package/tsconfig.json +18 -0
package/.dockerignore ADDED
@@ -0,0 +1,7 @@
1
+ node_modules
2
+ dist
3
+ *.log
4
+ .git
5
+ .gitignore
6
+ *.md
7
+ .claude
package/CLAUDE.md ADDED
@@ -0,0 +1,82 @@
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ ## 项目概述
6
+
7
+ agent-browser-mcp 是一个 MCP (Model Context Protocol) 服务器,为 AI Agent 提供无头浏览器自动化能力。基于 [vercel-labs/agent-browser](https://github.com/vercel-labs/agent-browser),通过封装其 CLI 工具,将浏览器操作暴露为 MCP 工具供 AI 调用。
8
+
9
+ ## 常用命令
10
+
11
+ ```bash
12
+ # 安装依赖
13
+ npm install
14
+
15
+ # 构建项目
16
+ npm run build
17
+
18
+ # 开发模式(使用 tsx 直接运行 TypeScript)
19
+ npm run dev
20
+
21
+ # 生产模式运行
22
+ npm start
23
+
24
+ # 运行测试
25
+ npm test
26
+
27
+ # SSE 模式启动
28
+ npm start -- --sse --port 9223
29
+
30
+ # 连接远程 CDP 浏览器
31
+ npm start -- --cdp "http://localhost:9222"
32
+
33
+ # npx 执行方式(无需本地安装)
34
+ npx @coofly/agent-browser-mcp
35
+ npx @coofly/agent-browser-mcp --sse --port 9223
36
+ npx @coofly/agent-browser-mcp --cdp "http://localhost:9222"
37
+ ```
38
+
39
+ ## 架构概览
40
+
41
+ ```
42
+ src/
43
+ ├── index.ts # 入口,加载配置并启动服务器
44
+ ├── server.ts # MCP 服务器核心,处理 stdio/SSE 传输
45
+ ├── config.ts # 配置类型定义和默认值
46
+ ├── utils/
47
+ │ ├── configLoader.ts # 配置加载(优先级:CLI > 环境变量 > 文件 > 默认)
48
+ │ └── executor.ts # agent-browser CLI 命令执行器
49
+ └── tools/ # MCP 工具实现,按功能分类
50
+ ├── navigation.ts # 导航:open, back, forward, reload
51
+ ├── interaction.ts # 交互:click, type, fill, hover, press
52
+ ├── information.ts # 信息:snapshot, getText, getHtml
53
+ ├── storage.ts # 存储相关
54
+ └── advanced.ts # 高级:screenshot, scroll
55
+ ```
56
+
57
+ ### 核心流程
58
+
59
+ 1. **配置加载** (`configLoader.ts`): 支持 YAML 文件、环境变量、命令行参数,按优先级合并
60
+ 2. **服务器启动** (`server.ts`): 根据配置选择 stdio 或 SSE 传输模式
61
+ 3. **工具调用**: MCP 请求 → `handleToolCall` → 对应 tools 模块 → `executeCommand` → 调用 `agent-browser` CLI
62
+
63
+ ### 关键依赖
64
+
65
+ - `@modelcontextprotocol/sdk`: MCP 协议实现
66
+ - `yaml`: 配置文件解析
67
+ - 外部依赖: 需要系统安装 `agent-browser` CLI 工具
68
+
69
+ ## 配置方式
70
+
71
+ 复制 `config.example.yaml` 为 `config.yaml` 进行配置。支持三种配置来源:
72
+
73
+ | 来源 | 示例 |
74
+ |------|------|
75
+ | 配置文件 | `config.yaml` 中的 `cdp.endpoint` |
76
+ | 环境变量 | `CDP_ENDPOINT`, `MCP_TRANSPORT`, `MCP_PORT` |
77
+ | 命令行 | `--cdp`, `--sse`, `--port`, `--host` |
78
+
79
+ ## 传输模式
80
+
81
+ - **stdio**: 默认模式,用于 Claude Desktop 等本地集成
82
+ - **SSE**: HTTP 模式,端点 `/sse`(连接)、`/messages`(消息)、`/health`(健康检查)
package/Dockerfile ADDED
@@ -0,0 +1,41 @@
1
+ # 构建阶段
2
+ FROM node:20-alpine AS builder
3
+
4
+ WORKDIR /app
5
+
6
+ # 复制依赖文件
7
+ COPY package*.json ./
8
+
9
+ # 安装依赖
10
+ RUN npm ci
11
+
12
+ # 复制源代码
13
+ COPY tsconfig.json ./
14
+ COPY src/ ./src/
15
+
16
+ # 编译 TypeScript
17
+ RUN npm run build
18
+
19
+ # 运行阶段
20
+ FROM node:20-alpine
21
+
22
+ WORKDIR /app
23
+
24
+ # 复制依赖文件并安装生产依赖
25
+ COPY package*.json ./
26
+ RUN npm ci --omit=dev && npm cache clean --force
27
+
28
+ # 从构建阶段复制编译产物
29
+ COPY --from=builder /app/dist ./dist
30
+
31
+ # 复制配置文件模板
32
+ COPY config.example.yaml ./
33
+
34
+ # 环境变量
35
+ ENV NODE_ENV=production
36
+
37
+ # 暴露 SSE 端口
38
+ EXPOSE 9223
39
+
40
+ # 启动命令
41
+ CMD ["node", "dist/index.js"]