-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathmcp_server.py
More file actions
166 lines (143 loc) · 6.03 KB
/
Copy pathmcp_server.py
File metadata and controls
166 lines (143 loc) · 6.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import os
import json
from mcp.server.fastmcp import FastMCP
from seedance_api import SeedanceAPI
# Initialize FastMCP server
mcp = FastMCP("Seedance 2.0 API Server")
# Helper to get API client
def get_api():
return SeedanceAPI()
@mcp.tool()
def text_to_video(prompt: str, aspect_ratio: str = "16:9", duration: int = 5, quality: str = "basic", remove_watermark: bool = False) -> str:
"""
Generate a video from a text prompt using Seedance 2.0.
:param prompt: Descriptive text prompt. Use @character:<id> for consistent characters.
:param aspect_ratio: Video aspect ratio (e.g., '16:9', '9:16', '1:1').
:param duration: Duration in seconds (5 or 10).
:param quality: 'basic' or 'high'.
:param remove_watermark: Whether to remove the MuAPI watermark.
"""
api = get_api()
result = api.text_to_video(prompt, aspect_ratio, duration, quality, remove_watermark)
return json.dumps(result, indent=2)
@mcp.tool()
def image_to_video(prompt: str, images_list: list[str], aspect_ratio: str = "16:9", duration: int = 5, quality: str = "basic", remove_watermark: bool = False) -> str:
"""
Animate static images into a video using Seedance 2.0.
:param prompt: Text prompt guiding the animation.
:param images_list: List of image URLs to animate.
:param aspect_ratio: Video aspect ratio.
:param duration: Duration in seconds.
:param quality: 'basic' or 'high'.
:param remove_watermark: Whether to remove the MuAPI watermark.
"""
api = get_api()
result = api.image_to_video(prompt, images_list, aspect_ratio, duration, quality, remove_watermark)
return json.dumps(result, indent=2)
@mcp.tool()
def omni_reference(prompt: str, aspect_ratio: str = "16:9", duration: int = 5, quality: str = "basic",
images_list: list[str] = None, video_files: list[str] = None, audio_files: list[str] = None) -> str:
"""
Generate a video conditioned on a mix of image, video, and audio references.
:param prompt: Descriptive prompt.
:param aspect_ratio: Video aspect ratio.
:param duration: Duration in seconds.
:param quality: 'basic' or 'high'.
:param images_list: Optional image URLs.
:param video_files: Optional video URLs.
:param audio_files: Optional audio URLs.
"""
api = get_api()
result = api.omni_reference(prompt, aspect_ratio, duration, quality, images_list, video_files, audio_files)
return json.dumps(result, indent=2)
@mcp.tool()
def create_character(images_list: list[str], outfit_description: str, character_name: str = None) -> str:
"""
Create a consistent character sheet from reference photos.
Returns a request_id for a character sheet image.
:param images_list: 1-3 image URLs of a real person.
:param outfit_description: Style/outfit description for the character.
:param character_name: Optional name for the character.
"""
api = get_api()
result = api.create_character(images_list, outfit_description, character_name)
return json.dumps(result, indent=2)
@mcp.tool()
def extend_video(request_id: str, prompt: str = "", duration: int = 5, quality: str = "basic") -> str:
"""
Extend a previously generated Seedance 2.0 video segment.
:param request_id: ID of the video to extend.
:param prompt: Optional prompt for the extension.
:param duration: Seconds to extend (e.g., 5).
:param quality: 'basic' or 'high'.
"""
api = get_api()
result = api.extend_video(request_id, prompt, duration, quality)
return json.dumps(result, indent=2)
@mcp.tool()
def video_edit(prompt: str, video_urls: list[str], images_list: list[str] = None,
aspect_ratio: str = "16:9", quality: str = "basic", remove_watermark: bool = False) -> str:
"""
Edit an existing video or apply styles using natural language.
:param prompt: Describe the desired edits.
:param video_urls: List of video URLs to edit.
:param images_list: Optional reference image URLs.
:param aspect_ratio: Video aspect ratio.
:param quality: 'basic' or 'high'.
:param remove_watermark: Whether to remove the watermark.
"""
api = get_api()
result = api.video_edit(prompt, video_urls, images_list, aspect_ratio, quality, remove_watermark)
return json.dumps(result, indent=2)
@mcp.tool()
def watermark_remover(video_url: str) -> str:
"""
Remove MuAPI watermark from a Seedance video.
"""
api = get_api()
result = api.watermark_remover(video_url)
return json.dumps(result, indent=2)
@mcp.tool()
def watermark_remover_pro(video_url: str) -> str:
"""
Remove MuAPI watermark from a Seedance video (Pro version).
"""
api = get_api()
result = api.watermark_remover_pro(video_url)
return json.dumps(result, indent=2)
@mcp.tool()
def t2v_480p(prompt: str, aspect_ratio: str = "16:9", duration: int = 5, quality: str = "basic") -> str:
"""
Generate a 480p video from text (faster/cheaper).
"""
api = get_api()
result = api.text_to_video_480p(prompt, aspect_ratio, duration, quality)
return json.dumps(result, indent=2)
@mcp.tool()
def i2v_480p(prompt: str, images_list: list[str], aspect_ratio: str = "16:9", duration: int = 5, quality: str = "basic") -> str:
"""
Generate a 480p video from an image (faster/cheaper).
"""
api = get_api()
result = api.image_to_video_480p(prompt, images_list, aspect_ratio, duration, quality)
return json.dumps(result, indent=2)
@mcp.tool()
def upload_file(file_path: str) -> str:
"""
Upload a local file (image or video) to MuAPI for use in generation tasks.
:param file_path: Local path to the file.
"""
api = get_api()
result = api.upload_file(file_path)
return json.dumps(result, indent=2)
@mcp.tool()
def get_task_status(request_id: str) -> str:
"""
Check the status and get results of a generation task.
:param request_id: The ID returned from a generation tool call.
"""
api = get_api()
result = api.get_result(request_id)
return json.dumps(result, indent=2)
if __name__ == "__main__":
mcp.run()