Content
# MCP Camera Service
## Feature Overview
This project is a multi-protocol camera control service based on Node.js/TypeScript, strictly following the [Model Context Protocol (MCP)](https://github.com/modelcontextprotocol/modelcontextprotocol) TypeScript SDK. It supports:
- Camera enumeration, photo taking, video recording (file/streaming), and more
- MCP tool interfaces (listCameras, takePhoto, startVideo, stopVideo)
- Multiple transport modes: stdio, HTTP, SSE
- Support for Windows (dshow) and Linux (v4l2)
- Support for concurrent video recording and streaming with multiple instances
- Rich environment variable configuration, customizable logging
- Video recording streaming supports streamUrl, clients can pull streams using httpx/curl/ffmpeg/ffplay
---
## Environment Dependencies
- Node.js 16+
- ffmpeg (must be installed and available in PATH or provided by ffmpeg-static)
- Recommended: Windows 10+/Linux, with a camera device
---
## Installation and Startup
```bash
npm install
# Configure the .env file (see below)
npm run build
npm start # or npm run start:http
```
---
## .env Configuration Instructions
When executing locally, please copy .env.sample to .env and configure it with the parameters you need.
```ini
# HTTP server port
PORT=3001
# MCP service name/version
MCP_SERVER_NAME=mcp-camera-server
MCP_SERVER_VERSION=1.0.0
# Log level and file
LOG_LEVEL=info
LOG_FILEPATH=./camera.log
# Photo/video file prefix and directory
PHOTO_PREFIX=image
VIDEO_PREFIX=video
PHOTO_DIR=photos
VIDEO_DIR=videos
# Video context auto-clean time (seconds)
FINISHED_VIDEO_CLEAN_SPAN_SECOND=1800
# Stream URL timeout (milliseconds)
STREAM_URL_EXPIRE_MS=300000
```
---
## Main MCP Tool Interfaces
### 1. listCameras - Enumerate Cameras
Function Description: Lists all available camera devices
Input Parameters: None
Output Parameters:
- cameras: List of cameras
- cameraID: Camera identifier
- name: Device name
- description: Device description
### 2. takePhoto - Photo Taking Function
Function Description: Captures a photo from the specified camera and saves it
Input Parameters:
- cameraID: Camera identifier
- filepath: Path to save the photo
Output Parameters:
- success: Whether the operation was successful
- imagePath: Path where the photo is saved (returned on success)
- error: Error message (returned on failure)
### 3. startVideo - Start Recording/Streaming
Function Description: Starts video recording or live streaming
Input Parameters:
- cameraID: Camera identifier
- filepath: Path to save the video file (optional, if not provided, streaming mode is activated)
- duration: Duration of the recording (milliseconds, optional)
Output Parameters (file mode):
- success: Whether the operation was successful
- videoPath: Path to the video file
- videoID: Recording session ID
Output Parameters (streaming mode):
- success: Whether the operation was successful
- videoID: Recording session ID
- streamUrl: Streaming access address
### 4. stopVideo - Stop Recording/Streaming
Function Description: Stops the ongoing recording or streaming
Input Parameters:
- videoID: Recording session ID (returned by startVideo)
Output Parameters:
- success: Whether the operation was successful
- message: Operation result message
- videoPath: Path to the video file (exists in file mode)
- error: Error message (returned on failure)
---
## MCP Tool Interface Testing Method
- After downloading this repository, navigate to the root directory `cd myCameraNodejs`
- Use `npm link .` to link it as a global command
- Please start modelcontextprotocol/inspector for testing using `npx modelcontextprotocol/inspector`:

In the interface:
- `Transport Type`: Select `STDIO`
- `Command`: Select `npx`
- `Arguments`: Enter `mcp-camera-server`
Click the `Connect` button to connect to the camera service.
If you start the service using `npx run start:sse`, fill in the `URL` as `http://127.0.0.1:3001/sse` (note that 3001 is specified by PORT in .env)
## Video Stream Testing Method
### 1. Save as ts file using curl
```bash
curl http://localhost:3001/video/stream?videoID=xxxx-xxxx-xxxx -o output.ts
```
### 2. Directly play using ffplay
```bash
ffplay http://localhost:3001/video/stream?videoID=xxxx-xxxx-xxxx
```
### 3. Save as mp4 file using ffmpeg
#### Directly transcode to mp4 (recommended)
```bash
ffmpeg -i "http://localhost:3001/video/stream?videoID=xxxx-xxxx-xxxx" -c:v libx264 -preset veryfast -crf 23 -f mp4 output.mp4
```
#### Save as ts file only (no transcoding, fastest)
```bash
ffmpeg -i "http://localhost:3001/video/stream?videoID=xxxx-xxxx-xxxx" -c copy output.ts
```
---
## Common Issues and Troubleshooting
- **ffplay/ffmpeg reports Invalid data found when processing input**
- Please confirm that the server's streaming format is mpegts (fixed)
- **streamUrl can only be consumed once/times out**
- This is by design; you need to call startVideo again to get a new streamUrl
- **Camera not found/photo taking failed**
- Please first use listCameras to obtain the cameraID and ensure ffmpeg can recognize it
- **Video file cannot be played**
- It is recommended to use ffmpeg/ffplay for transcoding or playback
- **Streaming timeout/recording context cleanup time**
- Can be configured through .env with STREAM_URL_EXPIRE_MS and FINISHED_VIDEO_CLEAN_SPAN_SECOND
---
## Other Notes
- Supports concurrent recording/streaming with multiple instances
- Detailed logging for troubleshooting
- Supports Windows/Linux, automatically adapts to dshow/v4l2
- Supports multiple modes of MCP stdio/http/sse
For more questions or requests, feel free to open an issue or contact Jackgao19700@qq.com or gaoshengqiang19700@gmail.com
It is certified by MCPHub. You can get it from https://mcphub.com/mcp-servers/jackgao19700/cameramcpserver.
Connection Info
You Might Also Like
everything-claude-code
Complete Claude Code configuration collection - agents, skills, hooks,...
markitdown
MarkItDown-MCP is a lightweight server for converting URIs to Markdown.
cc-switch
All-in-One Assistant for Claude Code, Codex & Gemini CLI across platforms.
servers
Model Context Protocol Servers
servers
Model Context Protocol Servers
Agent-Reach
Give your AI agent eyes to see the entire internet. Read & search Twitter,...