sora-mcp
Integrates with OpenAI's Sora model via api.tu-zi.com to generate videos from text prompts, supporting different orientations and model versions, with asynchronous task handling and automatic download.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@sora-mcp Generate a video of a sunrise over mountains"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Sora MCP Server
一个使用 OpenAI Sora 模型生成视频的 MCP (Model Context Protocol) 服务器。通过 api.tu-zi.com 官方格式接口调用 Sora 视频生成 API。
什么是 MCP?
Model Context Protocol (MCP) 是一个开放协议,允许 AI 助手(如 Claude、Cursor)与外部工具和数据源无缝交互。通过 MCP,AI 可以调用你的工具函数,实现更强大的功能。
功能特性
🎬 文本生成视频:通过自然语言描述生成高质量视频
📐 多种宽高比:支持竖屏(9:16)和横屏(16:9)视频
🌏 中英文提示词:支持中文和英文提示词
⏱️ 异步任务模式:自动提交任务、轮询状态、下载视频
📁 自动路径管理:自动创建输出目录,支持绝对路径和相对路径
📊 详细日志:通过 MCP Context 提供实时操作日志
🔒 安全可靠:使用环境变量管理 API 密钥,完善的错误处理
Related MCP server: Grok Imagine Video MCP Server
文件结构
sora-mcp/
├── server.py # MCP 服务器主逻辑
├── pyproject.toml # 项目配置和依赖声明
├── .env.example # 环境变量模板
├── .gitignore # Git 忽略规则
└── README.md # 项目文档(本文件)快速开始
1. 环境准备
系统要求:
Python >= 3.11
uv 包管理器(推荐)
获取 API 密钥:
联系 api.tu-zi.com 服务商获取 Sora API 密钥
2. 安装依赖
# 进入项目目录
cd sora-mcp
# 创建虚拟环境
uv venv
# 安装依赖
uv pip install -e .3. 配置 API 密钥
# 复制环境变量模板
cp .env.example .env
# 编辑 .env 文件,填入你的 API 密钥
# SORA_API_KEY=your_actual_api_key_here4. 启动 MCP 服务器
# 直接运行
python server.py
# 或使用安装的命令
sora-mcp5. 配置 Cursor 或 Claude Desktop
方式 A:Cursor MCP 配置(推荐)
配置文件位置:
macOS/Linux:
~/.cursor/mcp.jsonWindows:
%USERPROFILE%\.cursor\mcp.json
配置内容:
{
"mcpServers": {
"sora-mcp": {
"command": "uv",
"args": [
"--directory",
"/absolute/path/to/sora-mcp",
"run",
"server.py"
]
}
}
}⚠️ 注意事项:
将
/absolute/path/to/sora-mcp替换为你的实际项目路径路径必须使用绝对路径(不支持
~或相对路径)修改配置后需要重启 Cursor
重启后在右下角工具栏查看 MCP 连接状态
如何获取绝对路径:
# 进入项目目录
cd sora-mcp
# 显示绝对路径
pwd
# 示例输出:/Users/username/projects/sora-mcp方式 B:Claude Desktop 配置
配置文件位置:
macOS:
~/Library/Application Support/Claude/claude_desktop_config.jsonWindows:
%APPDATA%\Claude\claude_desktop_config.json
配置内容:
{
"mcpServers": {
"sora-mcp": {
"command": "uv",
"args": [
"--directory",
"/absolute/path/to/sora-mcp",
"run",
"server.py"
]
}
}
}同样需要将路径替换为实际的绝对路径。
使用说明
🎬 工具:generate_video
根据文本描述生成视频并保存到指定路径。
参数说明
参数 | 类型 | 必填 | 默认值 | 说明 |
| string | ✅ | - | 视频生成提示词,支持中英文 |
| string | ✅ | - | 输出文件路径(.mp4) |
| string | ❌ | portrait | 视频方向:portrait(竖屏)或 landscape(横屏) |
| string | ❌ | sora-2 | Sora 模型:sora-2(标准质量)、sora-2-pro(专业高质量) |
使用示例
示例 1:生成竖屏视频
"生成一个视频:一只可爱的橘猫在阳光下行走,保存为 cat.mp4"工具调用:
{
"prompt": "一只可爱的橘猫在阳光洒满的木地板上缓慢行走,镜头跟随,温暖色调",
"output_path": "cat.mp4"
}示例 2:生成横屏视频
"生成一个横屏视频:科幻城市夜景,霓虹灯闪烁,赛博朋克风格,保存为 city.mp4"工具调用:
{
"prompt": "科幻城市夜景,霓虹灯闪烁,飞行汽车穿梭其间,赛博朋克风格,镜头缓慢上升",
"output_path": "city.mp4",
"orientation": "landscape"
}示例 3:使用 sora-2-pro 生成高质量视频
"使用专业模型生成电影级森林晨雾场景,保存为 forest.mp4"工具调用:
{
"prompt": "电影级别的森林晨雾场景,阳光穿透树叶,细腻光影变化,鸟鸣回响",
"output_path": "forest.mp4",
"model": "sora-2-pro",
"orientation": "landscape"
}返回值
成功时:
{
"status": "ok",
"output_path": "/absolute/path/to/video.mp4",
"file_size_bytes": 7506042,
"prompt": "一只可爱的橘猫...",
"orientation": "portrait",
"model": "sora-2",
"task_id": "task_01k7rdk408fsfvgqq8whb7pjnq",
"generation_id": "gen_01k6fmwxqjfej860t5cszqmzvk",
"video_url": "https://...",
"width": 352,
"height": 640
}失败时:
{
"status": "error",
"message": "错误描述信息"
}提示词技巧
✅ 好的提示词(具体、详细)
"一只橘猫在木地板上缓慢行走,阳光从窗户洒进来,温暖的色调,镜头平稳跟随"
"科幻城市夜景,高楼林立,霓虹灯闪烁,飞行汽车穿梭,赛博朋克风格,镜头从低处缓慢上升"
"海浪轻柔拍打沙滩,夕阳西下,金色光线洒在水面,平静祥和,远景镜头"
"一杯咖啡冒着热气,特写镜头,背景虚化,温馨的咖啡馆环境,暖色调"
❌ 不好的提示词(模糊、笼统)
"一只猫"
"城市"
"海边"
"咖啡"
高级技巧
包含关键元素:
主体:描述主要对象(人、动物、物体)
动作:描述运动或变化
环境:描述场景和背景
光线:描述光线效果(阳光、霓虹灯、柔光等)
氛围:描述整体感觉(温暖、科幻、平静等)
镜头:描述镜头运动(跟随、上升、特写等)
使用具体形容词:
温暖的、柔和的、明亮的、阴暗的
快速的、缓慢的、平稳的、急促的
指定艺术风格:
赛博朋克、水彩画、电影感、复古、现代简约
工作原理
Sora MCP 使用异步任务模式生成视频:
1. 提交任务 → 2. 轮询状态 → 3. 下载视频详细流程:
提交任务:
发送提示词和参数到 api.tu-zi.com
服务器返回
task_id
轮询状态:
每 10 秒检查一次任务状态
最多轮询 60 次(总计 10 分钟)
状态流转:
queued→in_progress→completed
下载视频:
任务完成后获取
video_url自动下载并保存到指定路径
⏱️ 预计时间:2-10 分钟(取决于提示词复杂度和服务器负载)
常见问题
Q1: API 密钥设置后仍然报错?
解决方案:
检查
.env文件是否在项目根目录确认 API 密钥没有多余的空格或引号
重启 MCP 服务器或 Cursor/Claude Desktop
Q2: 视频生成时间过长?
原因:
Sora 视频生成通常需要 2-10 分钟
这是正常的,取决于提示词复杂度
解决方案:
耐心等待
检查任务状态(可能已在后台完成)
Q3: 任务失败怎么办?
可能原因:
API 密钥无效或过期
提示词包含不适当内容
服务器临时故障
解决方案:
确认 API 密钥有效
修改提示词内容
稍后重试
Q4: 支持什么视频格式?
当前支持:
格式:MP4
竖屏:352 x 640(9:16)
横屏:640 x 352(16:9)
时长:约 15 秒
技术栈
FastMCP: MCP 服务器框架
httpx: 异步 HTTP 客户端
asyncio: 异步任务处理
Pydantic: 参数验证
python-dotenv: 环境变量管理
相关资源
api.tu-zi.com - Sora API 服务商
Model Context Protocol - MCP 官方规范
FastMCP - FastMCP 框架文档
Cursor - AI 代码编辑器
Claude Desktop - Anthropic 桌面应用
开发指南
本地测试
# 激活虚拟环境
source .venv/bin/activate # macOS/Linux
# 或
.venv\Scripts\activate # Windows
# 运行测试脚本
python -c "
import asyncio
from server import generate_video
async def test():
result = await generate_video(
prompt='一只可爱的猫在阳光下行走',
output_path='test.mp4'
)
print(result)
asyncio.run(test())
"项目结构
sora-mcp/
├── server.py # MCP 服务器主逻辑
│ ├── generate_video() # 视频生成工具函数
│ ├── _get_sora_api_key() # API 密钥获取
│ └── main() # 服务器启动入口
├── pyproject.toml # 项目配置文件
├── .env # 环境变量(不提交到 Git)
├── .env.example # 环境变量模板
└── README.md # 项目文档许可证
本项目采用 MIT 许可证。详见 LICENSE 文件。
贡献
欢迎提交 Issue 和 Pull Request!
贡献指南:
Fork 本仓库
创建功能分支 (
git checkout -b feature/AmazingFeature)提交更改 (
git commit -m 'Add some AmazingFeature')推送到分支 (
git push origin feature/AmazingFeature)开启 Pull Request
问题反馈
如果你遇到任何问题或有功能建议,请:
⭐ 如果这个项目对你有帮助,请给个 Star!
Available Tools
1 toolgenerate_videoA
使用 Sora 模型生成视频并保存到指定路径(异步任务模式)。
通过 api.tu-zi.com 官方格式接口调用 Sora 视频生成模型。 采用任务提交 → 轮询状态 → 下载视频的异步流程。
⚠️ 重要提示:
视频生成时间较长,通常需要 2-10 分钟,请耐心等待
建议提示词详细且具体,包含场景、动作、风格等元素
支持中文和英文提示词
采用异步轮询机制,每 10 秒检查一次任务状态
Args: prompt: 视频生成提示词,描述越详细越好 output_path: 输出视频文件路径(.mp4) orientation: 视频方向,'portrait'(竖屏)或 'landscape'(横屏) model: Sora 模型名称,默认 'sora-2'(最新版本) ctx: MCP 上下文,用于日志记录
Returns: 包含生成结果的字典: - status: "ok" 或 "error" - output_path: 保存的视频文件路径(绝对路径) - file_size_bytes: 文件大小(字节) - prompt: 使用的提示词 - orientation: 视频方向 - model: 使用的模型名称 - task_id: 任务 ID - video_url: 视频下载 URL - size: 视频尺寸规格(如 "small") - seconds: 视频时长(秒) - created_at: 创建时间戳 - message: 错误信息(失败时)
Examples: >>> # 生成竖屏视频(使用默认 sora-2 模型) >>> result = await generate_video( ... prompt="一只可爱的橘猫在阳光下缓慢行走", ... output_path="videos/cat_walking.mp4" ... )
>>> # 生成横屏视频(使用默认 sora-2)
>>> result = await generate_video(
... prompt="科幻城市夜景,霓虹灯闪烁,赛博朋克风格",
... output_path="videos/cyberpunk_city.mp4",
... orientation="landscape"
... )
>>> # 使用 sora-2-pro 模型生成高质量视频
>>> result = await generate_video(
... prompt="电影级别的森林晨雾场景,阳光穿透树叶,细腻光影变化",
... output_path="videos/forest_cinematic.mp4",
... model="sora-2-pro",
... orientation="landscape"
... )
Inputs: prompt (required), output_path (required), model, orientation. Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 1 tool
Only one tool exists, so there is no possibility of overlap or mis-selection. The single tool's purpose is clearly defined a video generation.
The sole tool uses a clear snake_case verb_noun convention: generate_video. With no other tools there are no conflicting naming patterns to confuse an agent.
A single tool makes the server feel minimal and borderline thin for a video-generation service. However, the tool does encapsulate the full submit/poll/download workflow, so the count is not clearly inadequate.
The core video generation lifecycle is covered end-to-end within generate_video, including async polling and file saving. Minor gaps exist, such as no separate task-status or cancellation endpoint, but agents can still accomplish the primary use case without dead ends.
Maintenance
Related MCP Connectors
MCP server for OpenAI Sora AI video generation
MCP server for Google Veo AI video generation
MCP server for Wan AI video generation
MCP server for Hailuo (MiniMax) AI video generation
Related MCP Servers
- FlicenseNot gradedqualityCmaintenanceMCP server enabling AI agents to generate AI videos and images, analyze video content, and download videos from Douyin and Xiaohongshu.-
- AlicenseAqualityCmaintenanceMCP server for generating, editing, and batch processing videos using xAI's Grok Imagine Video API, with support for text-to-video, image-to-video, and video editing via natural language prompts.472 npm1MIT
- AlicenseAqualityBmaintenanceGenerate AI images, video, voiceovers and music from Claude, Cursor or VS Code through 50+ models (Veo 3.1, Kling 3, Seedance, Nano Banana, GPT Image, ElevenLabs). Upload photos for edits and image-to-video. Tools are annotated (read-only vs. credit-spending); failed generations are refunded. Local via npx or hosted with OAuth at fattly.app.645 npmMIT
- FlicenseNot gradedqualityDmaintenanceAn MCP server for generating images and videos via external multimodal models, providing unified tools like imageGenerate, videoGenerate, and materialWrite with support for normal and smart generation modes.-