From 88120d61c1b850193fbbd8807c8c68d12f3720fa Mon Sep 17 00:00:00 2001 From: kicer Date: Fri, 4 Sep 2026 22:28:39 +0800 Subject: [PATCH] video-gen: drop duration param, restrict image_url to a single URL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The cogvideox-flash API does not accept a duration field — passing one gets rejected upstream. Remove DEFAULT_DURATION, the X-Video-Gen-Duration header parser, and the field forwarded to Zhipu, both in code and README. image_url was documented as accepting up to 2 URLs for first/last frame, but the upstream schema only accepts a single string. Tighten the zod schema to z.string().url().optional() and update README / FAQ to make the single-URL constraint explicit. --- mcp/video-gen/README.md | 9 +++--- mcp/video-gen/src/mcp-server.js | 52 +++++++++++++++------------------ 2 files changed, 28 insertions(+), 33 deletions(-) diff --git a/mcp/video-gen/README.md b/mcp/video-gen/README.md index bc4caba..47ae9f5 100644 --- a/mcp/video-gen/README.md +++ b/mcp/video-gen/README.md @@ -152,7 +152,7 @@ curl -F "file=@/tmp/cat.png" https://video-gen.ai.foresh.com/upload | 名称 | 类型 | 必填 | 说明 | |---|---|---|---| | `prompt` | string | ❌ | 视频文本描述,最大 512 字符 | -| `image_url` | string | ❌ | 参考图 URL(也支持 base64)。最多两张,首张为首帧、第二张为尾帧。图片 ≤ 5MB,格式 png/jpeg/jpg | +| `image_url` | string (URL) | ❌ | 参考图 URL(**单张**,不支持数组 / 多张 / 首尾帧)。图片 ≤ 5MB,格式 png/jpeg/jpg。本地文件请走 `/upload` | | `size` | string | ❌ | 视频尺寸,例如 `1920x1080`、`1080x1920`、`1024x1024`、`1280x960` 等 | | `with_audio` | boolean | ❌ | 是否生成 AI 音效,默认 `false` | @@ -163,7 +163,6 @@ curl -F "file=@/tmp/cat.png" https://video-gen.ai.foresh.com/upload | `X-Video-Gen-Model` / `X-Mcp-Model` / `X-Model` | string | `cogvideox-flash` | 覆盖模型 | | `X-Video-Gen-Quality` | string | `speed` | `speed`(速度优先)或 `quality`(质量优先) | | `X-Video-Gen-Fps` | int | `30` | `30` 或 `60` | -| `X-Video-Gen-Duration` | int | `5` | `5` 或 `10` 秒 | | `X-Video-Gen-Watermark` | bool | `true` | 是否添加 AI 水印;关闭需先在智谱后台签署免责声明 | 模型名串识别顺序(首个非空值生效):`X-Video-Gen-Model` → `X-Mcp-Model` → `X-Model` → 默认。 @@ -360,7 +359,7 @@ package.json # @modelcontextprotocol/sdk + express + multer - **Token 闭包注入**:在 Express 入口处从 header 提取 token,闭包传给 tool 回调;不依赖 SDK 内部字段 - **AI 可见 vs AI 不可见**: - AI 只看到 `prompt / image_url / size / with_audio` - - `model / quality / fps / duration / watermark_enabled` 全部由 HTTP header 注入,避免 AI 误传或被诱导调高价档 + - `model / quality / fps / watermark_enabled` 全部由 HTTP header 注入,避免 AI 误传或被诱导调高价档 - **异步语义暴露给 AI**:服务端不做轮询,`generate_video` 只提交、`query_video` 只查一次。AI 自主决定节奏 - **服务端自动 `request_id`**:每次提交服务端生成一个 UUID 作为智谱 `request_id`,便于日志关联,但不暴露给 AI - **上传接口与 MCP 走同一进程**:额外 `POST /upload` + `GET /uploads/*` 不走 MCP、不鉴权,靠内网隔离;`PUBLIC_BASE_URL` 环境变量控制返回 URL 的拼接 host,AI 看到的 tool description 启动时拼接进真实地址,避免 AI 自由发挥 @@ -385,8 +384,8 @@ A: AI 自己 sleep 几秒再调(建议 2~5 秒间隔)。这是设计取舍 **Q: 视频 URL 多久过期?** A: 智谱签发 URL 默认 24h 左右。需要在收到后及时转存到自己的 OSS/S3。 -**Q: 为什么 quality / fps / duration 不让 AI 直接传?** -A: 这些是技术档位,与成本/单价挂钩。让 AI 自主挑 `quality=quality + fps=60 + duration=10` 会爆账号预算。改成 header 由部署方注入更可控。 +**Q: 为什么 quality / fps 不让 AI 直接传?** +A: 这些是技术档位,与成本/单价挂钩。让 AI 自主挑 `quality=quality + fps=60` 会爆账号预算。改成 header 由部署方注入更可控。 **Q: 能否限制 `size` 白名单?** A: 当前透传给智谱 API,不做强制校验。如需加白名单,修改 `src/mcp-server.js` 中 `generate_video` 的 `size` schema 即可。 diff --git a/mcp/video-gen/src/mcp-server.js b/mcp/video-gen/src/mcp-server.js index 626d25a..89b88fc 100644 --- a/mcp/video-gen/src/mcp-server.js +++ b/mcp/video-gen/src/mcp-server.js @@ -20,7 +20,6 @@ const DEFAULT_MODEL = "cogvideox-flash"; // AI 不可见的服务端默认(可被同名 header 覆盖) const DEFAULT_QUALITY = "speed"; // speed | quality const DEFAULT_FPS = 30; // 30 | 60 -const DEFAULT_DURATION = 5; // 5 | 10 const DEFAULT_WATERMARK_ENABLED = true; // 平台政策默认 true // ===== 上传文件相关 ===== @@ -197,7 +196,6 @@ async function submitVideo({ quality, with_audio, fps, - duration, watermark_enabled, }) { // 平台要求 image_url 和 prompt 至少传一个 @@ -207,7 +205,6 @@ async function submitVideo({ with_audio: Boolean(with_audio), watermark_enabled: Boolean(watermark_enabled), fps, - duration, // 由服务端生成唯一 request_id,便于日志关联;不暴露给 AI request_id: randomUUID(), }; @@ -270,11 +267,12 @@ Uploaded files live in container temp storage and are discarded on restart — d "Video text description (max 512 chars). At least one of prompt / image_url is required." ), image_url: z - .string() - .optional() - .describe( - "Reference image source for image-to-video. String or Array of up to 2 URLs for first/last frame. Image <= 5MB, .png/.jpeg/.jpg." - ), + .string() + .url() + .optional() + .describe( + "Reference image URL for image-to-video. Single URL only. Image <= 5MB, .png/.jpeg/.jpg. Use the /upload endpoint to get a URL from a local file." + ), size: z .string() .optional() @@ -297,15 +295,14 @@ Uploaded files live in container temp storage and are discarded on restart — d } // AI 不可见:全部走 header - const model = pickModel(headers) || DEFAULT_MODEL; - const quality = pickHeaderString(headers, "x-video-gen-quality", DEFAULT_QUALITY); - const fps = pickHeaderInt(headers, "x-video-gen-fps", DEFAULT_FPS); - const duration = pickHeaderInt(headers, "x-video-gen-duration", DEFAULT_DURATION); - const watermark_enabled = pickHeaderBool( - headers, - "x-video-gen-watermark", - DEFAULT_WATERMARK_ENABLED - ); + const model = pickModel(headers) || DEFAULT_MODEL; + const quality = pickHeaderString(headers, "x-video-gen-quality", DEFAULT_QUALITY); + const fps = pickHeaderInt(headers, "x-video-gen-fps", DEFAULT_FPS); + const watermark_enabled = pickHeaderBool( + headers, + "x-video-gen-watermark", + DEFAULT_WATERMARK_ENABLED + ); if (!args.prompt && !args.image_url) { return { @@ -321,17 +318,16 @@ Uploaded files live in container temp storage and are discarded on restart — d try { const data = await submitVideo({ - token, - model, - prompt: args.prompt, - image_url: args.image_url, - size: args.size, - quality, - with_audio: args.with_audio ?? false, - fps, - duration, - watermark_enabled, - }); + token, + model, + prompt: args.prompt, + image_url: args.image_url, + size: args.size, + quality, + with_audio: args.with_audio ?? false, + fps, + watermark_enabled, + }); const summary = `Model: ${model}\n` +