AI-ready camera server bridging industrial automation and the Model Context Protocol (MCP)
camera-mcp is an experimental Java service from ErgoTech Systems that makes live camera feeds accessible to AI agents and LangChain4j / MCP clients — much like an OPC UA server exposes process variables to control systems.
Originally inspired by a small Python OPC UA prototype that published a camera frame as a ByteString tag
specifically the excellent OPC-UA-Server-for-Camera project by RavilN
this project re-implements the concept in Java using OpenCV and Spring AI MCP, adding:
- dynamic image encoding (JPEG/PNG),
- region-of-interest masking,
- change-based streaming,
- and configurable grayscale/color modes.
The goal: provide an AI-native vision node
flowchart LR
subgraph OPC_UA["🧱 OPC UA Prototype (Python)"]
A1["cv2.VideoCapture()"] --> A2[Percent difference & deadband]
A2 --> A3["ByteString <br/> OPC UA tag \"CameraImage\""]
end
subgraph MCP["🌐 MCP Server (Java + LangChain4j)"]
B1[OpenCV capture service] --> B2[MCP tools via Spring AI]
B2 --> B3["SSE / JSON-RPC streaming <br/> (JPEG | PNG | Change)"]
B3 --> B4[Agentic AI / MIStudio integration]
end
OPC_UA -->|Re-imagined for AI context| MCP
| Capability | Description |
|---|---|
🖼️ get_image |
Capture a single image (JPEG or PNG) |
🔄 open_stream_url |
Continuous JPEG SSE stream |
🧊 open_png_stream_url |
Continuous PNG SSE stream |
⚡ open_png_change_stream_url |
PNG stream only when frame changes by % threshold |
| 🧮 Percent change metrics | Compute change between consecutive frames |
| 🎛️ Configurable options | Grayscale / color, ROIs, quality, deadband, interval |
| 🤖 MCP integration | Exposes all camera tools via /mcp endpoint for agents |
| 🌍 REST/SSE endpoints | /stream/sse, /stream/sse-png, /stream/sse-png-change |
┌──────────────────────────┐
│ Camera (USB / IP) │
└──────────┬───────────────┘
│ OpenCV
▼
┌──────────────────────────┐
│ CameraService │ → Frame capture & ROI masking
└──────────┬───────────────┘
▼
┌──────────────────────────┐
│ ChangeMetricsService │ → Percent-difference computation
└──────────┬───────────────┘
▼
┌──────────────────────────┐
│ StreamController │ → /stream/sse, /stream/sse-png, /stream/sse-png-change
└──────────┬───────────────┘
▼
┌──────────────────────────┐
│ MCP Server (Spring AI) │ → /mcp JSON-RPC 2.0 endpoint
└──────────────────────────┘
- Java 21+
- Gradle 8.5+
- Webcam or IP camera accessible to OpenCV
./gradlew clean bootRunServer starts (default port 8080) exposing:
| Endpoint | Purpose |
|---|---|
POST /mcp |
MCP JSON-RPC 2.0 endpoint |
/stream/sse |
MJPEG SSE stream |
/stream/sse-png |
PNG SSE stream |
/stream/sse-png-change |
Change-triggered PNG SSE stream |
Headless integration tests verify:
| Test | Purpose |
|---|---|
McpServerPresenceIT |
Confirms /mcp endpoint is live |
McpToolCallIT |
Calls get_image via JSON-RPC |
DisplayStreamManualTest |
Opens live stream and validates frame data |
Run all tests:
./gradlew testExample RPC call:
{
"jsonrpc": "2.0",
"id": "1",
"method": "tools/call",
"params": {
"name": "get_image",
"arguments": { "useGrayscale": true, "fmt": "png", "quality": 90 }
}
}Typical response:
{
"jsonrpc": "2.0",
"id": "1",
"result": {
"mimeType": "image/png",
"data_base64": "<Base64 image>",
"width": 640,
"height": 480,
"ts": 1697045290000
}
}Edit src/main/resources/application.yml:
server:
port: 8080
spring:
ai:
mcp:
server:
http:
enabled: true
path: /mcp
sse:
enabled: trueOptional environment variables:
| Variable | Description | Default |
|---|---|---|
CAMERA_INDEX |
Camera device index | 0 |
FRAME_INTERVAL_MS |
Capture interval (ms) | 100 |
CHANGE_DEADBAND_PCT |
% change threshold for updates | 3 |
IMAGE_FORMAT |
jpeg or png |
jpeg |
| Aspect | OPC UA Approach | MCP Approach |
|---|---|---|
| Transport | Binary / UA sessions | JSON-RPC / HTTP / SSE |
| Data Type | ByteString (PNG) |
Base64 JPEG / PNG |
| Access Control | UA session | HTTP auth / agent context |
| Configuration | Global server tags | Per-client arguments |
| Integration Target | PLC / MES systems | AI agents / data mesh |
MCP brings contextual, agent-aware data virtualization to the same vision interfaces that OPC UA once standardized for automation.
- Embed as an MCP data source node
- Deploy anyewhere, eg on Jetson Nano / Raspberry Pi edge devices
- Feed live imagery into AI pipelines for anomaly detection
- Attach to Digital Twin dashboards via MCP streaming
- WebSocket / gRPC transport options
- Per-client configuration via MCP contexts
- Object detection / annotation overlays
- Multi-camera support
- Integration with ErgoTech MIStudio MCP mesh
ErgoTech Systems, Inc. (Los Alamos, NM) develops AI-driven manufacturing software including:
- MIStudio – a no/low-code platform for process monitoring and AI integration
- TransSECS – a configurable SECS/GEM interface builder for semiconductor tools
- Data Mesh & Digital Twin frameworks bridging OT, IT, and AI systems
Visit 🌐 ergotech.com for more information.
MIT License © 2025 ErgoTech Systems, Inc.
“MCP turns every data source into a live, streaming part of the world’s context layer — so AI, analytics, and automation all work from the same real-time truth.”
— ErgoTech Systems, Inc.