Skip to content
Shell
10.4 KB
Raw Blame

omni.vu Enhanced MCP Server - Implementation Plan

Overview

Build an enhanced screen capture and GUI automation MCP server for macOS, combining the best features from competitors (Peekaboo, ACS Screenshot, Groundlight) into a Python-based solution.

Location: /Users/eddiebelaval/Development/id8/mcp-servers/omni-vu/ Platform: macOS only (simplifies development significantly) Language: Python with FastMCP Target Use Cases: Development feedback loop, automated testing/QA, agent automation, documentation


Project Structure

mcp-servers/omni-vu/
├── pyproject.toml
├── README.md
├── .env.example
├── src/
│   └── omni_vu/
│       ├── __init__.py
│       ├── server.py              # FastMCP entry point
│       ├── config.py              # Pydantic Settings configuration
│       │
│       ├── capture/               # Phase 1: Screen capture
│       │   ├── __init__.py
│       │   ├── base.py            # Abstract capturer
│       │   ├── full_screen.py     # Full screen (mss)
│       │   ├── window.py          # Window capture (CGWindowListCreateImage)
│       │   ├── region.py          # Region capture
│       │   ├── monitors.py        # Display enumeration
│       │   └── utils.py           # HiDPI, image processing
│       │
│       ├── vision/                # Phase 2: Multi-provider AI
│       │   ├── __init__.py
│       │   ├── base.py            # VisionProvider ABC
│       │   ├── claude.py          # Claude provider
│       │   ├── openai.py          # OpenAI GPT-4o
│       │   ├── gemini.py          # Google Gemini
│       │   ├── ollama.py          # Local Ollama
│       │   ├── factory.py         # Provider factory + fallback
│       │   └── optimization.py    # Image optimization per provider
│       │
│       ├── automation/            # Phase 3: GUI automation
│       │   ├── __init__.py
│       │   ├── mouse.py           # Click, move, drag, scroll
│       │   ├── keyboard.py        # Type, hotkey, press
│       │   ├── coordinates.py     # Retina/multi-monitor handling
│       │   ├── safety.py          # Rate limiting, dangerous action blocking
│       │   └── models.py          # Pydantic models
│       │
│       ├── tools/                 # MCP tool definitions
│       │   ├── __init__.py
│       │   ├── capture_tools.py   # vu, vu_window, vu_region
│       │   ├── query_tools.py     # vu_list_windows, vu_list_monitors
│       │   ├── vision_tools.py    # vu_describe
│       │   ├── automation_tools.py # vu_click, vu_type, etc.
│       │   └── utility_tools.py   # vu_diff, vu_history, vu_last, vu_status
│       │
│       ├── models/                # Shared Pydantic models
│       │   ├── __init__.py
│       │   ├── capture.py
│       │   ├── monitors.py
│       │   └── vision.py
│       │
│       └── history/               # Capture history
│           ├── __init__.py
│           └── manager.py
│
└── tests/
    ├── test_capture/
    ├── test_vision/
    └── test_automation/

Phase 1: Vision+ (Window & Region Capture)

New Tools

Tool Description
vu_window Capture specific window by title/ID
vu_region Capture specific screen region (x, y, w, h)
vu_list_windows List all windows with metadata
vu_list_monitors List all connected displays

Preserved Tools (from original)

  • vu - Full screen capture
  • vu_diff - Change detection
  • vu_history - Capture history
  • vu_last - Last capture
  • vu_status - System info

Key Implementation: Window Capture (PyObjC/CoreGraphics)

# capture/window.py - Core pattern
import Quartz
from Quartz import CGWindowListCopyWindowInfo, CGWindowListCreateImage

def capture_window(window_id: int) -> Image:
    cg_image = CGWindowListCreateImage(
        Quartz.CGRectNull,
        Quartz.kCGWindowListOptionIncludingWindow,
        window_id,
        Quartz.kCGWindowImageDefault
    )
    return cgimage_to_pil(cg_image)

Retina Support

  • Use NSScreen.mainScreen().backingScaleFactor() for scale detection
  • Provide both native (full pixels) and logical (scaled) output modes

Phase 2: Multi-Provider AI Vision

Enhanced vu_describe Tool

  • Supports: Claude, OpenAI GPT-4o, Gemini, Ollama (local)
  • Environment-based configuration
  • Automatic fallback chain
  • Image optimization per provider

Provider Abstraction Pattern

# vision/base.py
class VisionProvider(ABC):
    @abstractmethod
    async def analyze(self, image_base64: str, prompt: str) -> str:
        pass

    @abstractmethod
    async def is_available(self) -> bool:
        pass

# vision/factory.py
class VisionProviderFactory:
    fallback_chain = ["claude", "openai", "gemini", "ollama"]

    async def analyze_with_fallback(self, image: str, prompt: str) -> tuple[str, str]:
        for provider_name in self.fallback_chain:
            if await provider.is_available():
                try:
                    return await provider.analyze(image, prompt), provider_name
                except:
                    continue
        raise RuntimeError("All providers failed")

Configuration

# .env
OMNI_VU_ANTHROPIC_API_KEY=sk-ant-...
OMNI_VU_OPENAI_API_KEY=sk-...
OMNI_VU_GOOGLE_API_KEY=...
OMNI_VU_DEFAULT_PROVIDER=claude
OMNI_VU_FALLBACK_CHAIN=["claude","openai","gemini","ollama"]

Phase 3: GUI Automation

New Tools

Tool Description
vu_click Click at coordinates or element
vu_type Type text (with optional target)
vu_scroll Scroll up/down/left/right
vu_hotkey Press keyboard shortcuts
vu_drag Drag from point A to B
vu_move Move cursor without clicking

Backend: PyObjC + Quartz CGEvents

# automation/mouse.py - Core pattern
import Quartz

def click(point: tuple, button: str = "left", click_count: int = 1):
    event = Quartz.CGEventCreateMouseEvent(
        None,
        Quartz.kCGEventLeftMouseDown,
        point,
        Quartz.kCGMouseButtonLeft
    )
    Quartz.CGEventPost(Quartz.kCGHIDEventTap, event)

Safety Controls

  • Rate limiting (min 50ms between actions, max 20/sec)
  • Dangerous hotkey blocking (cmd+q, cmd+shift+q, etc.)
  • Restricted area protection (menu bar)
  • Max drag distance validation

Coordinate Handling

  • Logical (points) vs Physical (pixels) conversion for Retina
  • Multi-monitor coordinate validation
  • Screen bounds checking

Phase 4: Object Detection (Optional Enhancement)

Integration with Groundlight/mcp-vision Pattern

  • Add vu_detect tool for object detection
  • Use OwlViT or YOLO for specialized detection
  • Crop and zoom capabilities

Phase 5: Enterprise Features (Optional)

  • PII masking (OCR-based detection)
  • Audit logging
  • Rate limiting per client
  • Security policy configuration

Dependencies

# pyproject.toml
[project]
dependencies = [
    # Core MCP
    "fastmcp>=2.10.0",

    # Screen capture
    "mss>=9.0.0",
    "Pillow>=10.0.0",

    # macOS (PyObjC)
    "pyobjc-core>=10.0",
    "pyobjc-framework-Cocoa>=10.0",
    "pyobjc-framework-Quartz>=10.0",

    # AI Providers
    "anthropic>=0.30.0",
    "openai>=1.30.0",
    "google-generativeai>=0.5.0",
    "httpx>=0.27.0",

    # Configuration
    "pydantic>=2.5.0",
    "pydantic-settings>=2.1.0",
    "python-dotenv>=1.0.0",
]

Implementation Sequence

Week 1: Foundation + Phase 1

  1. Create project structure and pyproject.toml
  2. Implement config.py with Pydantic Settings
  3. Port existing omni.vu tools (vu, vu_diff, vu_history, vu_last, vu_status)
  4. Implement MonitorEnumerator (vu_list_monitors)
  5. Implement WindowCapturer (vu_window, vu_list_windows)
  6. Implement RegionCapturer (vu_region)
  7. Add Retina/HiDPI support

Week 2: Phase 2

  1. Implement VisionProvider ABC
  2. Implement ClaudeProvider (port from original)
  3. Implement OpenAIProvider
  4. Implement GeminiProvider
  5. Implement OllamaProvider
  6. Implement VisionProviderFactory with fallback
  7. Image optimization per provider
  8. Update vu_describe with provider selection

Week 3: Phase 3

  1. Implement coordinates.py (Retina handling)
  2. Implement safety.py (rate limiting, dangerous action blocking)
  3. Implement mouse.py (click, move, drag, scroll)
  4. Implement keyboard.py (type, hotkey, press)
  5. Create automation Pydantic models
  6. Add automation tools to server
  7. Integration testing

Week 4: Polish + Optional Phases

  1. Error handling refinement
  2. Documentation
  3. Claude Desktop integration testing
  4. Phase 4-5 if time permits

Critical Files to Create/Modify

Priority File Purpose
1 pyproject.toml Project config and dependencies
2 src/omni_vu/config.py Pydantic Settings configuration
3 src/omni_vu/server.py FastMCP server entry point
4 src/omni_vu/capture/window.py Window capture with PyObjC
5 src/omni_vu/capture/monitors.py Display enumeration
6 src/omni_vu/vision/factory.py Multi-provider factory
7 src/omni_vu/automation/mouse.py Mouse operations
8 src/omni_vu/automation/keyboard.py Keyboard operations
9 src/omni_vu/automation/safety.py Safety controls

macOS Requirements

  1. Screen Recording Permission: System Settings > Privacy & Security > Screen Recording
  2. Accessibility Permission: System Settings > Privacy & Security > Accessibility
  3. Python 3.10+ with PyObjC

MCP Configuration

// ~/.claude/mcp.json
{
  "mcpServers": {
    "omni.vu": {
      "command": "python",
      "args": ["/path/to/id8/mcp-servers/omni-vu/src/omni_vu/server.py"],
      "env": {
        "OMNI_VU_ANTHROPIC_API_KEY": "sk-ant-...",
        "OMNI_VU_DEFAULT_PROVIDER": "claude"
      }
    }
  }
}

Success Criteria

  • All original omni.vu tools working
  • Window and region capture functional
  • Multi-provider vision with fallback
  • Full GUI automation (click, type, scroll, hotkey, drag, move)
  • Retina/HiDPI support
  • Safety controls preventing dangerous actions
  • Integration with Claude Desktop verified