Wan2GP MCP服务器
一个模型上下文协议(MCP)服务器,为人工智能助手(如克劳德桌面)提供访问 Wan2GP 视频生成能力。
概述
此MCP服务器与正在运行的Wan2GP Gradio实例通信,以从文本提示和图像生成视频。它旨在通过以下方式与Wan2GP安装配合使用 稳定矩阵 或独立设置。
特性
- 文本转视频:根据文本描述生成视频
- 图像转视频:使用文本提示为静态图像设置动画
- 队列管理:查看和管理生成队列
- 模型列表:发现可用的视频生成模型
- LoRA支持:列出可用的LoRA适配器
- 健康监测:检查Wan2GP服务器状态
建筑
Claude Desktop (MCP Client)
↓ stdio (JSON-RPC 2.0)
Wan2GP MCP Server
↓ HTTP requests
Wan2GP Gradio Server (localhost:7860)先决条件
- Wan2GP服务器:正在运行的Wan2GP Gradio实例
- 通过安装 稳定矩阵 或手动 - 启动Gradio服务器: python wgp.py --server-name 0.0.0.0 --server-port 7860
- Python 3.10+:MCP服务器需要
- 克劳德桌面 (可选):用于MCP集成
安装
1.克隆或下载
cd /path/to/your/projects
git clone wan2gp-mcp-server
cd wan2gp-mcp-server2.安装依赖项
pip install -r requirements.txt3.配置服务器URL
编辑 config.json 要匹配您的Wan2GP服务器URL:
{
"wan2gp_url": "http://localhost:7860",
"timeout": 300,
"max_concurrent_tasks": 3,
"default_model": "wan",
"default_resolution": "1280x720",
"output_directory": "./output"
}或通过环境变量设置:
export WAN2GP_URL="http://localhost:7860"
export WAN2GP_TIMEOUT="300"用法
独立测试
直接测试MCP服务器:
python wan2gp_mcp_server.py在另一个终端中,使用MCP客户端进行测试或检查日志。
Claude桌面集成
- 添加到Claude桌面配置
找到Claude Desktop的配置文件:
- 视窗: %APPDATA%\Claude\claude_desktop_config.json - macOS: ~/Library/Application Support/Claude/claude_desktop_config.json - Linux: ~/.config/Claude/claude_desktop_config.json
- 合并配置
添加 wan2gp 服务器到 mcpServers 章节:
{
"mcpServers": {
"wan2gp": {
"command": "python",
"args": [
"/absolute/path/to/wan2gp-mcp-server/wan2gp_mcp_server.py"
],
"env": {
"WAN2GP_URL": "http://localhost:7860",
"WAN2GP_TIMEOUT": "300",
"LOG_LEVEL": "INFO"
}
}
}
}重要:在中使用绝对路径 args 部分。
- 重新启动克劳德桌面
Claude将在启动时加载MCP服务器。
- 在Claude中使用
现在,您可以让Claude生成视频:
Generate a 5-second video of a cat walking through a sunny gardenClaude将使用MCP服务器提交生成任务。
MCP工具
服务器提供以下工具:
generate_text_to_video
根据文本描述生成视频。
参数:
prompt(必填):视频的文字描述negative_prompt:视频中要避免的事情resolution:视频分辨率(例如,“1280x720”、“1920x1080”)video_length:帧数(24fps时49≈2秒)num_inference_steps:去噪步骤数(建议20-50)guidance_scale:遵循提示的力度(1-20)seed:随机种子(-1表示随机)model_type:要使用的型号(wan、hunyuan、ltx等)output_filename:自定义输出文件名
例子:
generate_text_to_video(
prompt="A cat walking through a sunny garden, slow motion",
resolution="1280x720",
num_inference_steps=25,
guidance_scale=7.5
)generate_image_to_video
根据文本提示为静态图像设置动画。
参数:
image_path(必填):输入图像的路径prompt(必填):图像应如何设置动画/移动negative_prompt:视频中要避免的事情motion_scale:产生多少运动(0.5-2.0)video_length:帧数num_inference_steps:去噪步骤数guidance_scale:遵循提示的力度有多大seed:随机种子(-1表示随机)model_type:要使用的模型
例子:
generate_image_to_video(
image_path="/path/to/image.jpg",
prompt="Camera slowly zooms in, clouds drift across the sky",
motion_scale=1.2
)health_check
检查Wan2GP服务器是否正在运行且可访问。
退货:
{
"status": "healthy",
"url": "http://localhost:7860",
"version": "10.951"
}list_models
列出所有可用的视频生成型号。
退货:
[
{
"name": "Wan2.1 T2V",
"id": "t2v_2_2",
"type": "text_to_video",
"resolution": "480p-8K",
"vram_requirement": "16GB+"
}
]list_loras
列出可用的LoRA适配器。
get_queue
获取当前生成队列。
cancel_task
取消排队的生成任务。
MCP资源
服务器提供以下资源:
wan2gp://models-列出可用模型(JSON)wan2gp://loras-列出可用的LoRA(JSON)wan2gp://queue-当前生成队列(JSON)wan2gp://health-服务器健康状态(JSON)
故障排除
“无法连接到Wan2GP服务器”
- 确保Wan2GP Gradio服务器正在运行
- 在中检查URL
config.json匹配您的服务器 - 验证服务器端口(默认值:7860)
“Flash Attention版本冲突”
这是Wan2GP环境问题,与MCP服务器无关。确保Wan2GP的依赖项已正确安装:
# In Wan2GP environment
pip install flash-attn==2.7.4Claude Desktop未显示MCP工具
- 检查克劳德桌面日志:
Help > Developer > Show Logs - 验证配置中的绝对路径
- 确保Python在系统PATH中
- 手动测试服务器:
python wan2gp_mcp_server.py
发展
运行测试
# Test client
python tests/test_client.py
# Test with MCP inspector
npx @modelcontextprotocol/inspector python wan2gp_mcp_server.py添加新工具
编辑 wan2gp_mcp_server.py 并使用添加新工具 @mcp.tool 装饰师:
@mcp.tool
async def my_new_tool(param: str) -> str:
"""Tool description."""
client = await get_client()
# ... implementation
return "result"配置参考
config.json
| 关键字 | 类型 | 默认值 | 描述 |
|---|---|---|---|
wan2gp_url | 字符串 | http://localhost:7860 | Wan2GP Gradio服务器URL |
timeout | 编号 | 300 | 请求超时(秒) |
max_concurrent_tasks | 编号 | 3 | 最大并发代数 |
default_model | 字符串 | wan | 要使用的默认模型 |
default_resolution | 字符串 | 1280x720 | 默认视频分辨率 |
output_directory | 字符串 | ./output | 在哪里保存生成的视频 |
环境变量
| 变量 | 描述 | 默认值 |
|---|---|---|
WAN2GP_URL | 覆盖Wan2GP服务器URL | http://localhost:7860 |
WAN2GP_TIMEOUT | 覆盖请求超时 | 300 |
LOG_LEVEL | 日志记录级别 | INFO |
许可证
此MCP服务器按原样提供,用于Wan2GP。
