gpm-browser
# GPM Browser — Antigravity (`agy`) MCP Plugin
Plugin MCP đa nền tảng cho **Antigravity (`agy`)** tích hợp **GPMLogin Local API v3** và **điều khiển trình duyệt anti-detect qua Playwright CDP**.
Thiết kế tương thích mọi máy:
- **Không gắn cứng đường dẫn cục bộ**: dùng `PLUGIN_ROOT` và `src/bootstrap.mjs`.
- **Tự động cài thư viện lần đầu**: khi cài trực tiếp từ GitHub bằng `agy plugin install`, `src/bootstrap.mjs` tự chạy `npm ci --omit=dev` (không tải thêm trình duyệt Playwright thừa) ngay lần khởi chạy đầu tiên.
- **Tự dò cổng GPMLogin**: ưu tiên `GPM_API_URL` → `GPM_PORT_FILE` → `%LOCALAPPDATA%\Programs\GPMLogin\api_port.dat` → mặc định `http://127.0.0.1:19995`.
- **Hỗ trợ điều khiển qua mạng LAN (macOS / Linux → Windows GPMLogin)**: tự động ánh xạ `remote_debugging_address` (`127.0.0.1:<port>`) sang host trong `GPM_API_URL` (hoặc `GPM_CDP_HOST`).
- **Bảo mật proxy mặc định**: tự động che mật khẩu trong `raw_proxy`.
---
## Yêu cầu
- **Node.js ≥ 20** (có sẵn `npm`)
- **Antigravity (`agy`)** (CLI hoặc Antigravity Desktop)
- **GPMLogin** đang chạy và bật Local API v3 (trên cùng máy Windows, hoặc máy Windows trong mạng LAN)
---
## Cài đặt nhanh (mọi máy)
### Cách 1: Cài trực tiếp từ GitHub bằng 1 lệnh (Khuyên dùng)
```powershell
agy plugin install https://github.com/luonghieu184/agy-gpm-mcp
```
> **Lưu ý trên Windows:** Nếu đang mở **Antigravity Desktop** và gặp lỗi `Access is denied` ở bước `rename` vào `~/.gemini/config/plugins`, hãy tạm đóng Antigravity Desktop, chạy lại lệnh trên rồi mở lại.
>
> Ở lần khởi chạy đầu tiên, `src/bootstrap.mjs` sẽ tự động cài 3 gói runtime (`@modelcontextprotocol/sdk`, `playwright-core`, `zod`) vào thư mục plugin. Các lần sau khởi chạy tức thì.
### Cách 2: Clone repo & chạy script cài tự động
**Windows (PowerShell):**
```powershell
git clone https://github.com/luonghieu184/agy-gpm-mcp.git
cd agy-gpm-mcp
.\scripts\install.ps1
# Hoặc tự động tạm tắt + mở lại Antigravity Desktop nếu bị khoá thư mục plugins:
.\scripts\install.ps1 -RestartAntigravity
```
**macOS / Linux:**
```bash
git clone https://github.com/luonghieu184/agy-gpm-mcp.git
cd agy-gpm-mcp
chmod +x scripts/install.sh
./scripts/install.sh
```
### Kiểm tra sau khi cài
```powershell
agy plugin list
```
Kết quả mong đợi:
```text
Installed plugins:
- gpm-browser (enabled, 1.0.0)
Source: antigravity
Components: 1 skill, 1 rule, 1 MCP server
```
---
## Cấu hình kết nối GPMLogin
| Biến môi trường | Mặc định | Mô tả |
|---|---|---|
| `GPM_API_URL` | *(tự dò)* | URL GPMLogin API v3, vd `http://127.0.0.1:19995` hoặc `http://192.168.1.50:19995` (LAN) |
| `GPM_PORT_FILE` | `%LOCALAPPDATA%\Programs\GPMLogin\api_port.dat` | Đường dẫn tuỳ chỉnh tới tệp `api_port.dat` của GPMLogin |
| `GPM_CDP_HOST` | *(theo host của `GPM_API_URL`)* | Ghi đè host khi kết nối CDP qua mạng LAN / SSH tunnel |
---
## Danh sách 21 MCP Tools
### 1. Quản lý GPMLogin (API v3 — 10 tools)
- `gpm_status` — Kiểm tra kết nối GPMLogin API, nguồn port và các phiên CDP đang mở
- `gpm_list_groups` — Liệt kê các group
- `gpm_list_profiles` — Liệt kê / tìm kiếm / phân trang profile (ẩn mật khẩu proxy mặc định)
- `gpm_get_profile` — Xem chi tiết 1 profile
- `gpm_create_profile` — Tạo profile mới (proxy, browser core, fingerprint, OS, WebRTC, ghi chú)
- `gpm_update_profile` — Cập nhật tên, group, proxy, startup URLs, ghi chú, user-agent, màu
- `gpm_delete_profile` — Xoá profile (`mode=1` chỉ DB, `mode=2` cả DB + thư mục)
- `gpm_start_profile` — Mở profile và tự động kết nối Playwright CDP (`auto_connect: true`)
- `gpm_close_profile` — Đóng profile và ngắt kết nối CDP
- `gpm_connect_cdp` — Kết nối CDP tới một profile đã mở sẵn
### 2. Điều khiển trình duyệt qua CDP (`gpm_browser_*` — 11 tools)
- `gpm_browser_tabs` — Liệt kê / mở / chuyển / đóng tab
- `gpm_browser_navigate` — Điều hướng URL, `back`, `forward`, `reload`
- `gpm_browser_snapshot` — Đọc nội dung văn bản và danh sách phần tử tương tác kèm selector gợi ý
- `gpm_browser_click` — Click theo CSS/Playwright selector hoặc toạ độ `(x, y)`
- `gpm_browser_type` — Nhập văn bản (hỗ trợ `delay_ms` gõ từng ký tự và `press_enter`)
- `gpm_browser_press` — Nhấn phím / tổ hợp phím
- `gpm_browser_select` — Chọn option trong `<select>`
- `gpm_browser_wait` — Chờ selector / URL / thời gian
- `gpm_browser_screenshot` — Chụp ảnh màn hình (trả ảnh trực tiếp cho AI + tuỳ chọn lưu ra tệp)
- `gpm_browser_evaluate` — Chạy JavaScript trong ngữ cảnh trang
- `gpm_browser_cookies` — Đọc / ghi / xoá cookies
---
## Kiểm thử
```powershell
# Kiểm tra chỉ đọc (không tạo/mở profile)
npm test
# Kiểm tra end-to-end thật trên GPMLogin (tạo profile tạm -> mở CDP -> duyệt web -> chụp ảnh -> đóng -> xoá sạch)
node tests/smoke.test.js --live
# Kiểm tra chuẩn manifest plugin Antigravity
agy plugin validate --strict .
```
## License
MIT
TDQS
Scored across 21 tools
Browser automation tools (navigate, click, type, select, wait, snapshot) each target a distinct action with clear boundaries. The only mild overlap is between gpm_start_profile and gpm_connect_cdp, since start_profile auto-connects CDP, but the descriptions distinguish the pre-opened versus fresh-launch cases.
All tools share a gpm_ prefix and the gpm_browser_* namespace is fully consistent. The management tools use varied verb prefixes (start, close, list, get, create, update, delete) that are readable but not uniformly namespaced under a profile_ grouping.
21 tools is on the heavier side but justified by serving two coherent domains: profile/group lifecycle management and browser automation. Each tool earns a distinct place, though the count sits near the upper reasonable bound.
Profile CRUD and browser interaction coverage is strong, covering navigation, form input, waits, snapshots, screenshots, JS evaluation, and cookies. Minor gaps exist: groups only support listing (no create/update/delete) and browser tools lack hover, drag, upload, or frame handling, but core workflows are covered.