Skip to content

Studio: render MCP Apps widgets in the chat thread - #9301

Merged
danielhanchen merged 65 commits into
unslothai:mainfrom
NilayYadav:studio-mcp-apps
Oct 1, 2026
Merged

danielhanchen merged 65 commits into
unslothai:mainfrom
NilayYadav:studio-mcp-apps

Conversation

@NilayYadav

@NilayYadav NilayYadav commented Aug 19, 2026 •

Copy link
Copy Markdown
Collaborator

MCP servers can return an interactive HTML UI with a tool result (_meta.ui.resourceUri a ui:// resource). Studio flattened these to text, so the server looked broken in chat.

Fetches the template via resources/read, renders it in a sandboxed iframe, and bridgesthe widget's ui/* postMessage calls back through the MCP session. Widgets can only reach their own server, and only tools marked "app" visibility. The model's transcript is unchanged.

Before / after

Merge base 476bea863 vs head 2336bbc1c, two isolated installs, Chromium. A local fastmcp server declares one tool with _meta.ui.resourceUri, and the same stored conversation is reopened from history on both sides. BEFORE prints the stored result object, ui:// URI included; AFTER draws the declared template in the sandboxed frame, sized to its content, and keeps only the tool's text under the card. On a base build a live call returns only the plain text, because it never writes the UI envelope.

PR 9301 before/after

Before After
Widget iframes on the card 0 1
GET /api/mcp/servers/{id}/ui-resource 404 200
Raw ui:// URI visible yes no

Live tool call on a local model

Merge base ed7a07863 vs head 7644b5ebb, two isolated Studio installs, Chromium, unsloth/Qwen3-8B-GGUF (Q4_K_M) loaded on a GPU. A local fastmcp server declares get_weather with a ui:// template and an app-only refresh_weather. The model is asked for the weather in Paris and its call is approved. BEFORE shows only the text; AFTER draws the widget seeded with the tool result. Clicking the widget's own button asks the host first, and after Allow the server's reply comes back into the widget.

PR 9301 live before/after

The widget's own tool call waits on the same approval prompt as the model's calls:

PR 9301 widget approval prompt

Before After
Widget iframes on the card 0 1
Widget seeded text none Weather in Paris | 21 °C
Widget tool call prompt none This app wants to run refresh_weather
Widget tool call result none server says: Paris is still 21 C at the station

NilayYadav pushed a commit to NilayYadav/unsloth-staging that referenced this pull request Aug 19, 2026
NilayYadav pushed a commit to NilayYadav/unsloth-staging that referenced this pull request Aug 19, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: de8887fe20

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread studio/backend/routes/mcp_servers.py Resolved
NilayYadav pushed a commit to NilayYadav/unsloth-staging that referenced this pull request Aug 19, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

NilayYadav pushed a commit to NilayYadav/unsloth-staging that referenced this pull request Aug 19, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d248dd7e3d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 22, 2026
@danielhanchen

Copy link
Copy Markdown
Member

pre-commit.ci run

# Conflicts:
#	studio/backend/core/inference/tools.py
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 1, 2026
@danielhanchen
danielhanchen merged commit fa2d246 into unslothai:main Oct 1, 2026
8 of 65 checks passed
ochafik added a commit to ochafik/unsloth that referenced this pull request Oct 2, 2026
…llscreen, model context

Builds on unslothai#9301. Widgets render through the spec's sandbox proxy, served from
a per-server origin on a second port of the host Studio is reached on; the
MCP handshake advertises io.modelcontextprotocol/ui. Widgets mount while the
model streams the tool's arguments (tool-input-partial) and are seeded with
the result without reloading; they are told before a conversation switch
(teardown) and parked rather than destroyed. Fullscreen with a floating chat
bar, model context captured per user turn (images included), widget tool
calls through the chat's permission level, concurrent widget calls on a stdio
session. Documented in studio/MCP.md; covered by backend tests, a spec
compliance suite, and Playwright e2e against a conformance server and four
published apps.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
ochafik added a commit to ochafik/unsloth that referenced this pull request Oct 12, 2026
…llscreen, model context

Builds on unslothai#9301. Widgets render through the spec's sandbox proxy, served from
a per-server origin on a second port of the host Studio is reached on; the
MCP handshake advertises io.modelcontextprotocol/ui. Widgets mount while the
model streams the tool's arguments (tool-input-partial) and are seeded with
the result without reloading; they are told before a conversation switch
(teardown) and parked rather than destroyed. Fullscreen with a floating chat
bar, model context captured per user turn (images included), widget tool
calls through the chat's permission level, concurrent widget calls on a stdio
session. Documented in studio/MCP.md; covered by backend tests, a spec
compliance suite, and Playwright e2e against a conformance server and four
published apps.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
danielhanchen added a commit that referenced this pull request Oct 25, 2026
`studio/backend/tests/test_mcp_servers.py::test_get_enabled_mcp_tools_caches_discovery`
fails now and then in `(Python 3.13, g-r)`, for example on #15279, and
passes when run alone:

```
tests/test_mcp_servers.py:1336: in test_get_enabled_mcp_tools_caches_discovery
E   assert 0 == 1
E    +  where 0 = len([])
```

## Cause

The tests, not the product. `core.inference.mcp_client` keeps discovered
tools (`_tool_cache`) and failed-probe cool-offs
(`_probe_cooloff_until`) as module state keyed by server id, and most
MCP tests name their server `s1`.

1.
`test_mcp_apps.py::test_a_rediscovery_that_fails_or_races_an_edit_caches_nothing`
(from #9301) runs a probe that fails. That correctly records a cool-off
for `s1`, and nothing removes it.
2. When `test_get_enabled_mcp_tools_caches_discovery` later runs on the
same worker, it resets the tool cache but not the cool-off map.
`get_enabled_mcp_tools()` then skips discovery for its own `s1`, so the
fake probe is never called.

How it was found: I ran the 151 MCP-related backend test files with a
detector on that state. It named this leak, plus
`test_mcp_tool_read_off_event_loop.py` leaving `s1` in the tool cache.

Running the two tests in that order reproduces the CI failure every
time.

## Fix

- An autouse fixture in `studio/backend/tests/conftest.py`,
`_forget_mcp_discovery_state`, clears both maps before and after every
test. It follows the other module-state resets already there and does
nothing when `mcp_client` has not been imported.
- `test_mcp_discovery_state_reset_between_tests.py` pins it: two tests
in one xdist group. The first records a cool-off and a cache entry the
way the client does; the second asserts neither survived.

## Verification

- The leak order (`test_mcp_apps.py::test_a_rediscovery...`, then
`test_get_enabled_mcp_tools_caches_discovery`), plus the new pair: 5
passed here. Without the fixture, 2 failed: the caching test and the
pair's second test.
- All 40 backend test files that touch `mcp_client`: 5703 passed here
against 5701 on main, which is the 2 new tests. The same 5 failures on
both sides come from this host's environment (`test_blender_managed.py`
x4 and `test_validate_url_rejects_bad[noscheme.com]`).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

affects UI# new-feature# security# Moves a security boundary: sandbox, allowlist, permission or network guard >3000#

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants