Skip to content

Support for MCP Apps, Elicitation, and Sampling#1408

Open
vaaale wants to merge 6 commits intoagent0ai:developmentfrom
vaaale:mcp-ui
Open

Support for MCP Apps, Elicitation, and Sampling#1408
vaaale wants to merge 6 commits intoagent0ai:developmentfrom
vaaale:mcp-ui

Conversation

@vaaale
Copy link
Copy Markdown

@vaaale vaaale commented Apr 1, 2026

MCP Apps, Elicitation & Sampling Support

Overview

Adds support for three MCP protocol extensions: MCP Apps (SEP-1865), Elicitation, and Sampling. These enable MCP servers to render interactive UIs in sandboxed iframes, request structured user input, and request LLM completions through the host.

Support for MCP Apps is implemented as a plugin. I'll make a separate PR for that and link it below.
If it should be an extension or part of core, the functionality can of course easily be moved.

Features

MCP Apps (SEP-1865)

  • Renders interactive UI applications from MCP servers in sandboxed iframes within chat messages
  • Implements the full JSON-RPC 2.0 over postMessage bridge between host and sandbox
  • Double-iframe sandbox architecture: outer sandbox (allow-scripts only, opaque origin) wraps an inner iframe with a strict Content Security Policy per the spec
  • Supports tools/call and resources/read proxying from iframe apps back to MCP servers via WebSocket
  • Lifecycle: ui/initialize → initialized → tool-input / tool-result notifications
  • size-changed notification throttling (100ms) and height-only auto-resize with buffer/hysteresis to prevent feedback loops
  • Debounce mechanism for duplicate requests (React StrictMode mitigation)
  • Full plugin implementation in usr/plugins/mcp_apps/

MCP Elicitation

  • Allows MCP servers to request structured input from the user during tool execution
  • ElicitationManager singleton manages pending requests with async event-based resolution
  • Frontend panel renders the elicitation form above the chat input
  • WebSocket handler for user approve/reject actions
  • 5-minute timeout with automatic rejection

MCP Sampling

  • Allows MCP servers to request LLM completions through the host
  • SamplingManager singleton with user approval workflow
  • Routes approved requests to the utility model via build_utility_model()
  • Frontend panel for approve/reject with message preview
  • WebSocket handler for user actions

Core Changes

helpers/mcp_handler.py

  • _initialize_with_ui_ext(): Replaces session.initialize() to inject io.modelcontextprotocol/ui extension capability into ClientCapabilities
  • read_resource(): Added to MCPClientBase, MCPServerRemote, MCPServerLocal, and MCPConfig for reading ui:// resources
  • get_tool_ui_meta(): Added at all levels for looking up _meta.ui on tools
  • update_tools(): Captures _meta.ui from tool metadata into tool_dict["ui_meta"]
  • _execute_with_session(): Injects elicitation and sampling callbacks into ClientSession

agent.py

  • tool_args now passed to tool_execute_after extension point (enables MCP Apps plugin to access original tool arguments)
  • Relaxed validate_tool_request to allow tools with no arguments

New Files

  • helpers/mcp_elicitation.py — ElicitationManager
  • helpers/mcp_sampling.py — SamplingManager
  • extensions/python/webui_ws_event/_20_mcp_elicitation.py
  • extensions/python/webui_ws_event/_21_mcp_sampling.py
  • webui/components/chat/elicitation/ — panel + store
  • webui/components/chat/sampling/ — panel + store
  • webui/index.html & webui/js/messages.js
  • Added elicitation and sampling panel component includes
  • Added mcp_elicitation and mcp_sampling message type handlers

Comments

  • React StrictMode in MCP Apps causes duplicate ui/initialize and tools/call messages (mitigated by debounce, cosmetic console warnings remain)
  • Elicitation, sampling, and MCP Apps UI metadata changes touch core files — these could be refactored into standalone plugins if _execute_with_session() and update_tools() gained @extensible hooks
  • The plugin has a simple MCP server to test the functionality test_mcp/mcp_elicitation_test_server.py

I created a PR for a0-plugins, but it seems that was not the correct thing to do, so I added it to this PR as well.
See PR a0-plugins #183

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants