Repository navigation
Studio: render MCP Apps widgets in the chat thread - #9301
Conversation
There was a problem hiding this comment.
💡 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".
…only implemented capabilities
There was a problem hiding this comment.
💡 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".
|
pre-commit.ci run |
# Conflicts: # studio/backend/core/inference/tools.py
…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]>
…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]>
`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]`).
MCP servers can return an interactive HTML UI with a tool result (
_meta.ui.resourceUriaui://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'sui/*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
476bea863vs head2336bbc1c, 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.GET /api/mcp/servers/{id}/ui-resourceui://URI visibleLive tool call on a local model
Merge base
ed7a07863vs head7644b5ebb, two isolated Studio installs, Chromium,unsloth/Qwen3-8B-GGUF(Q4_K_M) loaded on a GPU. A local fastmcp server declaresget_weatherwith aui://template and an app-onlyrefresh_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.The widget's own tool call waits on the same approval prompt as the model's calls:
Weather in Paris | 21 °CThis app wants to run refresh_weatherserver says: Paris is still 21 C at the station