Skip to content

fix(tui): save clipboard-pasted images to temp files for MCP tool access#21633

Open
mikwiseman wants to merge 1 commit intoanomalyco:devfrom
mikwiseman:fix/save-pasted-images-to-tmpfile
Open

fix(tui): save clipboard-pasted images to temp files for MCP tool access#21633
mikwiseman wants to merge 1 commit intoanomalyco:devfrom
mikwiseman:fix/save-pasted-images-to-tmpfile

Conversation

@mikwiseman
Copy link
Copy Markdown

Issue for this PR

Closes #14673

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

When an image is pasted from the clipboard (Cmd+V / Ctrl+V), OpenCode stores it as an inline data:image/...;base64,... URL. This works for multimodal models, but non-vision models that rely on MCP tools to analyze images break because MCP tools expect a file path on disk, not a raw base64 string.

This PR saves clipboard-pasted images to a temp file in os.tmpdir() and sets the attachment URL to file://..., so MCP tools can read them. The data: URL is kept as fallback if writing fails.

Single file change, ~15 lines added.

How did you verify your code works?

  1. bun run typecheck passes across all 13 packages
  2. Built a local binary (bun run script/build.ts) and verified:
    • Pasting an image from clipboard creates a file at /tmp/opencode-paste-<timestamp>.png
    • The attachment URL is now a file:// URL instead of data:...
    • An MCP tool (custom zai-vision server reading from the temp path) successfully analyzed the pasted screenshot
  3. Verified that non-image attachments are unaffected (no change in behavior)

Screenshots / recordings

No UI changes — purely internal data handling.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

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.

[FEATURE]:Pasted images use data: URL instead of file path, breaking MCP tools for non-vision models

1 participant