Repository navigation
mcp: send tool content to the model when structuredContent is present - #342190
Open
om singhal (Om-singhaI) wants to merge 1 commit into
Open
om singhal (Om-singhaI) wants to merge 1 commit into
om singhal (Om-singhaI) wants to merge 1 commit into
Conversation
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.
Contributor
There was a problem hiding this comment.
🟢 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #290063
When an MCP tool returns both
contentandstructuredContent,McpToolImplementation.invokeskips every text block meant for the model and sends onlyJSON.stringify(structuredContent). A server that puts the readable answer incontent[].textand metadata instructuredContentends up giving the model only the metadata, as in the Fabric reports on the issue.As noted on the issue,
structuredContentshould not be presented to the model. It is for programmatic use, and MCP Apps read it from the raw result. This change:structuredContentonly when nothing incontentis meant for the model, for example a result with an emptycontentor with onlyaudience: ["user"]text, so those servers keep working. A result with only an image plusstructuredContentnow sends just the image.structuredContentin the tool result details and inmcpOutput, 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
McpToolImplementationand addedmcpLanguageModelToolContribution.test.tswith five tests: text plus structured content, audience annotations, the fallback cases, no duplicate JSON, and image and resource blocks together withmcpOutput.How I tested: I ran the new test file in Node with mocha, and all 5 pass. With the fix reverted and only the
exportkept, 3 of the 5 fail because the model gets the serializedstructuredContentinstead 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.