feat: initial MCP Browser Sidecar implementation

Playwright browser automation service for LLM-driven UI interaction.

Features:
- Session-based browser management with domain allowlisting
- HTTP API endpoints for browser actions (navigate, click, type, wait, screenshot, snapshot)
- Session lifecycle management (create, close, status)
- Automatic session cleanup (idle timeout, max lifetime)
- Resource limits (max sessions, max actions per session)
- Domain filtering via route interception

API Surface:
- POST /sessions - Create session with allowed_domains
- DELETE /sessions/{id} - Close session
- GET /sessions/{id}/status - Get session info
- POST /sessions/{id}/navigate - Navigate to URL
- POST /sessions/{id}/click - Click element
- POST /sessions/{id}/type - Type into element
- POST /sessions/{id}/wait - Wait for condition
- POST /sessions/{id}/screenshot - Capture screenshot
- POST /sessions/{id}/snapshot - Get accessibility tree

Security:
- Mandatory domain allowlist per session
- Network request filtering
- Session isolation via browser contexts

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2025-12-08 20:27:14 +01:00
commit 5851cb39f4
14 changed files with 1406 additions and 0 deletions

28
Dockerfile Normal file
View File

@@ -0,0 +1,28 @@
# MCP Browser Sidecar Dockerfile
# Based on Playwright's official Python image with Chromium pre-installed
FROM mcr.microsoft.com/playwright/python:v1.40.0-jammy
WORKDIR /app
# Copy requirements first for layer caching
COPY requirements.txt .
# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt
# Copy application code
COPY app/ ./app/
# Create screenshots directory
RUN mkdir -p /screenshots && chmod 777 /screenshots
# Expose port
EXPOSE 8931
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8931/health || exit 1
# Run the server
CMD ["uvicorn", "app.server:app", "--host", "0.0.0.0", "--port", "8931"]