Skip to content

fix(agent-core-v2): reuse uploaded MCP tool images - #4767

Merged
7Sageer merged 1 commit into
MoonshotAI:mainfrom
pvzheroes125:fix/mcp-image-media-reference
Nov 9, 2026
Merged

7Sageer merged 1 commit into
MoonshotAI:mainfrom
pvzheroes125:fix/mcp-image-media-reference

Conversation

@pvzheroes125

Copy link
Copy Markdown
Contributor

Requirement or Bug

在会话中多次调用返回图片的 MCP 工具,例如截图工具。只要旧截图还在上下文里,后续模型请求就会重复发送它的全部数据,导致请求体变大,在慢速网络上可能超时。

Bug Reproduction Steps

  1. 使用支持图片上传和文件引用的 Kimi 模型,调用一个返回 PNG 的 MCP 工具。
  2. 继续对话,让同一个工具结果进入两次模型请求。
  3. 检查请求体,两次都包含同一张图片的 base64。

Root Cause

MCP 转换层会保存原始附件,但输出给模型的图片字段仍然是内联数据。Core 只会对会话附件引用执行已有的图片上传和缓存逻辑。

Code Changes

 MCP 工具返回图片 → 原有格式检查、压缩和大小检查
-→ 内联图片随每次模型请求发送
+→ 引用现有的会话附件,图片压缩后则引用实际交付的压缩版本
+→ Core 首次上传,后续请求使用缓存的文件 ID

转换只在新 MCP 结果生成时执行。无法使用上传引用时,支持内联图片的协议会回退到内联发送。

Behavior Changes and Affected Users

行为 改动前 改动后 受影响人群 退路
新 MCP 结果中的图片 随每次模型请求内联发送 支持图片上传和引用的供应商可以复用首次上传的文件 ID CLI 和其他使用 Core 的客户端中,运行截图或其他图片 MCP 工具的用户 无法保存附件时保留内联。供应商不支持上传且协议支持内联时,由现有解析流程内联
已写入会话的内联图片 随历史读取 按原格式读取 升级后继续旧会话的用户 无需迁移

回归使用 MCP 的 PNG 图片格式走实际请求构建,模拟 HTTP 服务记录到一次文件上传,随后两次模型请求都使用同一个文件引用。还验证了原图复用和压缩图可读。没有在 Windows 上运行真实截图工具。

测试详情
  • Core 的 MCP、媒体和协议路由共 469 项测试通过。
  • Core 类型检查、变更文件 lint、文档构建和 git diff --check 通过。
  • 包级导入检查有一条已存在于主线的错误,位于 src/human/agent/origin.ts。

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: issue must have a maintainer's /approve).
  • I have added tests that prove my feature works.
  • The behavior-change table above is complete, and every removed behavior or flipped default is named in the changeset and either has an escape hatch or was explicitly approved by a maintainer in this PR.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-09T13:23:19.198118Z d908a7e PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@changeset-bot

changeset-bot Bot commented Nov 9, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d908a7e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Nov 9, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@d908a7e
npx https://pkg.pr.new/@moonshot-ai/kimi-code@d908a7e

commit: d908a7e

@7Sageer
7Sageer merged commit 97637e5 into MoonshotAI:main Nov 9, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants