Skip to content

MCP tool results: structuredContent is dropped — only content[].text reaches the model #38923

Closed as not planned

Description

@lexbryan

Summary

When an MCP server returns a tool result carrying both content (text) and structuredContent (structured JSON), opencode forwards only content[].text to the model and discards structuredContent. Any tool that puts its real payload in structuredContent — with a terse human summary in content[].text — becomes unusable from the agent side: the model sees only the summary string, not the data.

Observed

Local stdio MCP server (LaunchWeld mcp-dev, Go, using the Go MCP SDK's idiomatic NewToolResultStructured(data, summary) helper). Its tool responses look like:

{
  "content": [{"type":"text","text":"4 items"}],
  "structuredContent": {"items":[ {"id":"…","title":"…","status":"…", …}, … ]}
}

Calling list_items from an opencode agent returns only 4 items to the model — the entire items array in structuredContent is dropped. Same for single-item reads (get_item_details → 1 item(s), 0 missing, with no fields), list_sprints, list_projects, etc. The model cannot see any of the actual data these tools return, so it cannot act on ticket/project/sprint state.

Confirming it's a client-side drop and not a server omission: invoking the same server binary directly over stdio JSON-RPC returns the full structuredContent payload; the truncation appears only when the result passes through opencode.

Expected

Per the MCP spec, structuredContent carries the structured result and content carries a human-readable representation. Clients should surface the structured data to the model (e.g. by serializing structuredContent as JSON into the tool-result text the model receives), not discard it. The spec explicitly allows servers to put the machine-readable result in structuredContent and a summary in content.

Repro

  1. Configure any MCP server that returns structuredContent (e.g. a Go MCP SDK server using NewToolResultStructured(data, summary)), type: "local" stdio.
  2. Call a tool whose real data lives in structuredContent.
  3. Observe the model receives only the content[].text summary.

Environment

  • opencode CLI; MCP server configured in ~/.config/opencode/opencode.jsonc as type: "local".
  • tool_output.max_bytes / max_lines are not the cause — the data is dropped before those limits apply, at the content-vs-structuredContent selection step.

Suggested fix

When an MCP CallToolResult includes structuredContent, serialize it (JSON) and include it in the tool-result text delivered to the model — appended to content[].text or as an additional content block. At minimum, expose a config flag to surface structuredContent, since the current default makes a large class of spec-compliant MCP servers unusable from agents.

Activity

  1. github-actions commented on Jul 26, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of an existing issue. Please check:

  2. kpom-specter commented on Jul 28, 2026

    @kpom-specter

    I don't think this is a duplicate. It seems that the original fix was logically overwritten by https://github.com/anomalyco/opencode/pull/34505/changes#diff-7bccf1fcd45159d118d7b2f5f84876d4400217d094e306b5dafba501ba6da65cL75

    I found an MCP server with text context only of use structuredContent which... open code uses instead of structuredContent. I think the right fix when both are present is to return the structured content along side of the existing content.

    if (result.structuredContent === undefined || result.structuredContent === null) return result
    
    return {
      ...result,
      content: [
        ...result.content,
        {
          type: "text" as const,
          text: JSON.stringify(result.structuredContent),
        },
      ],
    }
  3. ivocarv commented on Aug 5, 2026

    @ivocarv

    Same here, Ghidra headless mcp doesn't work with opencode because the answers are send on structuredContent: https://github.com/mrphrazer/ghidra-headless-mcp

  4. michele1967lux commented on Aug 23, 2026

    @michele1967lux

    Third independent server hitting this, with a different SDK — Python (mcp 2.0.0), stdio, local.

    Still reproducible on dev today. The discarding happens in packages/opencode/src/mcp/catalog.ts, in the convertTool execute wrapper:

    if (result.content.length > 0 || result.structuredContent === undefined || result.structuredContent === null)
      return result
    return { ...result, content: [{ type: "text", text: JSON.stringify(result.structuredContent) }] }

    The fallback only fires when content is empty. Any server that follows the common pattern — a short human-readable line in content plus the real payload in structuredContent — has the structured half dropped for the model. That's the same line @kpom-specter identified as overwritten by #34505.

    On the open question of what the right fix is when both are present: the 2026-07-28 spec is explicit that a tool returning structured content should also return the serialized JSON in a TextContent block for backwards compatibility — i.e. the two channels are expected to coexist, and structuredContent is the model-facing one. So a client that treats a non-empty content as a reason to discard structuredContent inverts the intent: the text block is the compatibility shim, not the authoritative payload. Forwarding both (or preferring structuredContent when present) is the conforming behaviour; discarding it is not recoverable client-side by the server.

    Practical impact for us: we ship a state handle in structuredContent ({activationId, expiresAt}) so a generic client can carry it across a multi-step round. With this behaviour the model never sees it, and the second step fails — we had to duplicate the handle into the text block as a workaround, which puts a bearer token in the transcript that would otherwise have stayed in the structured channel.

    Happy to test a patch against our server if that helps.

  5. neriousy commented on Oct 22, 2026

    @neriousy
    Member

    Thanks for the detailed report. This was traced to V1 code (packages/opencode/src/mcp/catalog.ts), which isn't part of OpenCode 2.0. V1 now only gets critical fixes, and this isn't one. If you'd like this in OpenCode 2.0, please open a new issue for 2.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions