Skip to content

fix: save pasted clipboard images to temp files to support MCP tools (#14673)#21547

Closed
mikwiseman wants to merge 1 commit intoanomalyco:devfrom
mikwiseman:fix/paste-images-mcp
Closed

fix: save pasted clipboard images to temp files to support MCP tools (#14673)#21547
mikwiseman wants to merge 1 commit intoanomalyco:devfrom
mikwiseman:fix/paste-images-mcp

Conversation

@mikwiseman
Copy link
Copy Markdown

@mikwiseman mikwiseman commented Apr 8, 2026

Issue for this PR

Closes #14673

Type of change

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

What does this PR do?

Currently, when an image is pasted from the clipboard into the prompt, it gets converted to a Base64 data URL and sent directly to the language model. While this works for multimodal models, it breaks workflows where non-vision models (like GLM-5.1) rely on external MCP tools (like zai-vision) because these tools typically expect a valid file path on disk, not a raw Base64 string.

This PR modifies the pasteAttachment function in packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx.
When an image is pasted from the clipboard (i.e. no filepath exists), it:

  1. Writes the base64 content to a temporary file in os.tmpdir().
  2. Uses the newly created temporary file path (file://...) as the attachment URL.

How did you verify your code works?

Compiled opencode locally (bun run build), confirmed that pasting images from clipboard now creates a temporary image file under /tmp, and verified that MCP servers can now read these files properly without throwing Base64 parsing errors.

Screenshots / recordings

Checklist

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

If you do not follow this template your PR will be automatically rejected.

@github-actions github-actions bot added the needs:compliance This means the issue will auto-close after 2 hours. label Apr 8, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2026

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2026

The following comment was made by an LLM, it may be inaccurate:

Based on my search results, here are the potentially related PRs:

Related PRs found:

  1. feat(tui): improve clipboard paste and drag-and-drop file handling on Linux (feat(tui): improve clipboard paste and drag-and-drop file handling on Linux #14552)

  2. feat(tui): improve drag-drop image path handling for tool access (feat(tui): improve drag-drop image path handling for tool access #17489)

These PRs appear to address similar problems in the clipboard/drag-drop image handling space, though they may have been closed or merged already. The current PR (#21547) is specifically focused on the clipboard paste scenario with temporary file storage for MCP tool compatibility.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2026

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

@github-actions github-actions bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Apr 8, 2026
@github-actions github-actions bot closed this Apr 8, 2026
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