使用说明
MCP媒体服务器
用Python构建的用于媒体处理的自定义MCP(模型上下文协议)服务器。该服务器使Claude等AI助手能够与媒体文件交互,执行视频处理,并与Supabase和Pinecone集成以进行数据存储和矢量搜索。
特性
核心功能
- 使用yt-dlp下载YouTube视频
- 使用FFmpeg进行视频处理
- 元数据存储的Supabase集成
- 矢量搜索的松果积分
- 用于AI助手集成的MCP服务器
高级功能
- 长期运行操作的进度跟踪
- 通知的Webhook支持
- 多个文件的批处理
- 缓存以提高性能
- API保护的速率限制
- 用户身份验证和API密钥管理
- 预定的维护任务
- RESTful API网关
- 使用Docker持续运行
- 与开发IDE集成(Roo Code和Windsurf)
先决条件
- Python 3.10或更高版本
- 转码
- Supabase账户
- 松果账户
- OpenAI API密钥(用于嵌入)
- Docker和Docker Compose(用于容器化部署)
安装
选项1:手动设置
-
克隆存储库:
git clone https://github.com/yourusername/mcp-media-server.git cd mcp-media-server -
创建虚拟环境:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate -
安装依赖项:
pip install -r requirements.txt -
通过复制和编辑示例环境文件来配置服务器:
cp .env.example .env -
编辑
.env文件添加API密钥和配置。
选项2:Docker设置
-
克隆存储库:
git clone https://github.com/yourusername/mcp-media-server.git cd mcp-media-server -
通过复制和编辑示例环境文件来配置服务器:
cp .env.example .env -
编辑
.env文件添加API密钥和配置。 -
构建并启动Docker容器:
docker-compose up -d
用法
运行MCP服务器
要运行MCP服务器,请执行以下操作:
python main.py
默认情况下,服务器使用stdio传输与Claude Desktop或其他MCP客户端直接集成。
从SSE运输开始
要使用服务器发送事件(SSE)传输运行服务器,请执行以下操作:
python main.py --transport sse
运行API服务器
要在MCP服务器旁边运行API服务器,请执行以下操作:
python main.py --api
启动SSE和API服务器
要同时运行SSE传输和API服务器,请执行以下操作:
python main.py --transport sse --api
Docker的持续运行
对于生产环境中的24/7操作:
-
使用Docker Compose进行部署:
docker-compose up -d -
设置自动重启和监控:
# Make scripts executable chmod +x deploy.sh monitor.sh generate_api_key.sh # Deploy with health checks ./deploy.sh # Add monitoring to crontab (runs every 5 minutes) (crontab -l 2>/dev/null; echo "*/5 * * * * /path/to/mcp-media-server/monitor.sh") | crontab - -
设置为系统服务(Linux):
# Copy service file sudo cp mcp-media-server.service /etc/systemd/system/ # Edit the service file to update the path sudo nano /etc/systemd/system/mcp-media-server.service # Enable and start the service sudo systemctl enable mcp-media-server.service sudo systemctl start mcp-media-server.service
IDE集成(Roo代码和Windsurf)
对于Windows用户:
- 运行IDE集成设置脚本:
setup_ide_integration.bat
对于Linux/macOS用户:
-
生成API密钥:
./generate_api_key.sh -
使用从生成的密钥和设置配置IDE
ide-config.json
与Claude Desktop集成
- 打开克劳德桌面应用程序
- 导航到“设置”
- 添加具有以下配置的新MCP服务器:
- 名称:MCP媒体服务器
- 命令:Python可执行文件的路径
- 参数:main.py文件的路径
配置示例:
{
"mcpServers": {
"mcp-media-server": {
"command": "C:\\path\\to\\venv\\Scripts\\python.exe",
"args": ["C:\\path\\to\\mcp-media-server\\main.py"]
}
}
}
API文档
API服务器运行后,您可以访问API文档:
http://localhost:9000/docs
API关键终结点
/videos/download-从YouTube下载视频/videos/process-使用FFmpeg处理视频/videos/search-在YouTube上搜索视频/videos/vector-search-视频语义搜索/videos/similar-查找类似视频
发展
项目结构
mcp-media-server/
├── src/
│ ├── api/ # RESTful API implementation
│ ├── auth/ # Authentication and security
│ ├── core/ # Core MCP server implementation
│ ├── config/ # Configuration settings
│ ├── db/ # Database integrations
│ ├── services/ # Background services
│ ├── tasks/ # Scheduled tasks
│ ├── tools/ # MCP tools implementation
│ ├── utils/ # Utilities and helpers
│ └── webhooks/ # Webhook handlers
├── downloads/ # Downloaded files
├── processed/ # Processed files
├── thumbnails/ # Generated thumbnails
├── cache/ # Cache files
├── logs/ # Log files
├── .env # Environment variables
├── docker-compose.yml # Docker configuration
├── Dockerfile # Docker build instructions
├── deploy.sh # Deployment script
├── monitor.sh # Health monitoring script
├── generate_api_key.sh # API key generation script
├── mcp-media-server.service # Systemd service file
├── setup_ide_integration.bat # IDE integration for Windows
├── ide-config.json # Configuration for IDE integration
├── main.py # Application entry point
└── requirements.txt # Python dependencies
添加新工具
要向MCP服务器添加新工具,请在 src/tools 目录和装饰它 @mcp_server.register_tool.
例子:
from src.core.server import mcp_server
@mcp_server.register_tool
async def my_new_tool(param1: str, param2: int) -> dict:
"""
Description of the new tool.
Args:
param1: Description of param1
param2: Description of param2
Returns:
Dict containing the result
"""
# Implement the tool functionality
result = {"status": "success", "message": "Tool executed successfully"}
return result
容器管理
查看日志:
docker-compose logs -f mcp-server
检查集装箱状态:
docker ps | grep mcp-server
监控资源使用情况:
docker stats mcp-server
许可证
此项目根据MIT许可证获得许可-有关详细信息,请参阅许可证文件。
