Skip to content

fix: deliver MCP tool images on the held Run as McpImageContent - #46

Merged
oakimov merged 3 commits into
oakimov:mainfrom
nkoynov:fix/mcp-image-results
Oct 8, 2026
Merged

oakimov merged 3 commits into
oakimov:mainfrom
nkoynov:fix/mcp-image-results

Conversation

@nkoynov

@nkoynov nkoynov commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #45. Stacked on #42 (ReadSuccess.data for image reads).

MCP tool images that OpenCode moves into the trailing Attached media from tool result: message reached Cursor only as history after the next user message. Cursor CLI's MCP executor appends each image as McpImageContent on McpToolResultContentItem field 2 after the success text. This PR does the same on held-Run continuations.

Changes

  • Wire McpImageContent + image case in messages.ts
  • mcp_result success: text items, then image items (CLI order); write/shell stay text-only
  • Normalize host media part shapes (mime/uri, OpenCode 1 type: media) before decode
  • Docs/CHANGELOG: MCP same-turn delivery; history path only for results without an image field
  • Unrelated to GenerateImage / cursor_image_save (MCP content items, not read/write exec)

Tests

  • messages.test.ts, tools.test.ts, continuation-session.test.ts, image-input.test.ts
  • bun test / typecheck / build / architecture gate green

Live A/B + cache (quality bar)

Host Result
OpenCode 1.18.35 Pass — mediaParts=1, continuation: 1 tool-result image(s) on mcp_result (stdio badge MCP, gpt-5.4-mini)
OpenCode 2.0.24 Pass — same (--standalone + local dist/)
Warm cache Pass — second turn continuity=warm, ~99.9% rawReadVsPriorContext on both hosts

Method: automated opencode run against local dist/ (not interactive TTY).

CONTRIBUTING checklist

Merge after #42.

@oakimov

oakimov commented Oct 7, 2026

Copy link
Copy Markdown
Owner

CONTRIBUTING checklist

Per CONTRIBUTING.md, please address:

Live A/B and Fixes #45 look good.

@nkoynov

nkoynov commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

Closing per the new contribution policy. This fix and the others we had open are maintained in our fork: https://github.com/nkoynov/cursor-opencode-provider

@nkoynov nkoynov closed this Oct 7, 2026
@oakimov oakimov reopened this Oct 7, 2026
@oakimov

oakimov commented Oct 7, 2026 •

Copy link
Copy Markdown
Owner

Reopening to land a quality-standard rebase stacked on #42 (MCP McpImageContent on held Runs; OpenCode 1.x + 2.0 live A/B; prompt-cache confirmation).

@oakimov
oakimov force-pushed the fix/mcp-image-results branch from 285275a to e974bf2 Compare October 7, 2026 23:30
@oakimov

oakimov commented Oct 8, 2026

Copy link
Copy Markdown
Owner

CONTRIBUTING checklist (tip e814095):

Live A/B: OC1.18.35 + OC2.0.24 pass (mcp_result image items); warm cache ~99.9% rawReadVsPriorContext. Merge after #42.

nkoynov and others added 3 commits October 8, 2026 14:26
OpenCode moves the images an MCP tool returns into a trailing
`Attached media from tool result:` user message. Since oakimov#34 that message
no longer forces a fresh Run, so the held Run got the MCP result as text
only and the model saw the image at the earliest after the next user
message. The README gave the reason as "Cursor's exec-result channel has
no image field", but agent.v1 has one: Cursor CLI 2026.10.01 declares
`McpImageContent|1 data 12|2 mime_type 9` and
`McpToolResultContentItem|1 text #0 content|2 image oakimov#1 content` in
`agent/v1/mcp_exec_pb.js`, and its MCP executor appends every MCP `image`
item as `{content: {case: "image", value: McpImageContent{data, mimeType}}}`.

Declare the type and the oneof case, and append the images attributed to
an `mcp_result` (the trailing-media path from the read-image change) as
image items after the text, as the CLI does. Update the README and
AGENTS.md: only results without an image field (shell, write) still wait
for the history path.
Normalize host mime/uri and OpenCode 1 type:media tool parts before
ReadSuccess/McpImageContent decode, and log continuation prompt-tail
media counts for cache/live diagnosis.
@oakimov
oakimov force-pushed the fix/mcp-image-results branch from f5bd930 to b82d8ee Compare October 8, 2026 12:28
@oakimov
oakimov merged commit 184b4d7 into oakimov:main Oct 8, 2026
1 check 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.

MCP image results reach the model only after the next user message

2 participants