Skip to content

mcp: send tool content to the model when structuredContent is present - #342190

Open
om singhal (Om-singhaI) wants to merge 1 commit into
microsoft:mainfrom
Om-singhaI:fix/mcp-structured-content-text
Open

om singhal (Om-singhaI) wants to merge 1 commit into
microsoft:mainfrom
Om-singhaI:fix/mcp-structured-content-text

Conversation

@Om-singhaI

Copy link
Copy Markdown

Fixes #290063

When an MCP tool returns both content and structuredContent, McpToolImplementation.invoke skips every text block meant for the model and sends only JSON.stringify(structuredContent). A server that puts the readable answer in content[].text and metadata in structuredContent ends up giving the model only the metadata, as in the Fabric reports on the issue.

As noted on the issue, structuredContent should not be presented to the model. It is for programmatic use, and MCP Apps read it from the raw result. This change:

  1. Always forwards text blocks meant for the model (no audience, or one that includes the assistant), the same way image and resource blocks are already forwarded.
  2. Sends the serialized structuredContent only when nothing in content is meant for the model, for example a result with an empty content or with only audience: ["user"] text, so those servers keep working. A result with only an image plus structuredContent now sends just the image.
  3. Keeps structuredContent in the tool result details and in mcpOutput, so the output view and MCP Apps get the same data as before.

When a server follows the spec and also puts the serialized JSON in a text block, the model gets that block once, not a second copy.

I exported McpToolImplementation and added mcpLanguageModelToolContribution.test.ts with five tests: text plus structured content, audience annotations, the fallback cases, no duplicate JSON, and image and resource blocks together with mcpOutput.

How I tested: I ran the new test file in Node with mocha, and all 5 pass. With the fix reverted and only the export kept, 3 of the 5 fail because the model gets the serialized structuredContent instead of the text, or on top of the image and resource blocks. ESLint with the repo config and the formatter check pass on both files.

When an MCP tool returned both content and structuredContent, the text
blocks meant for the model were dropped and the model only got
JSON.stringify(structuredContent). structuredContent is for programmatic
use and MCP Apps, so the model now gets the content blocks. The
serialized structuredContent is still sent when nothing in content is
meant for the model, so structured only results keep working, and it
stays in the tool result details and mcpOutput for the UI and MCP Apps.
Copilot AI balanced review requested due to automatic review settings October 16, 2026 22:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused changes match the intended behavior with no actionable findings; tests were not rerun.

No open issues 🎉

What changed in this PR

Fixes #290063 by preserving model-facing MCP tool content when structuredContent is present.

Changes:

  • Forwards model-facing content, using structured data only as a fallback.
  • Preserves structured data for output details and MCP Apps.
  • Adds five regression tests covering content forwarding, audience filtering, fallback behavior, and duplication.
File Description
src/​vs/​workbench/​contrib/​mcp/​test/​common/​mcpLanguageModelToolContribution.test.ts Adds regression coverage for mixed tool results.
src/​vs/​workbench/​contrib/​mcp/​common/​mcpLanguageModelToolContribution.ts Updates content forwarding and exports the implementation for tests.

Review effort: Balanced

This branch has not been deployed

No deployments
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: structuredContent in tool result overrides content[].text sent to model

3 participants