kimi-code icon indicating copy to clipboard operation
kimi-code copied to clipboard

Pasted images fail on text-only models — should offload to file + MCP path

Open grandmaster451 opened this issue 5 months ago • 3 comments

Problem

When a user pastes an image (Cmd-V) while using a text-only model (GLM-5.2, DeepSeek, Qwen, etc.), kimi-code sends the image as image_url content directly to the model API. The model rejects it with:

Error: Current model does not support image input.

The paste fails entirely — the image never reaches the conversation, and there is no fallback path.

Expected behavior

When the active model lacks image_in capability, kimi-code should offload the pasted image to a temp file and insert a text reference (file path) into the conversation instead of rejecting it outright. The agent can then process the image through a vision MCP server (e.g. @z_ai/mcp-server, @playwright/mcp) if one is configured.

This matters because many users pair a text-only coding model with a separate vision MCP server. The current behavior makes paste-to-chat unusable for this setup.

Suggested flow

  1. User pastes image (Cmd-V)
  2. kimi-code checks if the active model supports image_in (from the model capabilities in config.toml)
  3. If yes: send as image_url (current behavior)
  4. If no: save to /tmp/kilo-shots/pasted-{timestamp}.png, insert the file path as text in the input box (or as a system note), and let the agent decide how to process it (ReadMediaFile, vision MCP tool, etc.)

Current workaround

I run a clipboard watcher daemon that intercepts images, saves them to /tmp/kilo-shots/, and replaces the clipboard with the file path text. This works but is external to kimi-code — the fix should be native.

Environment

  • kimi-code v0.18.0
  • macOS (but the issue is cross-platform)
  • Model: zai-coding-plan/glm-5.2 (text-only, capabilities: ["thinking", "tool_use"] — no image_in)
  • Vision MCP: @z_ai/mcp-server (provides analyze_image, extract_text_from_screenshot, etc.)

Config

[models."zai-coding-plan/glm-5.2"]
provider = "zai-coding-plan"
model = "glm-5.2"
max_context_size = 1000000
max_output_size = 131072
capabilities = [ "thinking", "tool_use" ]  # no image_in
display_name = "GLM-5.2"

grandmaster451 avatar Jun 18 '26 23:06 grandmaster451

I can take this. The TUI already tracks pasted-image placeholders and rejects them when the selected model lacks image_in; I'll keep the fix narrow by turning those pasted images into local file-path tags for text-only models, while preserving the current image_url path for vision-capable models.

tt-a1i avatar Jun 20 '26 00:06 tt-a1i

同求。我在尝试把 Qwen-MM-Plugins 作为 vision MCP server 使用时遇到了完全一样的限制。

我的情况分两种:要么模型没声明 image_in,粘贴直接被拒;要么我强制声明 image_in 后,kimi-code 把图片以内联 image_url 形式发给 provider,而 provider 因为模型实际不支持图片而报错。

目前没有任何办法让粘贴的图片走 Qwen-MM-Plugins 的 read_image / ocr / grounding 这些 MCP 工具,尽管这些工具已经注册并可用。

如果框架能把粘贴的图片像不支持的

#921 只改了 CLI/TUI 的 apps/kimi-code/src/tui/*,Web/VSCode 走的 packages/kap-server 路径仍然会把所有图片 inline 成 image_url。网页端的问题我单独在 #<你的新 issue 号> 里跟进。 这样维护者就知道两边都要处理。

xinghui-code avatar Aug 11 '26 05:08 xinghui-code

Confirmed on kimi-code 2.3.3 (2026-10-26 release, Linux), and on this base the fix looks smaller than PR #921 assumes.

Repro

  • Model zhipuai-coding-plan/glm-5.3 through the coding-plan endpoint, capabilities = ["always_thinking", "tool_use"] (no image_in)
  • Paste an image (Ctrl+V) → submit → Error: Current model does not support image input. and the turn is dropped

Declaring image_in is not a workaround

The provider rejects the payload anyway, so forcing the capability just moves the error:

POST https://open.bigmodel.cn/api/coding/paas/v4/chat/completions   model=glm-5.3
→ 400 {"code":"1210","message":"messages.content.type 参数非法,取值范围 ['text']"}

glm-5.3-flash and glm-4.6v accept the identical payload with the same key, so this is model-level, not key- or plan-level. (For contrast, deepseek-v4-pro returns 200 and silently drops the image — arguably worse, since the model may then hallucinate what it saw.)

The machinery PR #921 introduces already exists on 2.3.3

  • materializeImageToCache(att) — writes the image bytes to <dataDir>/cache/<uuid>.<ext> and returns the path
  • buildMediaPathTag(kind, path) → <image path="…"></image>
  • formatMediaReference(kind, path) → Attached image file: … (open it with ReadMediaFile)
  • rewriteMediaPlaceholders(text, store, style) already renders images this way for slash-command arguments (/skill, plugin commands) — only the ordinary prompt path still hard-rejects.

So on this base the change is roughly: in validateMediaCapabilities(), instead of showError(...), degrade the image to a path reference and re-check capabilities. No new file-writing code is required.

The v2 engine already has a media-degradation path, but it is never reached

stripMediaParts() / MEDIA_STRIPPED_PLACEHOLDERS exist in agent-core-v2 for provider-side media rejection (see #2954), but the TUI rejects before the request is sent — and when that path does trigger, the image is dropped rather than turned into something the agent can act on.

We have a working local patch, verified end to end

Byte-level patch of the shipped SEA, on top of 2.3.3:

  • pasted image → saved to ~/.kimi-code/cache/<uuid>.png
  • the prompt carries [image saved to … — the current model cannot see images directly; pass this path to a vision MCP tool to analyze it]
  • the agent hands that path to @z_ai/mcp-server (extract_text_from_screenshot / analyze_image / …) and answers from the extracted text
  • multimodal models are unaffected — they still get the image inline

The patch is intentionally minimal so it can be re-derived after each release, but the underlying change is small enough that a normal PR rebased on 2.3.3 should be straightforward. Happy to open one if that would help — which base would you prefer it against?

chrisxthe avatar Oct 28 '26 10:10 chrisxthe