Skip to content

core(mcp): direct MCP tool calls drop structuredContent when content is non-empty and omit structured error/resource metadata #64837

Open

Description

@zsicheng0214

Description

Following up on #38923 for OpenCode 2.0 (packages/core): direct MCP tool calls (codemode: false or when Code Mode is disabled) only send tool.state.content to the model (to-llm-message.ts). Three MCP result shapes lose payload details before reaching the model:

  1. When a server returns a short summary or media block in content alongside the real payload in structuredContent (e.g. Go/Python MCP SDK structured helpers), packages/core/src/tool/mcp.ts sets output: result.structured and returns content unchanged. Because content is non-empty, normalizeContent ignores output and the model never sees structuredContent.
  2. When result.isError is true and the server puts error details in structuredContent (or textual EmbeddedResource parts) with empty content, mcp.ts inspects only part.type === "text" and collapses the failure to "MCP tool returned an error".
  3. In packages/core/src/mcp/client.ts (toCallToolResult), UTF-8 text EmbeddedResource items ("text" in resource) return bare resource.text, dropping resource.uri and resource.mimeType (unlike base64 textual resources in mcp.ts, which include [Resource <uri> (<mimeType>)]).

Plugins

None

OpenCode version

2.3.0 (dev)

Steps to reproduce

  1. Register a direct MCP tool (codemode: false) that returns { content: [{ type: "text", text: "1 item" }], structuredContent: { items: [{ id: "A1" }] } } (or { isError: true, content: [], structuredContent: { code: "QUOTA_EXCEEDED" } }).
  2. Execute the tool directly via Tool.Service.
  3. Observe content only contains "1 item" (dropping structuredContent), and the isError call fails with generic "MCP tool returned an error".

Operating System

Linux (Debian 12)

Terminal

Bash

Activity

  1. added
    area/mcp
    type/bug
    version/v2
    on Nov 19, 2026
  2. opencodejr commented on Nov 19, 2026

    @opencodejr
    Contributor

    Seen with a simulated model or a mock server, not a real provider; a maintainer should confirm.

    Thanks for the detailed report. I reproduced all three cases on 2.3.0, and they still happen on the latest dev (d33b578).

    I used a small local stdio MCP server with codemode: false whose three tools return the shapes from your report. A simulated model called each tool directly, and I checked the tool results sent back to the model in the next request:

    • structuredContent with a text summary: the model receives only "1 item"; structuredContent ({items:[{id:"A1"}]}) is dropped.
    • isError: true with empty content and structuredContent: {code: "QUOTA_EXCEEDED"}: the model receives only MCP tool returned an error, with no details.
    • A text EmbeddedResource with uri and mimeType: the model receives only # Notes, with no URI or MIME type.

    The model's tool calls were simulated (there were no provider credentials), but the results came through OpenCode's real MCP path. The script below reproduces it. Your PR #64838 targets this.

    Reproduction script (drive.ts)
    // Reproduces #64837: a direct (codemode: false) MCP tool call drops structuredContent / error details
    // before the tool result reaches the model. Writes the tool results the model receives to /workspace/repro/out-*.json.
    import { Effect, Stream } from "effect"
    import { Llm, OpenCodeDriver } from "opencode-drive"
    import { writeFileSync } from "node:fs"
    
    const label = process.env.OC_DEV ? "dev" : "release"
    export default OpenCodeDriver.use(
      {
        ...(process.env.OC_DEV ? { opencode: { dev: process.env.OC_DEV } } : {}),
        tui: { recording: true },
        config: {
          mcp: { servers: { repro: { type: "local", command: ["node", "/workspace/repro/mcp-server.mjs"], codemode: false } } },
          permissions: [{ action: "repro_*", resource: "*", effect: "allow" }],
        },
      } as any,
      ({ ui, llm }) =>
        Effect.gen(function* () {
          yield* llm.serve((request) => {
            const messages = ((request as any).body?.messages ?? []) as Array<{ role: string }>
            if (!messages.some((m) => m.role === "tool"))
              return Stream.make(
                Llm.toolCall({ index: 0, id: "call_list", name: "repro_list_items", input: {} }),
                Llm.toolCall({ index: 1, id: "call_quota", name: "repro_quota", input: {} }),
                Llm.toolCall({ index: 2, id: "call_doc", name: "repro_doc", input: {} }),
                Llm.finish("tool-calls"),
              )
            writeFileSync(`/workspace/repro/out-${label}.json`, JSON.stringify(request, null, 2))
            return Stream.make(Llm.text("Done reading tool results."))
          })
          yield* ui.submit("Call the repro tools")
          yield* ui.waitFor("Done reading tool results.", { timeout: 60000 } as any)
          yield* ui.screenshot("result")
        }),
    )

    Run it with opencode-drive: opencode-drive run ./drive.ts. It drives opencode from your PATH; set OC_DEV to the path of an OpenCode checkout to run that from source instead.

  3. added
    status/repro-simulated
    on Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/mcpplatform/linuxstatus/repro-simulatedtype/bugversion/v2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions