image_task: 去掉 size 参数,图片尺寸走上游默认(AI 传错值经常报错)
This commit is contained in:
@@ -74,7 +74,8 @@ docker exec mcp_image_task node -e "fetch('http://localhost:3000/health').then(r
|
||||
|---|---|---|---|
|
||||
| `op` | `"create"` | ✅ | 要执行的操作(当前仅 `create`) |
|
||||
| `prompt` | string | ✅ | 图片生成提示词,描述想要的画面内容(仅 op=create 使用) |
|
||||
| `size` | string | ❌ | 图片尺寸,例如 `1024x1024`、`1280x1280`、`1024x1792`、`1792x1024`、`768x1344`、`1344x768`,遵循智谱 API 规格(仅 op=create 使用) |
|
||||
|
||||
> 图片尺寸不再透传,走上游默认;尺寸档位与成本/成功率挂钩,AI 传错值经常直接报错。
|
||||
|
||||
### Model 控制(不在工具参数中暴露)
|
||||
|
||||
@@ -187,8 +188,7 @@ curl -s -X POST http://localhost:8082/mcp \
|
||||
"name": "image_task",
|
||||
"arguments": {
|
||||
"op": "create",
|
||||
"prompt": "一只可爱的小猫咪,坐在阳光明媚的窗台上,背景是蓝天白云",
|
||||
"size": "1280x1280"
|
||||
"prompt": "一只可爱的小猫咪,坐在阳光明媚的窗台上,背景是蓝天白云"
|
||||
}
|
||||
}
|
||||
}'
|
||||
@@ -251,6 +251,3 @@ A: 漏发了 `Mcp-Session-Id` header,或调 `tools/call` 前没先 `initialize
|
||||
|
||||
**Q: URL 多久过期?**
|
||||
A: 智谱签发 URL 默认 24h 左右,详见响应里的 `Expires` 参数。需要长期使用请自行转存到 OSS/S3。
|
||||
|
||||
**Q: 能否限制 `size` 白名单?**
|
||||
A: 当前透传给智谱 API,不做强制校验。如需加白名单,修改 `src/mcp-server.js` 中 `image_task` 的 `size` schema 即可。
|
||||
|
||||
@@ -77,9 +77,8 @@ function pickModel(headers) {
|
||||
return s || null;
|
||||
}
|
||||
|
||||
async function callZhipuImagesGenerations({ token, model, prompt, size }) {
|
||||
async function callZhipuImagesGenerations({ token, model, prompt }) {
|
||||
const body = { model, prompt };
|
||||
if (size) body.size = size;
|
||||
const resp = await fetch(ZHIPU_API_URL, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
@@ -123,14 +122,12 @@ async function handleCreate({ args, headers, token }) {
|
||||
// 不存进 session,每次从本次请求的 header 读取,未设置则用默认 CogView-3-Flash。
|
||||
// AI 看不到 model 参数(schema 中已删除),避免其误传。
|
||||
const model = pickModel(headers) || DEFAULT_MODEL;
|
||||
const size = args.size;
|
||||
|
||||
try {
|
||||
const data = await callZhipuImagesGenerations({
|
||||
token,
|
||||
model,
|
||||
prompt: args.prompt,
|
||||
size,
|
||||
});
|
||||
const urls = extractUrls(data);
|
||||
if (urls.length === 0) {
|
||||
@@ -188,7 +185,7 @@ function buildServer() {
|
||||
"image_task",
|
||||
`Manages image generation. Generation is synchronous: op=create returns the image URLs directly.
|
||||
|
||||
op=create Generate an image from a prompt. Requires prompt; optional size.`,
|
||||
op=create Generate an image from a prompt. Requires prompt.`,
|
||||
{
|
||||
op: z
|
||||
.enum(["create"])
|
||||
@@ -201,12 +198,6 @@ op=create Generate an image from a prompt. Requires prompt; optional size.`,
|
||||
.describe(
|
||||
"Image generation prompt; describe the desired scene in detail. Used with op=create."
|
||||
),
|
||||
size: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe(
|
||||
"Image size, Preferred sizes: 1024x1024, 1280x1280, 1536x1024, 1024x1536, Each side must be a multiple of 32. Used with op=create."
|
||||
),
|
||||
},
|
||||
async (args, extra) => {
|
||||
// SDK 在 tool callback 的 extra.requestInfo.headers 里会透传当前 HTTP 请求的 headers
|
||||
|
||||
Reference in New Issue
Block a user