Add tool result _meta in tool response and access in the ui#677
Open
zekebergida wants to merge 1 commit into
Open
Add tool result _meta in tool response and access in the ui#677zekebergida wants to merge 1 commit into
zekebergida wants to merge 1 commit into
Conversation
idosal
reviewed
Jul 7, 2026
| // Handle tool results from the server. Set before `app.connect()` to avoid | ||
| // missing the initial tool result. | ||
| app.ontoolresult = (result) => { | ||
| console.info("tool-result _meta:", (result as { _meta?: unknown })._meta); |
idosal
reviewed
Jul 7, 2026
| getTimeBtn.addEventListener("click", async () => { | ||
| // `app.callServerTool()` lets the UI request fresh data from the server | ||
| const result = await app.callServerTool({ name: "get-time", arguments: {} }); | ||
| console.info("callServerTool _meta:", (result as { _meta?: unknown })._meta); |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the quickstart MCP App example to demonstrate that tool result _meta is forwarded to the UI (per the Apps spec) by emitting _meta from the server tool and rendering a selected _meta field in the view.
Changes:
- Add
_metato theget-timetool result in the quickstart server. - Display/log tool-result
_metain the quickstart UI (both viaontoolresultandcallServerTool()). - Add a small UI element to show the
_meta.sourcevalue.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| examples/quickstart/src/mcp-app.ts | Reads and displays result._meta in the UI; adds logging for _meta. |
| examples/quickstart/server.ts | Adds _meta fields to the tool result returned by get-time. |
| examples/quickstart/mcp-app.html | Adds a Tool Meta Source field to the quickstart UI. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+11
to
+14
| function extractMetaSource(result: unknown): string { | ||
| const meta = (result as { _meta?: { source?: unknown } })._meta; | ||
| return typeof meta?.source === "string" ? meta.source : "[missing]"; | ||
| } |
Comment on lines
18
to
23
| app.ontoolresult = (result) => { | ||
| console.info("tool-result _meta:", (result as { _meta?: unknown })._meta); | ||
| const time = result.content?.find((c) => c.type === "text")?.text; | ||
| serverTimeEl.textContent = time ?? "[ERROR]"; | ||
| toolMetaSourceEl.textContent = extractMetaSource(result); | ||
| }; |
Comment on lines
28
to
+32
| const result = await app.callServerTool({ name: "get-time", arguments: {} }); | ||
| console.info("callServerTool _meta:", (result as { _meta?: unknown })._meta); | ||
| const time = result.content?.find((c) => c.type === "text")?.text; | ||
| serverTimeEl.textContent = time ?? "[ERROR]"; | ||
| toolMetaSourceEl.textContent = extractMetaSource(result); |
Comment on lines
+40
to
+44
| _meta: { | ||
| timestamp: time, | ||
| source: "quickstart-server", | ||
| debugToken: "quickstart-meta-debug", | ||
| }, |
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.
Include _meta in tool output and access it from the ui
Motivation and Context
While the docs specify that tooloutput _meta is forwarded to the ui and hidden from the model some providers including the basic host in this repo fail to make the _meta available to the ui. This PR will help demonstrate the functionality and can help others troubleshoot this.
How Has This Been Tested?
Claude.ai does forward tool output meta to the ui however chatgpt does not and there are ongoing discussions in developer communities for how to troubleshoot this
Breaking Changes
No
Types of changes
Checklist
Additional context