使用说明
Manim MCP服务器
用于编译和提供Manim动画的模型上下文协议(MCP)服务器。
🎯 两种服务器模式
- HTTP API服务器 (
app/server.py)-用于REST API调用、测试和web集成 - 标准MCP服务器 (
mcp_server.py)-适用于Claude Desktop、Dify和其他MCP客户端
看 MCP_SETUP.md 了解详细的MCP配置说明。
基于FastAPI的MCP(模型控制协议)服务器,提供两个主要工具:
- Manim编译:编译Manim代码并返回视频ID
- 视频下载:按ID下载已编译的Manim视频
特性
- 使用JWT令牌进行安全身份验证
- 用于工作流管理的LangGraph集成
- 支持不同的视频质量和分辨率
- 用于集成的简单API端点
先决条件
- Python 3.8+
- Manim社区版(v0.19.0或更高版本)
- FFmpeg
- 所需的Python包(请参阅
requirements.txt)
安装
-
克隆存储库:
git clone <repository-url> cd manim-mcp-server -
创建虚拟环境并激活它:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate -
安装所需的软件包:
pip install -r requirements.txt -
安装Manim及其依赖项:
pip install manim
配置
- 设置环境变量(创建
.env文件):SECRET_KEY=your-secret-key-here ACCESS_TOKEN_EXPIRE_MINUTES=30
运行服务器
选项1:使用启动脚本(推荐)
./start_server.sh
选项2:直接使用uvicorn
uvicorn app.server:app --reload
服务器将在以下时间可用 http://localhost:8000
API文档
服务器运行后,您可以访问以下位置访问交互式API文档:
- Swagger用户界面:http://localhost:8000/docs
- 重新记录:http://localhost:8000/redoc
API终点
根
GET /-获取服务器信息和可用工具
马尼姆汇编
-
POST /tools/manim_compile-编译Manim代码{ "parameters": { "code": "from manim import *\nclass Example(Scene):\n def construct(self):\n circle = Circle()\n self.play(Create(circle))", "scene_name": "Example" } }参数:
code(必填):要编译的Manim Python代码scene_name(必填):要编译的特定场景类的名称
视频下载
GET /videos/{file_id}-按ID下载已编译的视频
LangGraph兼容端点
GET /v1/tools-列出所有可用工具POST /v1/tools/call-调用工具(兼容LangGraph){ "tool": "manim_compile", "parameters": { "code": "from manim import *\nclass Example(Scene):\n def construct(self):\n circle = Circle()\n self.play(Create(circle))" } }
示例用法
1.检查服务器状态
curl http://localhost:8000/
2.编译Manim代码
curl -X 'POST' \
'http://localhost:8000/tools/manim_compile' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"parameters": {
"code": "from manim import *\nclass Example(Scene):\n def construct(self):\n circle = Circle()\n self.play(Create(circle))"
}
}'
3.下载已编译的视频
# Replace VIDEO_ID with the file_id from the compile response
curl -X 'GET' \
'http://localhost:8000/videos/VIDEO_ID' \
--output output.mp4
4.按名称编译特定场景
curl -X 'POST' \
'http://localhost:8000/tools/manim_compile' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"parameters": {
"code": "from manim import *\nclass Scene1(Scene):\n def construct(self):\n circle = Circle()\n self.play(Create(circle))\n\nclass Scene2(Scene):\n def construct(self):\n square = Square()\n self.play(Create(square))",
"scene_name": "Scene1"
}
}'
5.列出可用工具
curl http://localhost:8000/v1/tools
6.运行示例脚本
python example_usage.py
测试
看 测试.md 详细的测试说明。
快速测试:
# Run tool tests (no server needed)
python test_tools.py
# Run API tests (server must be running)
python test_api.py
安全
- 在生产环境中始终使用HTTPS
- 考虑为生产部署添加身份验证
- 验证并净化所有用户输入
- 为您的用例设置适当的CORS策略
许可证
此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。
