Repository navigation
feat(mcp): in-card actions on the answer card via an app-only tool (#369) - #374
Merged
Merged
Conversation
) A card control that asks for the same answer with other arguments (a page, a filter chip, a refresh) now updates the MCP Apps card in place instead of sending a new user turn. - New conversation action `rerun` ({args, fallback}) and a chip's `rerun`; every other channel renders it as `send_message` with the fallback. Producer surfaces mark in-card events with the `triton.in_card:` prefix. - App-only tool `triton_ui_event` (`_meta.ui.visibility: ["app"]`, readOnlyHint, `openai/widgetAccessible`), listed only to clients that declared the MCP Apps extension while some tool is in-card capable. - Controls carry an HMAC token (A2UI action key) over (tool, scope, args), bound to tenant, sub, issuer and a <= 24 h expiry; producer tokens name the answer's in-card event names and surfaces. - `Dispatcher::invoke_in_card`: revocation, per-principal rate limit, token, event scope, authorization, and the read-only gate (declared `tools.<name>.in_card` in adapter.yaml AND `readOnlyHint`); one audit line with an `in_card` part (key names and sizes, never values). - Widget: `tools/call` (or `window.openai.callTool`), in-place update, `ui/update-model-context`; on refusal, error, timeout or an unusable answer the control's fallback goes as `ui/message`. Fixes a collapsed frame after a same-height re-render. - Docs: upstream contract §4a, architecture, realizations, widget README. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EqCfXJb5WRqV9Mz4ZkdkjZ
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.
Closes #369.
What
A card control that asks for the same answer with other arguments (a page, a filter chip, a refresh) now updates the MCP Apps answer card in place through an app-only tool, instead of a new user turn (
ui/message, which Claude stages behind a confirmation banner). Decisions D1–D5 as posted on the issue.{"type":"rerun","args":{…},"fallback":"…"}and a chip'srerun.argsare laid over the producing call's arguments. Every other channel (A2A, Gemini Enterprise, Teams, chat, text) renders a rerun assend_messagewithfallback. A producer surface marks an in-card event with the name prefixtriton.in_card:(allowed through passthrough vetting; every othertriton.*name stays reserved).triton_ui_event._meta.ui.visibility: ["app"],annotations.readOnlyHint, legacyopenai/widgetAccessible. Listed only to a client that declared the MCP Apps extension, and only while some tool is in-card capable. Listing is cosmetic: every call is decided by the dispatcher.(tool, scope, args), bound to tenant,sub, issuer and an expiry of at most 24 h. A producer token also names the answer's in-card event names and surfaces. Stateless, with no nonce store, which is acceptable only because the path is read-only.Dispatcher::invoke_in_card(single audit pivot), in this order: revocation, per-principal rate limit (burst 10, 2/s), token, event scope and size limits,can_invoke, read-only gate. The read-only gate needs the tool declared inadapter.yaml(tools.<name>.in_card: true, orDispatcher::with_in_card_toolsfor an embedding host) and annotatedreadOnlyHint(single-flight cache: a yes is kept 60 s, a no 5 s). Exactly one audit line per call, with anin_cardpart: event, component id, token state, and the context's key names and size, never values. The dispatch is buffered, so it cannot turn into an async task.isErrortool result.tools/callwhen the host reportsserverTools, else viawindow.openai.callTool. It replaces the card and sendsui/update-model-contextwith the one-line card text (setWidgetStateon ChatGPT without the bridge). When the call is refused, errors, times out after 15 s, or the answer is one the renderer takes none of, the control'sfallbackgoes out asui/message. A producer event has no fallback (the producer's own text is never sent as the user's). Also fixes a collapsed frame after a same-height re-render.Out of scope, noted in the contract: read-only form submits in place (forms stay
send_message), and drill-down (stays a new turn, D2).Tests
crates/triton-tests/tests/mcp_in_card.rs, real binary + fake agent): tool listed to card hosts only; signed controls for card hosts and fallbacks elsewhere and for undeclared or non-read-only tools; a page turn, a chained page turn and a filter chip update the card without a turn, with_triton.client.in_cardupstream and one audit line; a producer event arrives as_triton.client.a2ui_events; refusals for a writing tool (never reaching the upstream), another principal's, tampered, expired and missing tokens, and an event outside the token's scope; a concurrent burst is rate-limited.deploy/local-e2e/mcp-widget/run.sh, 55 checks): Next sends onetools/calland noui/message, the card shows page 2, the frame keeps its height,ui/update-model-contextis sent once with the card text. Producer refresh carries the result token. Refusal, error, missingserverTools, a silent host (timeout) and a rejected answer each fall back to oneui/message. A no-card answer keeps the card. A producer's injected fallback is never sent. ChatGPTcallToolplus widget state.Local gate:
scripts/check.shpre-push set, 9 of 9 steps green (Flutter at the CI pin 3.44.4).Manual checks still open
Claude and ChatGPT: page a list and check that no composer banner appears, the card updates in place, the audit
subjectmatches the original call's, the tool is absent from the model's tool list, and the model knows the current page. ChatGPT: also whether an approval prompt appears, whetherwidgetAccessibleis needed, and whethercallToolreturns_meta.🤖 Generated with Claude Code
https://claude.ai/code/session_01EqCfXJb5WRqV9Mz4ZkdkjZ
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.