Stop returning structuredContent in MCP tool call results#214
Merged
Conversation
Some MCP clients discard a tool result's content (text and images) entirely when structuredContent is present, treating it as a replacement. The MCP Apps viewers only need the notebookUrl, which already travels out-of-band via _meta (with the in-content <internal><url> marker as the fallback for hosts that drop _meta), so structuredContent is unnecessary here and actively harmful. - StartMCPServer: stop forwarding structuredContent from tool results; the _meta forwarding is unchanged. - UIResources: drop the now-orphaned StructuredContent key from makeNotebookUIResult -- its only consumer was the forwarding above. - Remove the now-dead structuredContent reads from the evaluator, notebook, and wolframalpha viewers, since nothing can populate them anymore. - Update tests, tool comments, and docs/mcp-apps.md accordingly. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016ixcyVNPpuYCf9k9xnCoYP
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates AgentTools’ MCP tool-call result pipeline and MCP Apps viewers to stop emitting structuredContent, because some MCP clients treat it as a replacement for content and therefore drop model-visible text/images. Notebook UI delivery is preserved via _meta.notebookUrl (plus the existing <internal><url>…</url></internal> marker fallback when _meta is dropped).
Changes:
- Remove
structuredContentforwarding fromKernel/StartMCPServer.wltool results while preserving_metaforwarding. - Stop producing the
StructuredContentkey inmakeNotebookUIResultand delete now-dead viewer logic that readparams/result.structuredContent. - Update tests and documentation to assert/describe
_meta-only delivery for notebook URLs.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| Tests/MCPApps.wlt | Updates expectation to assert StructuredContent is not produced by makeNotebookUIResult. |
| Tests/EvaluatorSessions.wlt | Removes now-moot structured-content preservation test. |
| Kernel/UIResources.wl | Drops StructuredContent from makeNotebookUIResult; updates comments to _meta-only rationale. |
| Kernel/Tools/WolframLanguageEvaluator.wl | Updates UI-result comment to reflect _meta-only delivery. |
| Kernel/Tools/WolframAlpha.wl | Updates UI-result comment to reflect _meta-only delivery. |
| Kernel/StartMCPServer.wl | Stops forwarding structuredContent into MCP tool call results; continues forwarding _meta. |
| docs/mcp-apps.md | Documents _meta-only delivery and explains why structuredContent is intentionally not sent. |
| Assets/Apps/wolframalpha-viewer.html | Removes dead structuredContent parameter plumbing; keeps _meta + marker recovery. |
| Assets/Apps/notebook-viewer.html | Removes dead structuredContent reads; keeps _meta + marker recovery. |
| Assets/Apps/evaluator-viewer.html | Removes dead structuredContent reads; keeps _meta + marker recovery. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Summary
Some MCP clients discard a tool result's
content(text and images) entirely whenstructuredContentis present, using it as a replacement for the model-visible content. That is not what we want. The MCP Apps viewers only need thenotebookUrl, which already travels out-of-band via_meta(with the in-content<internal><url>marker as the fallback for hosts that drop_meta), sostructuredContentis unnecessary here and actively harmful.This PR stops emitting
structuredContentfrom tool call results end-to-end, keeping_metaexactly as-is, and removes the resulting dead code.Changes
Stop sending
structuredContentKernel/StartMCPServer.wl—evaluateToolno longer forwardsstructuredContentinto the tool result. The_metaforwarding (e.g.notebookUrlfor MCP Apps) is unchanged.Kernel/UIResources.wl— dropped the now-orphanedStructuredContentkey frommakeNotebookUIResult; its only consumer was the forwarding above. It now carriesnotebookUrlin_metaonly.Remove the resulting dead code in the viewers
Since
makeNotebookUIResultwas the sole producer of the key and the server no longer emits it,params.structuredContent/result.structuredContentcan never reach a viewer — the reads were unreachable.Assets/Apps/evaluator-viewer.html,notebook-viewer.html,wolframalpha-viewer.html— removed the deadstructuredparameter and its unreachable check fromfindNotebookUrl/handleToolResultand all call sites. The live_meta → per-item _meta → <internal><url>marker recovery chain is unchanged.Tests, comments, docs
Tests/MCPApps.wlt— themakeNotebookUIResulttest now assertsStructuredContentis not produced.Tests/EvaluatorSessions.wlt— removed the mootAppendSessionInfo-PreservesStructuredContenttest (PreservesMetaalready covers generic sibling-key preservation).docs/mcp-apps.mdto reflect_meta-only delivery.Test plan
Tests/MCPApps.wlt— 94/94 passTests/EvaluatorSessions.wlt— 34/34 passTests/NotebookViewer.wlt— 24/24 passTests/MCPAppsTest.wlt— 19/19 passTests/StartMCPServer.wlt— 51/51 non-subprocess tests pass. The 34 failures are pre-existing/environmental: this sandbox can't spawn awolframscriptsubprocess (StartProcess::pnfd→MCPTestServerNotRunning), so the server never starts andevaluateToolis never reached. Should be re-run in an environment that can spawn subprocesses.CodeInspectorclean on all four changed.wlfiles (only pre-existing, unrelatedFixMeCommentwarnings).node --checkon all three extracted viewer scripts — syntax valid.Notes
Related upstream context (hosts dropping
_meta/structuredContent): ext-apps#696. No internal tracking issue.🤖 Generated with Claude Code