VI

Video Still Capture MCP Server for OpenCV Cameras

Capture high-quality video stills from OpenCV cameras with an easy-to-deploy MCP server for webcams and other video sources.

Quick Install
npx -y @13rac1/videocapture-mcp

Overview

This MCP (Model Context Protocol) server captures high-quality still frames from OpenCV-compatible video sources (webcams, USB cameras, RTSP/HTTP streams) and exposes them as simple HTTP/MCP tools. It is designed for developers who need deterministic single-frame captures for testing, dataset collection, monitoring, or to provide visual context to agent workflows. Deploying the server gives you a low-latency API that can be called by local scripts, CI jobs, or agent systems that support MCP-style tool integrations.

The server focuses on predictable frame grabs: it configures capture parameters (resolution, pixel format, exposure hints) and returns images in a format convenient for downstream processing (binary image response, base64 payload, or a small JSON metadata envelope). Because it leverages OpenCV, you can use it with nearly any camera source supported by your OS and OpenCV build.

Features

  • Capture a single, high-quality still frame from a selected OpenCV video source
  • Support for webcams, USB cameras, and network streams (RTSP/HTTP)
  • Configurable capture parameters: camera index/URL, width, height, exposure hints, color conversion
  • Multiple output formats: image file (JPEG/PNG), base64-encoded image in JSON, or direct binary image response
  • Simple HTTP API compatible with MCP-style tool invocation patterns
  • Lightweight Python implementation using OpenCV and a minimal web framework (Flask/FastAPI)
  • Docker-friendly for easy deployment

Installation / Configuration

Prerequisites:

  • Python 3.8+
  • OpenCV (opencv-python or opencv-python-headless)
  • A camera device or accessible video stream

Install with pip:

python -m venv venv
source venv/bin/activate
pip install opencv-python flask requests  # or fastapi+uvicorn

Run locally (example with Flask-based server script named server.py):

export CAMERA_SOURCE=0        # device index or RTSP/HTTP URL
export WIDTH=1280
export HEIGHT=720
export PORT=8080

python server.py

Docker deploy (example Dockerfile usage):

FROM python:3.10-slim
WORKDIR /app
COPY . /app
RUN pip install --no-cache-dir -r requirements.txt
ENV CAMERA_SOURCE=0 WIDTH=1280 HEIGHT=720 PORT=8080
CMD ["python", "server.py"]

Build and run:

docker build -t videocapture-mcp .
docker run --device=/dev/video0 -e CAMERA_SOURCE=0 -p 8080:8080 videocapture-mcp

Environment variables and common options:

VariableDefaultDescription
CAMERA_SOURCE0OpenCV camera index or stream URL (rtsp://, http://)
WIDTH1280Desired capture width
HEIGHT720Desired capture height
PORT8080HTTP port to listen on
FORMATjpegOutput format: jpeg or png
TIMEOUT_MS2000Capture timeout in milliseconds

Available Tools / Resources

The server provides a small set of HTTP endpoints suitable for programmatic use:

  • GET /health
    • Returns 200 when server and camera are accessible.
  • POST /capture
    • Request body (JSON) options: camera_source, width, height, format, encode_base64 (bool)
    • Response: image binary (Content-Type: image/jpeg/png) or JSON with base64 image and metadata.
  • GET /capture?camera_source=…&width=…&height=…&format=…
    • Shortcut for quick GET-based captures.

Example JSON response (when encode_base64=true):

{
  "timestamp": "2026-04-10T12:34:56.789Z",
  "camera_source": "0",
  "width": 1280,
  "height": 720,
  "format": "jpeg",
  "image_b64": "/9j/4AAQSkZJRgABAQAAAQ..."
}

Repository and reference:

  • GitHub: https://github.com/13rac1/videocapture-mcp

Usage Examples

Simple curl request to get a JPEG image:

curl "http://localhost:8080/capture?format=jpeg" --output still.jpg

Capture as JSON with base64 image (useful for embedding in MCP messages):

curl -s -X POST "http://localhost:8080/capture" \
  -H "Content-Type: application/json" \
  -d '{"width":640,"height":480,"format":"png","encode_base64":true}' \
  | jq -r '.image_b64' | base64 --decode > still.png

Python client example:

import requests
resp = requests.post(
    "http://localhost:8080/capture",
    json={"width": 1280, "height": 720, "format": "jpeg"}
)
if resp.headers.get("Content-Type", "").startswith("image/"):
    with open("capture.jpg", "wb") as f:
        f.write(resp.content)
else:
    data = resp.json()
    import base64
    img = base64.b64decode(data["image_b64"])
    open("capture.jpg","wb").write(img)

Use Cases

  • Dataset collection: programmatically capture labeled frames for training CV models without manual camera control.
  • Agent visual context: provide on-demand snapshots to an ML agent through an MCP-compatible tool to augment text-based context with images.
  • Remote troubleshooting: grab stills from remote or embedded cameras for diagnostics and logs.
  • Automated monitoring: schedule single-frame captures for periodic quality checks or visual records.
  • Robotics and control systems: snapshot camera frames for debugging control loops without streaming full video.

This server is intended as a lightweight, reproducible component you can add to pipelines that need reliable single-frame captures from any OpenCV-supported source. The API and configuration make it straightforward to integrate into CI, agent runtimes, or edge deployments.

Tags:media