@infimind/video-mcp-cli 1.0.2 → 1.0.4

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.
Files changed (2) hide show
  1. package/dist/server.js +55 -5
  2. package/package.json +1 -1
package/dist/server.js CHANGED
@@ -6,6 +6,8 @@
6
6
  */
7
7
  import { Server } from "@modelcontextprotocol/sdk/server/index.js";
8
8
  import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
9
+ import { readFileSync, existsSync } from "fs";
10
+ import { extname, basename } from "path";
9
11
  /**
10
12
  * Create and configure the MCP Server
11
13
  */
@@ -44,7 +46,7 @@ export function createServer(token, apiBaseUrl) {
44
46
  },
45
47
  sourceImage: {
46
48
  type: "string",
47
- description: "可选的参考图片 - 可以是本地文件路径(如 /path/to/image.jpg)或公网 URL",
49
+ description: "可选的参考图片 - 可以是本地文件路径(如 /path/to/image.jpg)或公网 URL。本地文件会被自动转换为 base64",
48
50
  },
49
51
  model: {
50
52
  type: "string",
@@ -98,13 +100,13 @@ export function createServer(token, apiBaseUrl) {
98
100
  {
99
101
  name: "create_video_analysis_task",
100
102
  description: "创建视频拆解任务,将视频拆解为脚本、风格、卖点话术、爆款公式,并生成用于视频创作的提示词。" +
101
- "支持本地文件路径或公网 URL 作为视频文件。",
103
+ "支持本地文件路径或公网 URL 作为视频文件。本地文件会被自动转换为 base64。",
102
104
  inputSchema: {
103
105
  type: "object",
104
106
  properties: {
105
107
  videoFile: {
106
108
  type: "string",
107
- description: "要分析的视频文件 - 可以是本地文件路径(如 /path/to/video.mp4)或公网 URL",
109
+ description: "要分析的视频文件 - 可以是本地文件路径(如 /path/to/video.mp4)或公网 URL。本地文件会被自动转换为 base64",
108
110
  },
109
111
  },
110
112
  required: ["videoFile"],
@@ -187,6 +189,54 @@ async function handleGetUserInfo(apiBaseUrl, token) {
187
189
  ],
188
190
  };
189
191
  }
192
+ /**
193
+ * 处理文件输入:支持本地文件路径或公网 URL
194
+ * 对于本地文件,读取并转换为 base64
195
+ */
196
+ async function processFileInput(fileInput) {
197
+ // 检查是否是公网 URL
198
+ if (fileInput.startsWith("http://") || fileInput.startsWith("https://")) {
199
+ return {
200
+ data: fileInput,
201
+ fileName: fileInput.split("/").pop() || "file",
202
+ mimeType: "url",
203
+ isUrl: true,
204
+ };
205
+ }
206
+ // 本地文件路径处理
207
+ const filePath = fileInput;
208
+ // 检查文件是否存在
209
+ if (!existsSync(filePath)) {
210
+ throw new Error(`文件不存在: ${filePath}`);
211
+ }
212
+ // 读取文件
213
+ const buffer = readFileSync(filePath);
214
+ // 获取文件扩展名并确定 MIME type
215
+ const ext = extname(filePath).toLowerCase();
216
+ let mimeType = "application/octet-stream";
217
+ const mimeTypes = {
218
+ ".jpg": "image/jpeg",
219
+ ".jpeg": "image/jpeg",
220
+ ".png": "image/png",
221
+ ".gif": "image/gif",
222
+ ".webp": "image/webp",
223
+ ".mp4": "video/mp4",
224
+ ".mov": "video/quicktime",
225
+ ".avi": "video/x-msvideo",
226
+ ".mkv": "video/x-matroska",
227
+ };
228
+ if (ext in mimeTypes) {
229
+ mimeType = mimeTypes[ext];
230
+ }
231
+ // 转换为 base64
232
+ const base64 = `data:${mimeType};base64,${buffer.toString("base64")}`;
233
+ return {
234
+ data: base64,
235
+ fileName: basename(filePath),
236
+ mimeType,
237
+ isUrl: false,
238
+ };
239
+ }
190
240
  /**
191
241
  * Handle create_video_task tool call
192
242
  */
@@ -194,7 +244,7 @@ async function handleCreateVideoTask(apiBaseUrl, token, args) {
194
244
  const response = await callRestApi(apiBaseUrl, "/mcp/video/create", {
195
245
  token,
196
246
  prompt: args.prompt,
197
- sourceImage: args.sourceImage,
247
+ sourceImage: args.sourceImage ? (await processFileInput(args.sourceImage)).data : undefined,
198
248
  model: args.model || "sora_video2-15s",
199
249
  size: args.size || "1280x704",
200
250
  seconds: args.seconds || 10,
@@ -272,7 +322,7 @@ async function handleGetVideoStatus(apiBaseUrl, token, args) {
272
322
  async function handleCreateVideoAnalysisTask(apiBaseUrl, token, args) {
273
323
  const response = await callRestApi(apiBaseUrl, "/mcp/video-analysis/create", {
274
324
  token,
275
- videoFile: args.videoFile,
325
+ videoFile: (await processFileInput(args.videoFile)).data,
276
326
  }, "POST");
277
327
  const result = [
278
328
  `# 视频拆解任务已创建`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infimind/video-mcp-cli",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
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",