@infimind/video-mcp-cli 1.0.5 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -50,7 +50,7 @@ Add the following to your Claude Desktop configuration file:
50
50
  "command": "sora-mcp",
51
51
  "args": ["--token=YOUR_TOKEN_HERE"],
52
52
  "env": {
53
- "SORA_API_URL": "https://your-api-domain.com/api/trpc"
53
+ "SORA_API_URL": "https://your-api-domain.com/api"
54
54
  }
55
55
  }
56
56
  }
@@ -59,7 +59,7 @@ Add the following to your Claude Desktop configuration file:
59
59
 
60
60
  #### Environment Variables
61
61
 
62
- - `SORA_API_URL` (optional): Your API base URL. Defaults to `http://localhost:3000/api/trpc`
62
+ - `SORA_API_URL` (optional): Your API base URL. Defaults to `http://localhost:3000/api`
63
63
 
64
64
  ### 3. Restart Claude Desktop
65
65
 
@@ -76,6 +76,159 @@ Get information about the authenticated user.
76
76
  Get my user information for the video generator
77
77
  ```
78
78
 
79
+ ### `create_video_task`
80
+
81
+ Create a video generation task.
82
+
83
+ Supported engines:
84
+
85
+ - `S2`: 极睿Sa专业版
86
+ - `S5`: 极睿Sd专业版 (VIP only)
87
+ - `S6`: 极睿Ha专业版 (VIP only)
88
+
89
+ Parameter applicability:
90
+
91
+ | Parameter | S2 极睿Sa专业版 | S5 极睿Sd专业版 | S6 极睿Ha专业版 |
92
+ | --- | --- | --- | --- |
93
+ | `sourceImage` | Optional single image | Not recommended | Standard mode single image |
94
+ | `sourceImages` | Not supported | allinone / firstlast images | reference / edit reference images |
95
+ | `sourceVideos` | Not supported | allinone reference videos | edit input videos |
96
+ | `sourceAudios` | Not supported | allinone reference audio | Not supported |
97
+ | `taskMode` | Not needed | `allinone` / `firstlast` | `standard` / `reference` / `edit` |
98
+ | `resolution` | Not supported | `480p` / `720p` / `1080p` | `720p` / `1080p` |
99
+ | `inputDurationTier` | Not supported | `short` / `medium` / `long` | edit mode only |
100
+ | `ratio` | Not supported | Not supported | reference or text-to-video standard mode |
101
+ | `generateAudio` | Not supported | Optional | Not supported |
102
+ | `webSearchEnabled` | Not supported | Optional | Not supported |
103
+ | `dryRun` | Optional preflight | Optional preflight | Optional preflight |
104
+
105
+ Local file paths and public URLs are both supported. Local files are converted to base64 by the MCP server before being sent to the API.
106
+
107
+ Use `dryRun: true` to validate parameters, VIP access, estimated credits, and media rules without creating a task or deducting credits. The result includes `success`, `dryRun`, `route`, `engineName`, `taskMode`, `estimatedCredits`, `remainingCredits`, and `validationWarnings`.
108
+
109
+ #### Dry run before creating a task
110
+
111
+ ```json
112
+ {
113
+ "prompt": "@图片1 作为角色参考,生成自然的走秀镜头",
114
+ "route": "S6",
115
+ "taskMode": "reference",
116
+ "sourceImages": ["/path/to/character.jpg"],
117
+ "seconds": 10,
118
+ "ratio": "9:16",
119
+ "resolution": "720p",
120
+ "dryRun": true
121
+ }
122
+ ```
123
+
124
+ #### 极睿Sa专业版 - 标准生成
125
+
126
+ ```json
127
+ {
128
+ "prompt": "一个高质感的产品展示视频,柔和布光,镜头缓慢推进",
129
+ "route": "S2",
130
+ "sourceImage": "/path/to/product.jpg",
131
+ "seconds": 10,
132
+ "size": "720x1280",
133
+ "language": "zh-CN",
134
+ "count": 1
135
+ }
136
+ ```
137
+
138
+ #### 极睿Sd专业版 - 全能参考
139
+
140
+ ```json
141
+ {
142
+ "prompt": "根据参考素材生成一个高质感产品展示视频",
143
+ "route": "S5",
144
+ "taskMode": "allinone",
145
+ "sourceImages": ["/path/to/reference.jpg"],
146
+ "sourceVideos": ["/path/to/reference.mp4"],
147
+ "sourceAudios": ["/path/to/music.mp3"],
148
+ "seconds": 10,
149
+ "size": "720x1280",
150
+ "resolution": "720p",
151
+ "inputDurationTier": "medium",
152
+ "generateAudio": true,
153
+ "webSearchEnabled": false
154
+ }
155
+ ```
156
+
157
+ #### 极睿Sd专业版 - 首尾帧
158
+
159
+ ```json
160
+ {
161
+ "prompt": "从首帧自然过渡到尾帧,保持产品主体一致",
162
+ "route": "S5",
163
+ "taskMode": "firstlast",
164
+ "sourceImages": ["/path/to/first-frame.jpg", "/path/to/end-frame.jpg"],
165
+ "seconds": 5,
166
+ "size": "1280x720",
167
+ "resolution": "720p"
168
+ }
169
+ ```
170
+
171
+ #### 极睿Ha专业版 - 标准模式
172
+
173
+ Text-to-video:
174
+
175
+ ```json
176
+ {
177
+ "prompt": "一段电影感城市夜景镜头,雨后街道反光,霓虹灯闪烁",
178
+ "route": "S6",
179
+ "taskMode": "standard",
180
+ "seconds": 5,
181
+ "size": "1280x720",
182
+ "ratio": "16:9",
183
+ "resolution": "720p"
184
+ }
185
+ ```
186
+
187
+ Image-to-video:
188
+
189
+ ```json
190
+ {
191
+ "prompt": "让参考图中的商品在干净摄影棚中缓慢旋转展示",
192
+ "route": "S6",
193
+ "taskMode": "standard",
194
+ "sourceImage": "/path/to/product.jpg",
195
+ "seconds": 5,
196
+ "size": "720x1280",
197
+ "resolution": "720p"
198
+ }
199
+ ```
200
+
201
+ #### 极睿Ha专业版 - 图片参考
202
+
203
+ ```json
204
+ {
205
+ "prompt": "@图片1 和 @图片2 作为角色参考,生成自然的走秀镜头",
206
+ "route": "S6",
207
+ "taskMode": "reference",
208
+ "sourceImages": ["/path/to/character-1.jpg", "/path/to/character-2.jpg"],
209
+ "seconds": 10,
210
+ "size": "720x1280",
211
+ "ratio": "9:16",
212
+ "resolution": "720p"
213
+ }
214
+ ```
215
+
216
+ #### 极睿Ha专业版 - 视频编辑
217
+
218
+ ```json
219
+ {
220
+ "prompt": "增强视频的电影感光影,保持人物和商品一致",
221
+ "route": "S6",
222
+ "taskMode": "edit",
223
+ "sourceVideos": ["/path/to/input.mp4"],
224
+ "sourceImages": ["/path/to/reference.jpg"],
225
+ "resolution": "720p",
226
+ "inputDurationTier": "medium"
227
+ }
228
+ ```
229
+
230
+ After creating a task, use `get_video_status` with the returned `taskId` to query progress and video links.
231
+
79
232
  ## Development
80
233
 
81
234
  ```bash
@@ -89,10 +242,65 @@ npm install
89
242
  # Build
90
243
  npm run build
91
244
 
245
+ # Run MCP smoke tests
246
+ npm run test:smoke
247
+
92
248
  # Run in development mode
93
249
  node dist/index.js --token=YOUR_TOKEN
94
250
  ```
95
251
 
252
+ ### Local MCP testing
253
+
254
+ #### MCP Inspector
255
+
256
+ ```bash
257
+ cd mcp-server
258
+ npm run build
259
+ npx @modelcontextprotocol/inspector node dist/index.js --token=YOUR_TOKEN
260
+ ```
261
+
262
+ Set `SORA_API_URL=http://localhost:3000/api` when testing against a local app server.
263
+
264
+ #### Claude Desktop with local build
265
+
266
+ ```json
267
+ {
268
+ "mcpServers": {
269
+ "sora-video-generator-local": {
270
+ "command": "node",
271
+ "args": ["/absolute/path/to/sora_video_generator/mcp-server/dist/index.js", "--token=YOUR_TOKEN"],
272
+ "env": {
273
+ "SORA_API_URL": "http://localhost:3000/api"
274
+ }
275
+ }
276
+ }
277
+ }
278
+ ```
279
+
280
+ #### npx against the published package
281
+
282
+ ```json
283
+ {
284
+ "mcpServers": {
285
+ "sora-video-generator": {
286
+ "command": "npx",
287
+ "args": ["-y", "@infimind/video-mcp-cli", "--token=YOUR_TOKEN"],
288
+ "env": {
289
+ "SORA_API_URL": "https://your-api-domain.com/api"
290
+ }
291
+ }
292
+ }
293
+ }
294
+ ```
295
+
296
+ ### Troubleshooting
297
+
298
+ - If a client reports schema mismatch, run `npm run build` and `npm run test:smoke` in `mcp-server`.
299
+ - If `get_video_status` cannot connect, verify `SORA_API_URL` includes `/api`, for example `http://localhost:3000/api`.
300
+ - If S5/S6 returns VIP errors, confirm the MCP token belongs to a VIP user.
301
+ - If S6 reference/edit prompts contain `@图片N`, keep the original markers; those modes skip prompt translation to preserve image references.
302
+ - If local file inputs fail, use absolute paths and supported media types: jpg/png/webp/gif, mp4/mov/avi/mkv, mp3/wav/m4a/aac/ogg.
303
+
96
304
  ## Publishing
97
305
 
98
306
  ```bash
package/dist/server.js CHANGED
@@ -8,13 +8,26 @@ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
8
8
  import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
9
9
  import { readFileSync, existsSync } from "fs";
10
10
  import { extname, basename } from "path";
11
+ import { MCP_SERVER_VERSION, getMcpDefaultTaskMode, getMcpEngineName, getMcpVideoStatusHint, isMcpRoute, isValidMcpTaskMode, } from "./videoRules.js";
12
+ class McpToolError extends Error {
13
+ code;
14
+ route;
15
+ engineName;
16
+ constructor(message, code = "BAD_REQUEST", route) {
17
+ super(message);
18
+ this.name = "McpToolError";
19
+ this.code = code;
20
+ this.route = route;
21
+ this.engineName = route ? getMcpEngineName(route) : undefined;
22
+ }
23
+ }
11
24
  /**
12
25
  * Create and configure the MCP Server
13
26
  */
14
27
  export function createServer(token, apiBaseUrl) {
15
28
  const server = new Server({
16
29
  name: "sora-video-generator-mcp",
17
- version: "1.0.0",
30
+ version: MCP_SERVER_VERSION,
18
31
  }, {
19
32
  capabilities: {
20
33
  tools: {},
@@ -27,15 +40,34 @@ export function createServer(token, apiBaseUrl) {
27
40
  const tools = [
28
41
  {
29
42
  name: "get_user_info",
43
+ title: "获取用户信息",
30
44
  description: "获取当前用户的信息,包括用户名、姓名、邮箱、角色、积分和 VIP 状态",
31
45
  inputSchema: {
32
46
  type: "object",
33
47
  properties: {},
34
48
  },
49
+ outputSchema: {
50
+ type: "object",
51
+ properties: {
52
+ success: { type: "boolean" },
53
+ id: { type: "number" },
54
+ username: { type: "string" },
55
+ name: { type: ["string", "null"] },
56
+ email: { type: ["string", "null"] },
57
+ role: { type: "string" },
58
+ credits: { type: "number" },
59
+ isVip: { type: "boolean" },
60
+ code: { type: "string" },
61
+ message: { type: "string" },
62
+ },
63
+ required: ["success"],
64
+ },
35
65
  },
36
66
  {
37
67
  name: "create_video_task",
68
+ title: "创建视频生成任务",
38
69
  description: "创建视频生成任务。支持本地文件路径或公网 URL 作为参考图片。" +
70
+ "支持极睿Sd专业版和极睿Ha专业版的多模态素材输入。" +
39
71
  "提示词会根据目标语言自动翻译和优化。",
40
72
  inputSchema: {
41
73
  type: "object",
@@ -46,16 +78,31 @@ export function createServer(token, apiBaseUrl) {
46
78
  },
47
79
  sourceImage: {
48
80
  type: "string",
49
- description: "可选的参考图片 - 可以是本地文件路径(如 /path/to/image.jpg)或公网 URL。本地文件会被自动转换为 base64",
81
+ description: "可选的单张参考图片。S2 使用此字段;S6 标准模式可用作单图图生视频。可以是本地文件路径或公网 URL,本地文件会被自动转换为 base64",
82
+ },
83
+ sourceImages: {
84
+ type: "array",
85
+ description: "S5/S6 多张参考图片。本地文件路径或公网 URL 数组;本地文件会被自动转换为 base64。S5 首尾帧模式下第1张为首帧、第2张为尾帧;S6 reference/edit 模式作为参考图",
86
+ items: { type: "string" },
87
+ },
88
+ sourceVideos: {
89
+ type: "array",
90
+ description: "S5 全能参考或 S6 视频编辑模式的视频素材。本地文件路径或公网 URL 数组;本地文件会被自动转换为 base64",
91
+ items: { type: "string" },
92
+ },
93
+ sourceAudios: {
94
+ type: "array",
95
+ description: "S5 全能参考模式的音频素材。本地文件路径或公网 URL 数组;本地文件会被自动转换为 base64",
96
+ items: { type: "string" },
50
97
  },
51
98
  size: {
52
99
  type: "string",
53
- description: "视频分辨率(默认:1280x720)",
54
- enum: ["1280x720", "720x1280"],
100
+ description: "视频方向/比例。S2 支持横竖屏;S5/S6 还支持正方形、4:3、3:4(默认:1280x720)",
101
+ enum: ["1280x720", "720x1280", "1024x1024", "1024x768", "768x1024"],
55
102
  },
56
103
  seconds: {
57
104
  type: "number",
58
- description: "视频时长(秒)。S2路线: 10或15秒;S5路线: 5、10或15秒",
105
+ description: "视频时长(秒)。S2=10或15秒;S5极睿Sd专业版=5、10或15秒;S6极睿Ha专业版 standard/reference=5、10或15秒,edit 模式由输入视频决定",
59
106
  enum: [5, 10, 15],
60
107
  },
61
108
  language: {
@@ -71,15 +118,70 @@ export function createServer(token, apiBaseUrl) {
71
118
  },
72
119
  route: {
73
120
  type: "string",
74
- description: "使用的 API 线路:S2=sora(默认)或 S5=seedance。注意:S5 (Seedance) 仅限 VIP 用户使用",
75
- enum: ["S2", "S5"],
121
+ description: "使用的生成引擎:S2=极睿Sa专业版(默认)、S5=极睿Sd专业版、S6=极睿Ha专业版。注意:S5、S6 仅限 VIP 用户使用",
122
+ enum: ["S2", "S5", "S6"],
123
+ },
124
+ taskMode: {
125
+ type: "string",
126
+ description: "引擎模式。S5: allinone=全能参考、firstlast=首尾帧;S6: standard=标准模式、reference=图片参考、edit=视频编辑",
127
+ enum: ["allinone", "firstlast", "standard", "reference", "edit"],
128
+ },
129
+ resolution: {
130
+ type: "string",
131
+ description: "S5/S6 输出清晰度(默认:720p)",
132
+ enum: ["480p", "720p", "1080p"],
133
+ },
134
+ inputDurationTier: {
135
+ type: "string",
136
+ description: "S5 或 S6 edit 模式的输入素材时长档位:short=0-4秒、medium=5-10秒、long=11-15秒(默认:short)",
137
+ enum: ["short", "medium", "long"],
138
+ },
139
+ ratio: {
140
+ type: "string",
141
+ description: "S6 图片参考或标准文生视频模式的宽高比,例如 9:16、16:9、1:1、4:3、3:4",
142
+ enum: ["16:9", "9:16", "1:1", "4:3", "3:4"],
143
+ },
144
+ generateAudio: {
145
+ type: "boolean",
146
+ description: "S5 极睿Sd专业版是否生成音频(默认:true)",
147
+ },
148
+ webSearchEnabled: {
149
+ type: "boolean",
150
+ description: "S5 极睿Sd专业版是否启用 Agent 增强(默认:false)",
151
+ },
152
+ dryRun: {
153
+ type: "boolean",
154
+ description: "仅执行参数、素材、权限和积分预检,不创建任务、不扣费。适合在正式创建前确认 S5/S6 参数是否可用",
76
155
  },
77
156
  },
78
157
  required: ["prompt"],
79
158
  },
159
+ outputSchema: {
160
+ type: "object",
161
+ properties: {
162
+ success: { type: "boolean" },
163
+ taskId: { type: "number" },
164
+ route: { type: "string" },
165
+ engineName: { type: "string" },
166
+ taskMode: { type: "string" },
167
+ videoCount: { type: "number" },
168
+ dryRun: { type: "boolean" },
169
+ estimatedCredits: { type: "number" },
170
+ remainingCredits: { type: "number" },
171
+ statusHint: { type: "string" },
172
+ validationWarnings: {
173
+ type: "array",
174
+ items: { type: "string" },
175
+ },
176
+ code: { type: "string" },
177
+ message: { type: "string" },
178
+ },
179
+ required: ["success"],
180
+ },
80
181
  },
81
182
  {
82
183
  name: "get_video_status",
184
+ title: "查询视频生成状态",
83
185
  description: "获取视频生成任务的状态,包括进度和视频 URL",
84
186
  inputSchema: {
85
187
  type: "object",
@@ -91,9 +193,40 @@ export function createServer(token, apiBaseUrl) {
91
193
  },
92
194
  required: ["taskId"],
93
195
  },
196
+ outputSchema: {
197
+ type: "object",
198
+ properties: {
199
+ success: { type: "boolean" },
200
+ taskId: { type: "number" },
201
+ status: { type: "string" },
202
+ progress: { type: "number" },
203
+ totalVideos: { type: "number" },
204
+ completedVideos: { type: "number" },
205
+ code: { type: "string" },
206
+ message: { type: "string" },
207
+ route: { type: "string" },
208
+ engineName: { type: "string" },
209
+ videos: {
210
+ type: "array",
211
+ items: {
212
+ type: "object",
213
+ properties: {
214
+ id: { type: "number" },
215
+ status: { type: "string" },
216
+ videoUrl: { type: ["string", "null"] },
217
+ thumbnailUrl: { type: ["string", "null"] },
218
+ errorMessage: { type: ["string", "null"] },
219
+ },
220
+ required: ["id", "status", "videoUrl", "thumbnailUrl", "errorMessage"],
221
+ },
222
+ },
223
+ },
224
+ required: ["success"],
225
+ },
94
226
  },
95
227
  {
96
228
  name: "create_video_analysis_task",
229
+ title: "创建视频拆解任务",
97
230
  description: "创建视频拆解任务,将视频拆解为脚本、风格、卖点话术、爆款公式,并生成用于视频创作的提示词。" +
98
231
  "支持本地文件路径或公网 URL 作为视频文件。本地文件会被自动转换为 base64。",
99
232
  inputSchema: {
@@ -106,9 +239,23 @@ export function createServer(token, apiBaseUrl) {
106
239
  },
107
240
  required: ["videoFile"],
108
241
  },
242
+ outputSchema: {
243
+ type: "object",
244
+ properties: {
245
+ success: { type: "boolean" },
246
+ analysisId: { type: "number" },
247
+ creditsUsed: { type: "number" },
248
+ remainingCredits: { type: "number" },
249
+ statusHint: { type: "string" },
250
+ code: { type: "string" },
251
+ message: { type: "string" },
252
+ },
253
+ required: ["success"],
254
+ },
109
255
  },
110
256
  {
111
257
  name: "get_video_analysis_status",
258
+ title: "查询视频拆解状态",
112
259
  description: "获取视频拆解任务的状态和结果",
113
260
  inputSchema: {
114
261
  type: "object",
@@ -120,6 +267,26 @@ export function createServer(token, apiBaseUrl) {
120
267
  },
121
268
  required: ["analysisId"],
122
269
  },
270
+ outputSchema: {
271
+ type: "object",
272
+ properties: {
273
+ success: { type: "boolean" },
274
+ analysisId: { type: "number" },
275
+ status: { type: "string" },
276
+ conversionProgress: { type: ["number", "null"] },
277
+ script: { type: ["string", "null"] },
278
+ style: { type: ["string", "null"] },
279
+ sellingPoints: { type: ["string", "null"] },
280
+ viralFormula: { type: ["string", "null"] },
281
+ generatedPrompt: { type: ["string", "null"] },
282
+ errorMessage: { type: ["string", "null"] },
283
+ originalVideoUrl: { type: ["string", "null"] },
284
+ videoFileName: { type: ["string", "null"] },
285
+ code: { type: "string" },
286
+ message: { type: "string" },
287
+ },
288
+ required: ["success"],
289
+ },
123
290
  },
124
291
  ];
125
292
  return { tools };
@@ -147,6 +314,7 @@ export function createServer(token, apiBaseUrl) {
147
314
  }
148
315
  catch (error) {
149
316
  const errorMessage = error instanceof Error ? error.message : String(error);
317
+ const toolError = error instanceof McpToolError ? error : undefined;
150
318
  return {
151
319
  content: [
152
320
  {
@@ -154,6 +322,13 @@ export function createServer(token, apiBaseUrl) {
154
322
  text: `错误:${errorMessage}`,
155
323
  },
156
324
  ],
325
+ structuredContent: {
326
+ success: false,
327
+ code: toolError?.code || "INTERNAL_ERROR",
328
+ message: errorMessage,
329
+ route: toolError?.route,
330
+ engineName: toolError?.engineName,
331
+ },
157
332
  isError: true,
158
333
  };
159
334
  }
@@ -182,13 +357,23 @@ async function handleGetUserInfo(apiBaseUrl, token) {
182
357
  text: userInfo,
183
358
  },
184
359
  ],
360
+ structuredContent: {
361
+ success: true,
362
+ id: response.id,
363
+ username: response.username,
364
+ name: response.name,
365
+ email: response.email,
366
+ role: response.role,
367
+ credits: response.credits,
368
+ isVip: Boolean(response.isVip),
369
+ },
185
370
  };
186
371
  }
187
372
  /**
188
373
  * 处理文件输入:支持本地文件路径或公网 URL
189
374
  * 对于本地文件,读取并转换为 base64
190
375
  */
191
- async function processFileInput(fileInput) {
376
+ async function processFileInput(fileInput, expectedType) {
192
377
  // 检查是否是公网 URL
193
378
  if (fileInput.startsWith("http://") || fileInput.startsWith("https://")) {
194
379
  return {
@@ -202,7 +387,7 @@ async function processFileInput(fileInput) {
202
387
  const filePath = fileInput;
203
388
  // 检查文件是否存在
204
389
  if (!existsSync(filePath)) {
205
- throw new Error(`文件不存在: ${filePath}`);
390
+ throw new McpToolError(`文件不存在: ${filePath}`, "FILE_NOT_FOUND");
206
391
  }
207
392
  // 读取文件
208
393
  const buffer = readFileSync(filePath);
@@ -219,9 +404,18 @@ async function processFileInput(fileInput) {
219
404
  ".mov": "video/quicktime",
220
405
  ".avi": "video/x-msvideo",
221
406
  ".mkv": "video/x-matroska",
407
+ ".mp3": "audio/mpeg",
408
+ ".wav": "audio/wav",
409
+ ".m4a": "audio/mp4",
410
+ ".aac": "audio/aac",
411
+ ".ogg": "audio/ogg",
222
412
  };
223
- if (ext in mimeTypes) {
224
- mimeType = mimeTypes[ext];
413
+ if (!(ext in mimeTypes)) {
414
+ throw new McpToolError(`不支持的文件类型:${ext || "无扩展名"}。请使用 jpg/png/webp/gif 图片、mp4/mov/avi/mkv 视频或 mp3/wav/m4a/aac/ogg 音频。`, "UNSUPPORTED_FILE_TYPE");
415
+ }
416
+ mimeType = mimeTypes[ext];
417
+ if (expectedType && !mimeType.startsWith(`${expectedType}/`)) {
418
+ throw new McpToolError(`文件 ${basename(filePath)} 类型不匹配:当前是 ${mimeType},但该字段需要 ${expectedType} 文件。`, "INVALID_FILE_TYPE");
225
419
  }
226
420
  // 转换为 base64
227
421
  const base64 = `data:${mimeType};base64,${buffer.toString("base64")}`;
@@ -232,38 +426,191 @@ async function processFileInput(fileInput) {
232
426
  isUrl: false,
233
427
  };
234
428
  }
429
+ async function processFileInputs(fileInputs, expectedType) {
430
+ if (!Array.isArray(fileInputs) || fileInputs.length === 0) {
431
+ return undefined;
432
+ }
433
+ const processed = await Promise.all(fileInputs
434
+ .filter((fileInput) => typeof fileInput === "string" && fileInput.length > 0)
435
+ .map(async (fileInput) => (await processFileInput(fileInput, expectedType)).data));
436
+ return processed.length > 0 ? processed : undefined;
437
+ }
438
+ function hasItems(value) {
439
+ return Array.isArray(value) && value.some((item) => typeof item === "string" && item.length > 0);
440
+ }
441
+ function normalizeRoute(value) {
442
+ const route = typeof value === "string" ? value : "S2";
443
+ if (!isMcpRoute(route)) {
444
+ throw new McpToolError("route 只能是 S2、S5 或 S6。S2=极睿Sa专业版,S5=极睿Sd专业版,S6=极睿Ha专业版。", "INVALID_ROUTE");
445
+ }
446
+ return route;
447
+ }
448
+ function normalizeTaskMode(route, value) {
449
+ const mode = typeof value === "string" ? value : getMcpDefaultTaskMode(route);
450
+ if (route === "S2") {
451
+ if (value !== undefined) {
452
+ throw new McpToolError("taskMode 仅适用于极睿Sd专业版或极睿Ha专业版;S2 极睿Sa专业版无需传 taskMode。", "UNSUPPORTED_FIELD", route);
453
+ }
454
+ return getMcpDefaultTaskMode(route);
455
+ }
456
+ if (!isValidMcpTaskMode(route, mode)) {
457
+ const allowedModes = route === "S5" ? "allinone 或 firstlast" : "standard、reference 或 edit";
458
+ throw new McpToolError(`${getMcpEngineName(route)} 的 taskMode 只能是 ${allowedModes}。`, "INVALID_TASK_MODE", route);
459
+ }
460
+ return mode;
461
+ }
462
+ function normalizeInputDurationTier(value) {
463
+ const tier = (typeof value === "string" ? value : "short");
464
+ if (!["short", "medium", "long"].includes(tier)) {
465
+ throw new McpToolError("inputDurationTier 只能是 short、medium 或 long。");
466
+ }
467
+ return tier;
468
+ }
469
+ function validateCreateVideoArgs(args) {
470
+ if (!args || typeof args !== "object") {
471
+ throw new McpToolError("请提供视频生成参数。");
472
+ }
473
+ if (!args.prompt || typeof args.prompt !== "string" || !args.prompt.trim()) {
474
+ throw new McpToolError("prompt 不能为空。");
475
+ }
476
+ const route = normalizeRoute(args.route);
477
+ const taskMode = normalizeTaskMode(route, args.taskMode);
478
+ const inputDurationTier = normalizeInputDurationTier(args.inputDurationTier);
479
+ const resolution = typeof args.resolution === "string" ? args.resolution : "720p";
480
+ const dryRun = args.dryRun === true;
481
+ if (route === "S2" && args.seconds === 5) {
482
+ throw new McpToolError("极睿Sa专业版不支持 5 秒视频,请使用 10 或 15 秒。", "INVALID_SECONDS", route);
483
+ }
484
+ if (route === "S2") {
485
+ const unsupported = [
486
+ hasItems(args.sourceImages) ? "sourceImages" : undefined,
487
+ hasItems(args.sourceVideos) ? "sourceVideos" : undefined,
488
+ hasItems(args.sourceAudios) ? "sourceAudios" : undefined,
489
+ args.resolution !== undefined ? "resolution" : undefined,
490
+ args.inputDurationTier !== undefined ? "inputDurationTier" : undefined,
491
+ args.ratio !== undefined ? "ratio" : undefined,
492
+ args.generateAudio !== undefined ? "generateAudio" : undefined,
493
+ args.webSearchEnabled !== undefined ? "webSearchEnabled" : undefined,
494
+ ].filter(Boolean);
495
+ if (unsupported.length > 0) {
496
+ throw new McpToolError(`这些字段不适用于极睿Sa专业版:${unsupported.join("、")}。S2 单图请使用 sourceImage。`, "UNSUPPORTED_FIELD", route);
497
+ }
498
+ }
499
+ if (route === "S5") {
500
+ if (args.sourceImage !== undefined) {
501
+ throw new McpToolError("sourceImage 不适用于极睿Sd专业版;请使用 sourceImages 传参考图或首尾帧。", "UNSUPPORTED_FIELD", route);
502
+ }
503
+ if (args.ratio !== undefined) {
504
+ throw new McpToolError("ratio 仅适用于极睿Ha专业版;极睿Sd专业版请使用 size 控制画面比例。", "UNSUPPORTED_FIELD", route);
505
+ }
506
+ if (taskMode === "firstlast" && !hasItems(args.sourceImages)) {
507
+ throw new McpToolError("极睿Sd专业版首尾帧模式需要在 sourceImages 中提供至少 1 张首帧图片。", "MISSING_SOURCE_IMAGE", route);
508
+ }
509
+ if (taskMode === "firstlast" && (hasItems(args.sourceVideos) || hasItems(args.sourceAudios))) {
510
+ throw new McpToolError("sourceVideos/sourceAudios 仅适用于极睿Sd专业版全能参考模式;首尾帧模式只使用 sourceImages。", "UNSUPPORTED_FIELD", route);
511
+ }
512
+ }
513
+ if (route === "S6") {
514
+ const unsupported = [
515
+ hasItems(args.sourceAudios) ? "sourceAudios" : undefined,
516
+ args.generateAudio !== undefined ? "generateAudio" : undefined,
517
+ args.webSearchEnabled !== undefined ? "webSearchEnabled" : undefined,
518
+ ].filter(Boolean);
519
+ if (unsupported.length > 0) {
520
+ throw new McpToolError(`这些字段仅适用于极睿Sd专业版,不能用于极睿Ha专业版:${unsupported.join("、")}。`, "UNSUPPORTED_FIELD", route);
521
+ }
522
+ if (taskMode === "standard" && (hasItems(args.sourceImages) || hasItems(args.sourceVideos))) {
523
+ throw new McpToolError("极睿Ha专业版标准模式只支持 sourceImage 作为单图输入;多图请使用 reference 模式,视频请使用 edit 模式。", "UNSUPPORTED_FIELD", route);
524
+ }
525
+ if ((taskMode === "reference" || taskMode === "edit") && args.sourceImage !== undefined) {
526
+ throw new McpToolError("sourceImage 仅适用于极睿Ha专业版标准模式;reference/edit 模式请使用 sourceImages。", "UNSUPPORTED_FIELD", route);
527
+ }
528
+ if (taskMode === "reference" && !hasItems(args.sourceImages)) {
529
+ throw new McpToolError("极睿Ha专业版图片参考模式需要在 sourceImages 中提供至少 1 张参考图片。", "MISSING_SOURCE_IMAGE", route);
530
+ }
531
+ if (taskMode === "edit" && !hasItems(args.sourceVideos)) {
532
+ throw new McpToolError("极睿Ha专业版视频编辑模式需要在 sourceVideos 中提供至少 1 个参考视频。", "MISSING_SOURCE_VIDEO", route);
533
+ }
534
+ }
535
+ return {
536
+ route,
537
+ taskMode,
538
+ resolution,
539
+ inputDurationTier,
540
+ dryRun,
541
+ statusHint: getMcpVideoStatusHint(dryRun),
542
+ };
543
+ }
235
544
  /**
236
545
  * Handle create_video_task tool call
237
546
  */
238
547
  async function handleCreateVideoTask(apiBaseUrl, token, args) {
548
+ const normalized = validateCreateVideoArgs(args);
239
549
  const response = await callRestApi(apiBaseUrl, "/mcp/video/create", {
240
550
  token,
241
551
  prompt: args.prompt,
242
- sourceImage: args.sourceImage ? (await processFileInput(args.sourceImage)).data : undefined,
552
+ sourceImage: args.sourceImage ? (await processFileInput(args.sourceImage, "image")).data : undefined,
553
+ sourceImages: await processFileInputs(args.sourceImages, "image"),
554
+ sourceVideos: await processFileInputs(args.sourceVideos, "video"),
555
+ sourceAudios: await processFileInputs(args.sourceAudios, "audio"),
243
556
  size: args.size || "1280x720",
244
557
  seconds: args.seconds || 10,
245
558
  language: args.language || "zh-CN",
246
559
  count: args.count || 1,
247
- route: args.route || "S2",
560
+ route: normalized.route,
561
+ taskMode: normalized.taskMode,
562
+ isFirstLastMode: normalized.taskMode === "firstlast",
563
+ resolution: normalized.resolution,
564
+ inputDurationTier: normalized.inputDurationTier,
565
+ ratio: args.ratio || undefined,
566
+ generateAudio: args.generateAudio,
567
+ webSearchEnabled: args.webSearchEnabled,
568
+ dryRun: normalized.dryRun,
248
569
  }, "POST");
570
+ const route = response.route || normalized.route;
571
+ const engineName = response.engineName || getMcpEngineName(route);
572
+ const taskMode = response.taskMode || normalized.taskMode;
573
+ const estimatedCredits = response.estimatedCredits ?? response.creditsUsed;
574
+ const dryRun = response.dryRun === true || normalized.dryRun;
575
+ const statusHint = response.statusHint || normalized.statusHint;
249
576
  const result = [
250
- `# 视频生成任务已创建`,
577
+ dryRun ? `# 视频生成参数预检通过` : `# 视频生成任务已创建`,
251
578
  ``,
252
- `- **任务 ID**: ${response.taskId}`,
579
+ `- **生成引擎**: ${engineName}`,
580
+ `- **模式**: ${taskMode}`,
253
581
  `- **消息**: ${response.message}`,
254
582
  `- **生成视频数量**: ${response.videoCount}`,
255
- `- **消耗积分**: ${response.creditsUsed}`,
256
- `- **剩余积分**: ${response.remainingCredits}`,
257
- ``,
258
- `使用任务 ID ${response.taskId} 调用 \`get_video_status\` 查看进度。`,
259
- ].join("\n");
583
+ `- **预估积分**: ${estimatedCredits ?? "N/A"}(视频完成后按成功扣费)`,
584
+ `- **当前积分**: ${response.remainingCredits}`,
585
+ ];
586
+ if (!dryRun && response.taskId !== undefined) {
587
+ result.splice(4, 0, `- **任务 ID**: ${response.taskId}`);
588
+ }
589
+ if (response.validationWarnings?.length) {
590
+ result.push(`- **预检提示**: ${response.validationWarnings.join(";")}`);
591
+ }
592
+ result.push(``, statusHint);
260
593
  return {
261
594
  content: [
262
595
  {
263
596
  type: "text",
264
- text: result,
597
+ text: result.join("\n"),
265
598
  },
266
599
  ],
600
+ structuredContent: {
601
+ success: response.success,
602
+ taskId: response.taskId,
603
+ route,
604
+ engineName,
605
+ taskMode,
606
+ videoCount: response.videoCount,
607
+ dryRun,
608
+ estimatedCredits,
609
+ remainingCredits: response.remainingCredits,
610
+ statusHint,
611
+ validationWarnings: response.validationWarnings || [],
612
+ message: response.message,
613
+ },
267
614
  };
268
615
  }
269
616
  /**
@@ -308,6 +655,15 @@ async function handleGetVideoStatus(apiBaseUrl, token, args) {
308
655
  text: result.join("\n"),
309
656
  },
310
657
  ],
658
+ structuredContent: {
659
+ success: true,
660
+ taskId: response.taskId,
661
+ status: response.status,
662
+ progress: response.progress,
663
+ totalVideos: response.totalVideos,
664
+ completedVideos: response.completedVideos,
665
+ videos: response.videos || [],
666
+ },
311
667
  };
312
668
  }
313
669
  /**
@@ -316,7 +672,7 @@ async function handleGetVideoStatus(apiBaseUrl, token, args) {
316
672
  async function handleCreateVideoAnalysisTask(apiBaseUrl, token, args) {
317
673
  const response = await callRestApi(apiBaseUrl, "/mcp/video-analysis/create", {
318
674
  token,
319
- videoFile: (await processFileInput(args.videoFile)).data,
675
+ videoFile: (await processFileInput(args.videoFile, "video")).data,
320
676
  }, "POST");
321
677
  const result = [
322
678
  `# 视频拆解任务已创建`,
@@ -335,6 +691,14 @@ async function handleCreateVideoAnalysisTask(apiBaseUrl, token, args) {
335
691
  text: result,
336
692
  },
337
693
  ],
694
+ structuredContent: {
695
+ success: response.success,
696
+ analysisId: response.analysisId,
697
+ message: response.message,
698
+ creditsUsed: response.creditsUsed,
699
+ remainingCredits: response.remainingCredits,
700
+ statusHint: `使用分析 ID ${response.analysisId} 调用 get_video_analysis_status 查看进度。`,
701
+ },
338
702
  };
339
703
  }
340
704
  /**
@@ -402,6 +766,20 @@ async function handleGetVideoAnalysisStatus(apiBaseUrl, token, args) {
402
766
  text: result.join("\n"),
403
767
  },
404
768
  ],
769
+ structuredContent: {
770
+ success: true,
771
+ analysisId: response.analysisId,
772
+ status: response.status,
773
+ conversionProgress: response.conversionProgress,
774
+ script: response.script,
775
+ style: response.style,
776
+ sellingPoints: response.sellingPoints,
777
+ viralFormula: response.viralFormula,
778
+ generatedPrompt: response.generatedPrompt,
779
+ errorMessage: response.errorMessage,
780
+ originalVideoUrl: response.originalVideoUrl,
781
+ videoFileName: response.videoFileName,
782
+ },
405
783
  };
406
784
  }
407
785
  /**
@@ -432,6 +810,22 @@ async function callRestApi(apiBaseUrl, path, params, method = "GET") {
432
810
  });
433
811
  if (!response.ok) {
434
812
  const errorText = await response.text();
813
+ try {
814
+ const parsed = JSON.parse(errorText);
815
+ const apiError = parsed?.error;
816
+ if (apiError?.message) {
817
+ const toolError = new McpToolError(apiError.message, apiError.code || `HTTP_${response.status}`, apiError.route);
818
+ if (apiError.engineName) {
819
+ toolError.engineName = apiError.engineName;
820
+ }
821
+ throw toolError;
822
+ }
823
+ }
824
+ catch (error) {
825
+ if (error instanceof McpToolError) {
826
+ throw error;
827
+ }
828
+ }
435
829
  throw new Error(`API 请求失败,状态码 ${response.status}: ${errorText}`);
436
830
  }
437
831
  const data = await response.json();
@@ -0,0 +1,17 @@
1
+ export type McpRoute = "S2" | "S5" | "S6";
2
+ export type McpTaskMode = "allinone" | "firstlast" | "standard" | "reference" | "edit";
3
+ export declare const MCP_SERVER_VERSION = "1.0.5";
4
+ export declare const MCP_VIDEO_STATUS_HINT = "\u4EFB\u52A1\u5DF2\u521B\u5EFA\u540E\uFF0C\u4F7F\u7528 get_video_status \u5E76\u4F20\u5165 taskId \u67E5\u8BE2\u751F\u6210\u8FDB\u5EA6\u548C\u89C6\u9891\u94FE\u63A5\u3002";
5
+ export declare const MCP_VIDEO_DRY_RUN_HINT = "dryRun \u4EC5\u5B8C\u6210\u53C2\u6570\u3001\u6743\u9650\u3001\u79EF\u5206\u548C\u7D20\u6750\u89C4\u5219\u9884\u68C0\uFF0C\u4E0D\u4F1A\u521B\u5EFA\u4EFB\u52A1\u6216\u6263\u8D39\u3002";
6
+ export declare const MCP_VIDEO_ENGINES: Record<McpRoute, {
7
+ engineName: string;
8
+ model: string;
9
+ defaultTaskMode: McpTaskMode;
10
+ taskModes: McpTaskMode[];
11
+ }>;
12
+ export declare function isMcpRoute(value: string): value is McpRoute;
13
+ export declare function getMcpEngineName(route: string): string;
14
+ export declare function getMcpTaskModel(route: McpRoute): string;
15
+ export declare function getMcpDefaultTaskMode(route: McpRoute, isFirstLastMode?: boolean): McpTaskMode;
16
+ export declare function isValidMcpTaskMode(route: McpRoute, taskMode: string): taskMode is McpTaskMode;
17
+ export declare function getMcpVideoStatusHint(dryRun?: boolean): string;
@@ -0,0 +1,44 @@
1
+ export const MCP_SERVER_VERSION = "1.0.5";
2
+ export const MCP_VIDEO_STATUS_HINT = "任务已创建后,使用 get_video_status 并传入 taskId 查询生成进度和视频链接。";
3
+ export const MCP_VIDEO_DRY_RUN_HINT = "dryRun 仅完成参数、权限、积分和素材规则预检,不会创建任务或扣费。";
4
+ export const MCP_VIDEO_ENGINES = {
5
+ S2: {
6
+ engineName: "极睿Sa专业版",
7
+ model: "sora-2",
8
+ defaultTaskMode: "standard",
9
+ taskModes: ["standard"],
10
+ },
11
+ S5: {
12
+ engineName: "极睿Sd专业版",
13
+ model: "doubao-seedance-2-0-260128",
14
+ defaultTaskMode: "allinone",
15
+ taskModes: ["allinone", "firstlast"],
16
+ },
17
+ S6: {
18
+ engineName: "极睿Ha专业版",
19
+ model: "happyhorse-1.0",
20
+ defaultTaskMode: "standard",
21
+ taskModes: ["standard", "reference", "edit"],
22
+ },
23
+ };
24
+ export function isMcpRoute(value) {
25
+ return value === "S2" || value === "S5" || value === "S6";
26
+ }
27
+ export function getMcpEngineName(route) {
28
+ return isMcpRoute(route) ? MCP_VIDEO_ENGINES[route].engineName : MCP_VIDEO_ENGINES.S2.engineName;
29
+ }
30
+ export function getMcpTaskModel(route) {
31
+ return MCP_VIDEO_ENGINES[route].model;
32
+ }
33
+ export function getMcpDefaultTaskMode(route, isFirstLastMode) {
34
+ if (route === "S5" && isFirstLastMode === true) {
35
+ return "firstlast";
36
+ }
37
+ return MCP_VIDEO_ENGINES[route].defaultTaskMode;
38
+ }
39
+ export function isValidMcpTaskMode(route, taskMode) {
40
+ return MCP_VIDEO_ENGINES[route].taskModes.includes(taskMode);
41
+ }
42
+ export function getMcpVideoStatusHint(dryRun) {
43
+ return dryRun ? MCP_VIDEO_DRY_RUN_HINT : MCP_VIDEO_STATUS_HINT;
44
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infimind/video-mcp-cli",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "MCP Server for Sora AI Video Generator - Access video generation features through Claude Desktop",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -14,6 +14,7 @@
14
14
  "scripts": {
15
15
  "build": "tsc",
16
16
  "dev": "tsc --watch",
17
+ "test:smoke": "node scripts/smoke-test.mjs",
17
18
  "prepublishOnly": "npm run build"
18
19
  },
19
20
  "keywords": [