护卫舰MCP服务器
A. 模型上下文协议(MCP) 服务器 护卫舰NVR,使AI助手能够与您的护卫舰安全摄像头系统进行交互。
](https://www.python.org/downloads/) 
🌟 特性
- 相机管理:列出并监控所有配置的摄像头
- 事件检测:通过按相机、对象类型和时间进行过滤来查询检测事件
- 实时快照:获取当前或历史相机快照
- 录音:访问录制摘要和片段
- 系统统计信息:监控护卫舰性能、探测器速度和相机FPS
- 配置:检索完整的护卫舰配置
📋 先决条件
- Python 3.10或更高版本
- 跑步 护卫舰NVR 例子
- 访问Frigate HTTP API
🚀 安装
1.克隆存储库
git clone https://github.com/yourusername/frigate-mcp.git
cd frigate-mcp2.创建虚拟环境
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate3.安装依赖项
pip install -e .4.配置环境
创建 .env 项目根目录中的文件:
# Required: URL of your Frigate instance
FRIGATE_FRIGATE_URL=http://localhost:5000
# Optional: API key if authentication is required
# FRIGATE_API_KEY=your_secret_key_here
# Optional: HTTP timeout in seconds (default: 30)
# FRIGATE_TIMEOUT=30🔧 配置
服务器使用环境变量进行配置。您可以在以下位置设置它们:
.env文件 (建议开发)- 环境变量 (推荐用于生产)
配置选项
| 变量 | 描述 | 默认值 | 必填 |
|---|---|---|---|
FRIGATE_FRIGATE_URL | 护卫舰实例的基本URL | http://localhost:5000 | 没有 |
FRIGATE_API_KEY | 用于身份验证的API密钥 | 无 | 否 |
FRIGATE_TIMEOUT | HTTP请求超时(秒) | 30 | 没有 |
FRIGATE_SERVER_HOST | SSE/HTTP模式的服务器主机 | 0.0.0.0 | 没有 |
FRIGATE_SERVER_PORT | SSE/HTTP模式的服务器端口 | 8000 | 没有 |
示例配置
本地护卫舰实例:
FRIGATE_FRIGATE_URL=http://localhost:5000带身份验证的远程护卫舰:
FRIGATE_FRIGATE_URL=http://192.168.1.100:5000
FRIGATE_API_KEY=your_secret_key
FRIGATE_TIMEOUT=60🎯 用法
服务器支持三种操作模式:
1.STDIO模式(默认)
对于与Claude Desktop等MCP客户端的直接集成:
python -m frigate_mcp.server
# or
frigate-mcp2.SSE模式(服务器发送事件)
对于具有实时更新的基于web的客户端:
frigate-mcp-sse服务器将在以下时间启动 http://localhost:8000/sse (可通过环境变量配置)。
特征:
- 实时事件流
- 基于HTTP的类似WebSocket的体验
- 易于在浏览器中调试的开发工具
- 与web应用程序兼容
3.HTTP模式(REST API)
对于生产部署和API访问:
STDIO模式 (适用于MCP客户):
python -m frigate_mcp.serverSSE模式 (适用于web客户端):
frigate-mcp-sseHTTP模式 (适用于REST API):
frigate-mcp-http与MCP客户端集成
克劳德桌面(STDIO模式)
测试连接
运行附带的测试脚本以验证您的护卫舰连接:
python test_connection.py预期产量:
============================================================
Frigate MCP Server - Connection Test
============================================================
🔧 Frigate Configuration:
URL: http://localhost:5000
API URL: http://localhost:5000/api
Timeout: 30s
📹 Testing /api/config (cameras)...
✅ Found 1 camera(s)
- front_door: enabled
📊 Testing /api/stats...
✅ Frigate version: 0.16.3
✅ Detectors: ['coral']
✅ Active cameras: ['front_door']
...运行MCP服务器
在stdio模式下启动服务器(适用于MCP客户端):
python -m frigate_mcp.server克劳德桌面(STDIO模式)
添加到您的MCP客户端配置中(例如,Claude Desktop config.json):
{
"mcpServers": {
"frigate": {
"command": "/path/to/frigate-mcp/.venv/bin/python",
"args": ["-m", "frigate_mcp.server"],
"env": {
"FRIGATE_FRIGATE_URL": "http://localhost:5000"
}
}
}
}Web客户端(SSE模式)
连接到SSE端点以进行实时更新:
const eventSource = new EventSource('http://localhost:8000/sse');
eventSource.onmessage = (event) => {
const data = JSON.parse(event.data);
console.log('Received:', data);
};REST API(HTTP模式)
发出标准HTTP请求:
# Get cameras
curl http://localhost:8000/tools/get_cameras
# Get events
curl http://localhost:8000/tools/get_events?limit=5
# Get stats
curl http://localhost:8000/tools/get_stats或者使用任何HTTP客户端:
import requests
response = requests.post(
'http://localhost:8000/tools/get_events',
json={'camera': 'front_door', 'limit': 10}
)
print(response.json()) "frigate": {
"command": "/path/to/frigate-mcp/.venv/bin/python",
"args": ["-m", "frigate_mcp.server"],
"env": {
"FRIGATE_FRIGATE_URL": "http://localhost:5000"
}
}
}
}🛠️ 可用工具
服务器提供7个MCP工具用于与护卫舰交互:
1. get_cameras()
列出所有已配置的摄像头及其状态和属性。
退货:
[
{
"name": "front_door",
"enabled": true,
"width": 1920,
"height": 1080,
"fps": 5
}
]2. get_events(camera, label, limit)
使用可选筛选获取最近的检测事件。
参数:
camera(可选):按相机名称过滤label(可选):按对象类型筛选(person,car,dog等等)limit(默认值:10):要返回的最大事件数(1-100)
例子:
get_events(camera="front_door", label="person", limit=5)退货:
[
{
"id": "1234567890.123456-abcdef",
"camera": "front_door",
"label": "person",
"start_time": 1704067200.5,
"end_time": 1704067205.8,
"has_clip": true,
"has_snapshot": true,
"zones": ["entrance"],
"thumbnail": "http://localhost:5000/api/events/1234.../thumbnail.jpg"
}
]3. get_stats()
获取护卫舰系统统计数据和性能指标。
退货:
{
"service": {
"uptime": 86400,
"version": "0.16.3",
"storage": {...}
},
"detectors": {
"coral": {
"inference_speed": 8.5,
"detection_start": 1704067200.0
}
},
"cameras": {
"front_door": {
"camera_fps": 5.0,
"process_fps": 5.0,
"detection_fps": 1.2
}
}
}4. get_event_details(event_id)
获取有关特定事件的全面详细信息。
参数:
event_id:唯一事件标识符
退货:
{
"id": "1234567890.123456-abcdef",
"camera": "front_door",
"label": "person",
"start_time": 1704067200.5,
"end_time": 1704067205.8,
"duration": 5.3,
"score": 0.87,
"zones": ["entrance"],
"has_clip": true,
"has_snapshot": true,
"media": {
"thumbnail": "http://localhost:5000/api/events/.../thumbnail.jpg",
"snapshot": "http://localhost:5000/api/events/.../snapshot.jpg",
"clip": "http://localhost:5000/api/events/.../clip.mp4"
}
}5. get_snapshot(camera, timestamp)
从特定相机获取快照URL。
参数:
camera:相机名称timestamp(可选):历史快照的Unix时间戳
退货:
{
"camera": "front_door",
"timestamp": "latest",
"url": "http://localhost:5000/api/front_door/latest.jpg",
"description": "Snapshot from front_door (latest)"
}6. get_recordings(camera, date)
获取特定相机和日期的录制信息。
参数:
camera:相机名称date(可选):日期YYYY-MM-DD格式(默认为今天)
退货:
{
"camera": "front_door",
"date": "2024-01-01",
"recordings_count": 24,
"total_duration": 86400,
"recordings": [
{
"day": "2024-01-01",
"hour": "10",
"duration": 3600,
"events": 5
}
]
}7. get_config()
获取护卫舰配置摘要。
退货:
{
"cameras": ["front_door", "backyard", "garage"],
"detectors": ["coral"],
"mqtt": {
"enabled": true,
"host": "localhost"
},
"model": "path/to/model.tflite",
"version": "0.16.3"
}🏗️ 项目结构
frigate-mcp/
├── src/
│ └── frigate_mcp/
│ ├── __init__.py # Package metadata
│ ├── config.py # Configuration management
│ └── server.py # MCP server & tools
├── test_connection.py # Connection test script
├── pyproject.toml # Project dependencies
├── .env # Environment variables (not in git)
└── README.md # This file______________________________________________________________________
由以下材料制成❤️ 为护卫舰和MCP社区
