Model Context Protocol server for Pixverse video generation APIs
Project description
Pixverse MCP
A Model Context Protocol (MCP) server for Pixverse video generation APIs.
Features
- Complete API Coverage: All 7 Pixverse generation endpoints
- Type Safety: Full Pydantic model validation
- Error Handling: Comprehensive error handling with retries
- Rate Limiting: Built-in rate limiting and throttling
- Logging: Structured logging with loguru
- MCP Integration: Native MCP server implementation
Supported Endpoints
- Text to Video (
/openapi/v2/video/text/generate) - Image to Video (
/openapi/v2/video/img/generate) - Transition Video (
/openapi/v2/video/transition/generate) - Extend Video (
/openapi/v2/video/extend/generate) - Lip Sync Video (
/openapi/v2/video/lip_sync/generate) - Sound Effect Video (
/openapi/v2/video/sound_effect/generate) - Fusion Video (
/openapi/v2/video/fusion/generate)
Installation
From Source
git clone <repository-url>
cd pixverse_mcp
pip install -e .
Development Installation
pip install -e ".[dev]"
Configuration
配置方式
方式1: 配置文件(推荐)
复制并编辑配置文件:
cp config.yaml my_config.yaml
配置文件示例:
# API Configuration
api_key: "your_api_key_here"
base_url: "https://app-api.pixverseai.cn"
# Request Configuration
timeout: 30
max_retries: 3
retry_delay: 1.0
# Rate Limiting
rate_limit_requests: 100
rate_limit_window: 60
# Logging
log_level: "INFO"
log_file: null
# MCP Server Configuration
server_name: "pixverse-mcp"
server_version: "1.0.0"
方式2: 环境变量
Copy env.example to .env and configure:
cp env.example .env
Required variables:
PIXVERSE_API_KEY: Your Pixverse API key
Optional variables:
PIXVERSE_BASE_URL: API base URL (default: https://app-api.pixverseai.cn)PIXVERSE_TIMEOUT: Request timeout in seconds (default: 30)PIXVERSE_MAX_RETRIES: Max retries for failed requests (default: 3)PIXVERSE_RATE_LIMIT_REQUESTS: Rate limit per minute (default: 100)PIXVERSE_LOG_LEVEL: Logging level (default: INFO)
Usage
As MCP Server
使用配置文件启动:
python run_server.py --config my_config.yaml
或使用环境变量启动:
python run_server.py
查看帮助:
python run_server.py --help
Or directly:
python -m pixverse_mcp.server
As Python Library
import asyncio
from pixverse_mcp import PixverseClient
from pixverse_mcp.models import TextToVideoRequest
async def main():
async with PixverseClient(api_key="your-api-key") as client:
# Quick text-to-video
result = await client.quick_text_video(
prompt="A cat playing piano",
model="v5",
duration=5
)
print(f"Video ID: {result.video_id}")
# Detailed request
request = TextToVideoRequest(
prompt="A beautiful sunset over mountains",
model="v5",
duration=5,
aspect_ratio="16:9",
quality="540p",
sound_effect_switch=True
)
result = await client.text_to_video(request)
print(f"Video ID: {result.video_id}")
asyncio.run(main())
MCP Tools
The server provides the following MCP tools:
text_to_video
Generate video from text prompt.
Parameters:
prompt(required): Text descriptionmodel: Model version (default: "v5")duration: Video duration in seconds (5, 8, 10)aspect_ratio: Video aspect ratioquality: Video qualitystyle: Video style (optional)motion_mode: Motion modesound_effect_switch: Enable sound effects
image_to_video
Generate video from image.
Parameters:
prompt(required): Text descriptionimg_idorimg_ids: Image ID(s)model: Model versionduration: Video durationquality: Video qualitytemplate_id: Template ID (optional)
upload_image
Upload image file and get img_id for video generation.
Parameters:
file_path(required): Path to the image file
Returns:
img_id: Image ID for use in video generationfile_name: Original file nameimage_url: Uploaded image URL
upload_media
Upload media file (video/audio) and get media_id.
Parameters:
file_path(required): Path to the media filemedia_type: Type of media ("video" or "audio")
Returns:
media_id: Media ID for use in video operationsfile_name: Original file namemedia_type: Type of uploaded media
transition_video
Generate transition between two frames.
Parameters:
prompt(required): Text descriptionfirst_frame_img(required): First frame image IDlast_frame_img(required): Last frame image IDmodel: Model version (v3.5+)duration: Video durationquality: Video quality
extend_video
Extend existing video.
Parameters:
prompt(required): Extension descriptionsource_video_idorvideo_media_id: Source videomodel: Model versionduration: Extension durationquality: Video quality
lip_sync_video
Generate lip sync video.
Parameters:
source_video_idorvideo_media_id: Source videoaudio_media_idor TTS parameters: Audio source
sound_effect_video
Add sound effects to video.
Parameters:
sound_effect_content(required): Sound descriptionsource_video_idorvideo_media_id: Source videooriginal_sound_switch: Keep original sound
fusion_video
Generate multi-subject fusion video.
Parameters:
prompt(required): Text with @ref_name referencesimage_references(required): Array of image referencesduration: Video durationquality: Video qualityaspect_ratio: Video aspect ratio
get_tts_speakers
Get available TTS speakers for lip sync.
Parameters:
page_num: Page number (default: 1)page_size: Page size (default: 30)
Model Constraints
V5 Model
- Does not support
motion_mode: "fast" - Recommended:
duration: 5,quality: "540p" - Sound effects enabled by default
Quality Constraints
1080pdoes not supportduration > 5fastmotion mode only supportsduration ≤ 5
Parameter Conflicts
template_idandcamera_movementare mutually exclusiveimg_idandimg_idsare mutually exclusivesound_effect_contentandsound_modeare mutually exclusivesource_video_idandvideo_media_idare mutually exclusive
Error Handling
The client provides comprehensive error handling:
PixverseAPIError: API-level errorsPixverseAuthError: Authentication failuresPixverseRateLimitError: Rate limit exceededPixverseValidationError: Request validation errorsPixverseTimeoutError: Request timeoutsPixverseConnectionError: Connection issues
Development
Setup
# Install development dependencies
pip install -e ".[dev]"
# Install pre-commit hooks
pre-commit install
Testing
# Run tests
pytest
# Run with coverage
pytest --cov=src/pixverse_mcp
Code Quality
# Format code
black src/ tests/
# Sort imports
isort src/ tests/
# Lint code
flake8 src/ tests/
# Type checking
mypy src/
Popular Templates
| Template ID | Name | Use Case |
|---|---|---|
| 315446315336768 | Kiss Kiss | Romantic scenes |
| 315447659476032 | Kungfu Club | Action scenes |
| 315447659476033 | Earth Zoom | Sci-fi scenes |
| 316826014376384 | General Effects | Universal effects |
License
MIT License - see LICENSE file for details.
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Run quality checks
- Submit a pull request
Support
For issues and questions:
- GitHub Issues: [repository-url]/issues
- Documentation: [docs-url]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pixverse_mcp-0.1.2.tar.gz.
File metadata
- Download URL: pixverse_mcp-0.1.2.tar.gz
- Upload date:
- Size: 25.7 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b3cf2db30a8dacd7a18f1f2bcb40ee77407417eb61ed809417a987133a0fbedc
|
|
| MD5 |
566e73a5de14ebe693adec3a50e4c3ab
|
|
| BLAKE2b-256 |
2c3607cce0e658c036d0fd5e73d79fd94750a81a4fb5351203283ceea5e7c3a5
|
File details
Details for the file pixverse_mcp-0.1.2-py3-none-any.whl.
File metadata
- Download URL: pixverse_mcp-0.1.2-py3-none-any.whl
- Upload date:
- Size: 31.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9233be60c501df14f3a72f2ddaa8faf00ff1851195d30fdbad4aeb4012aa26f3
|
|
| MD5 |
a38f31d49d01a2b9234bdd57e3d1b43f
|
|
| BLAKE2b-256 |
e86d5e9b73fa8cf1e2ca6ad6d53e826dfdaf1d2fc5b890cbd9691bbd356e4990
|