omniparse-mcp: standalone OmniParser V2 parsing service + MCP shim
Self-contained: vendored util/ (CC BY 4.0, fixes noted in NOTICE), portable setup.sh (venv + weights + Pascal lane), start.sh with real-parse readiness gate, FastAPI service (bearer, serial GPU queue, LRU cache, OOM->503), MCP stdio shim (MCPServer 2.x, token strip), hardware-honest README.
This commit is contained in:
commit
2a4b1101e6
16 files changed
+2113
No files matched your search
@@ -0,0 +1,149 @@
|
||||
# omniparse-mcp
|
||||
|
||||
**Screenshot → structured, numbered, clickable elements — as a self-hosted HTTP
|
||||
service with an MCP tool wrapper.** Point it at any GUI screenshot and get back
|
||||
every interactable element with a caption, bounding box, and click coordinates
|
||||
(pixels and normalized). Built on [OmniParser V2](https://github.com/microsoft/OmniParser)
|
||||
(pure-vision pipeline: OCR + YOLOv9-E icon detection + Florence-2 captioning —
|
||||
no accessibility trees, works on any screen including video and remote desktops).
|
||||
|
||||
The point: give a vision LLM agent *eyes with coordinates*. Instead of sending
|
||||
a 1920×1080 image and hoping GPT-4V-class grounding lands, the agent gets a
|
||||
compact token-cheap list:
|
||||
|
||||
```
|
||||
id=22 center=(1008,402) caption="Notepad"
|
||||
id=57 center=(84,48) caption="File"
|
||||
```
|
||||
|
||||
## Architecture
|
||||
|
||||
```mermaid
|
||||
graph LR
|
||||
A[agent / script] -->|MCP stdio| B[mcp_server.py<br/>tiny shim]
|
||||
A2[any HTTP client] -->|POST /parse| C
|
||||
B -->|REST + bearer token| C[server.py<br/>FastAPI, queue, LRU cache]
|
||||
C --> D[engine.py<br/>EasyOCR → YOLOv9-E → Florence-2]
|
||||
D --> E[(one GPU)]
|
||||
```
|
||||
|
||||
One process owns the GPU (serial worker + bounded queue → `429` on overflow,
|
||||
no VRAM thrash). The MCP shim is a ~50-line stdio↔REST forwarder: restart your
|
||||
agent harness freely, the service (and its model load + warm cache) survives.
|
||||
Identical screenshots (same bytes + params) answer from cache in ~5 ms — the
|
||||
agent re-sending a screenshot across thinking turns is free.
|
||||
|
||||
## Requirements
|
||||
|
||||
- Linux, Python ≥ 3.10
|
||||
- **GPU: ≥ 6 GB VRAM** usable (models ~2.5 GB resident; OCR detection peak
|
||||
needs headroom — the service returns a clean `503` if the card is shared
|
||||
and full, never a corrupt partial parse). CPU works, painfully.
|
||||
- Pascal/Maxwell/Volta (GTX 900/10, TITAN X/P, V100): use `./setup.sh --pascal`
|
||||
— recent torch CUDA ≥ 12.8 wheels dropped these architectures.
|
||||
- ~1.8 GB of model weights (downloaded, not committed).
|
||||
|
||||
## Quick start
|
||||
|
||||
```bash
|
||||
git clone https://git.plean.rip/plean/omniparse-mcp.git && cd omniparse-mcp
|
||||
./setup.sh # venv + deps + weights (add --pascal for GTX 9/10 cards)
|
||||
./start.sh # starts, waits for models, smoke-tests a real parse
|
||||
curl -s http://127.0.0.1:8898/healthz
|
||||
```
|
||||
|
||||
`start.sh` readiness = an actual parse round-trip, not just "models loaded"
|
||||
(OCR loads lazily and its detection peak is where VRAM pressure bites).
|
||||
|
||||
Parse something:
|
||||
|
||||
```bash
|
||||
TOKEN=$(cat ~/.config/omniparse_token)
|
||||
python -c "import base64,json,urllib.request as u
|
||||
b = base64.b64encode(open('shot.png','rb').read()).decode()
|
||||
req = u.Request('http://127.0.0.1:8898/parse', data=json.dumps(
|
||||
{'image_b64': b, 'format': 'view'}).encode(),
|
||||
headers={'Authorization': f'Bearer $TOKEN'})
|
||||
print(json.loads(u.urlopen(req).read())['view'])"
|
||||
```
|
||||
|
||||
## REST API
|
||||
|
||||
Bearer auth on everything except `/healthz`. OpenAPI at `/docs`.
|
||||
|
||||
| Endpoint | Notes |
|
||||
|---|---|
|
||||
| `POST /parse` | `{image_b64, format: "view"\|"full", include_som?, box_thr?, iou_thr?, imgsz?, batch?, engine?}` |
|
||||
| `POST /parse_upload` | same params as fields, screenshot as multipart file |
|
||||
| `GET /healthz` | device, VRAM, queue depth, parse/cache counters |
|
||||
|
||||
Response fields: `elements[]` (`id, type, content, bbox_px, center_px,
|
||||
center_norm, source`), `view` (one line per element, ~12 tokens each), `image_size`,
|
||||
`timings`, `cache_hit`, optional `som_image_b64` (set-image overlay PNG).
|
||||
|
||||
Tunables (env): `OMNI_CUDA_DEVICE` (card; `-1` = CPU), `OMNI_API_PORT`,
|
||||
`OMNI_TOKEN_FILE`, `OMNI_MAX_QUEUE`, `OMNI_CACHE_MAX`, `OMNI_PYTHON`.
|
||||
|
||||
## MCP registration
|
||||
|
||||
Start the service first. Then any MCP harness — omp (`~/.omp/agent/mcp.json`):
|
||||
|
||||
```json
|
||||
{ "mcpServers": { "omniparse": {
|
||||
"command": "/path/to/omniparse-mcp/.venv/bin/python",
|
||||
"args": ["-m", "omni_api.mcp_server"],
|
||||
"cwd": "/path/to/omniparse-mcp",
|
||||
"timeout": 120000,
|
||||
"env": { "OMNI_API_URL": "http://127.0.0.1:8898",
|
||||
"OMNI_API_TOKEN": "!cat ~/.config/omniparse_token" } } } }
|
||||
```
|
||||
|
||||
The shim registers one tool, `omniparse(image_path | image_b64, format,
|
||||
include_som)`. In omp: `/mcp reload`, then `/mcp test omniparse`. The same
|
||||
entry works in Claude Desktop / Cursor-class harnesses; where `!cmd` env
|
||||
indirection isn't supported, inline the token string (and keep the file out of
|
||||
sync deliberately, or patch `OMNI_TOKEN_FILE`).
|
||||
|
||||
Remote agents: serve it on a LAN box — set `OMNI_API_URL` to
|
||||
`http://that.host:8898`, keep the token file client-side; only the shim
|
||||
speaks HTTP, agents never need GPU access.
|
||||
|
||||
## Measured performance
|
||||
|
||||
GTX 1070 Ti (8 GB, Pascal) / GTX 1080 Ti, torch 2.6+cu124, fp32 OCR + fp16
|
||||
Florence, 1920×1080 screenshots:
|
||||
|
||||
| Workload | Warm latency |
|
||||
|---|---|
|
||||
| Dense desktop (137 elements) | ~5 s (OCR ~4 s dominates) |
|
||||
| Simple app window (56 elements) | ~1.3 s |
|
||||
| Repeat of same screenshot | ~5 ms (cache) |
|
||||
| MCP round-trip incl. shim startup | +0.5–1 s over REST |
|
||||
|
||||
OCR-recognition-bound: 1080 Ti ≈ 1070 Ti here. Any sm_70+ card with more
|
||||
memory scales with batch size instead.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
- **`503 GPU out of memory (another process on the card?)`** — something else
|
||||
(a Jupyter kernel!) holds VRAM. Free it or move the service via
|
||||
`OMNI_CUDA_DEVICE`. Check `/healthz`.
|
||||
- **`429`** — queue full (default 8 waiters); service is serial by design.
|
||||
- **Slow first parse after boot (~10 s extra)** — lazy EasyOCR load, then warm.
|
||||
- **Silent 401s from MCP** — your harness doesn't expand `!cat …`; inline the token.
|
||||
- **`InvalidHeader` on first MCP call** — token env value carries a newline;
|
||||
this repo's shim strips it, but check your harness passes it cleanly.
|
||||
|
||||
## License
|
||||
|
||||
- This repo's service/shim/setup code (`omni_api/`, `start.sh`, `setup.sh`,
|
||||
`requirements.txt`): **MIT** (LICENSE).
|
||||
- `util/` is vendored from [microsoft/OmniParser](https://github.com/microsoft/OmniParser)
|
||||
under **CC BY 4.0** (LICENSE.upstream) with modifications noted in NOTICE —
|
||||
commercial use permitted with attribution.
|
||||
- Model weights (not committed; fetched by `setup.sh`): MIT / MIT-based,
|
||||
see NOTICE.
|
||||
- If you swap the icon detector to the ultralytics path, that component is AGPL.
|
||||
|
||||
Cite upstream: Lu et al., *OmniParser for Pure Vision Based GUI Agent*,
|
||||
arXiv:2408.00203.
|
||||
Reference in new issue
Block a user