@optilogic/mcp-ui
v0.2.1
Published
MCP Apps UI bridge for Optilogic widgets - postMessage host client, React hooks, and WidgetRoot for building sandboxed opti-ui widgets embedded in Claude
Downloads
285
Readme
@optilogic/mcp-ui
The bridge for building MCP Apps widgets — self-contained HTML UIs that Claude (and other MCP hosts) embed in a sandboxed iframe. It handles the boring, spec-defined parts so a widget is just an opti-ui component plus a data hook:
- Host client — a typed
postMessage/ JSON-RPC transport that speaks the MCP Apps app↔host protocol (handshake, render-data delivery, tool callbacks, host context). - React hooks —
useMcpData()(the tool's render data),useHostTheme()(host light/dark → opti-ui theme),useCallTool()(call a server tool back through the host). <WidgetRoot>— wraps a widget: runs the handshake, injects@optilogic/corestyles + theme, and renders loading / error states so every widget doesn't re-solve them.@optilogic/mcp-ui/testing— a mock host for developing and Storybook-testing widgets offline, with no MCP host in the loop.
Widgets themselves live in the server that owns their tool data contracts (e.g.
opti-mcp/web/widgets/*), not here. This package ships the reusable plumbing + the components they render come from@optilogic/charts/@optilogic/core.
Trust boundary
Everything arriving over postMessage is untrusted input. The transport validates every
inbound message with hand-written type guards (unknown → narrowed) before it reaches
widget code — never a cast. See src/protocol/.
Status
Foundation phase (opti-ui-foundation). The wire contract is being reconciled against the
live MCP Apps spec; the transport's message format is isolated in src/protocol/ as the
single swap-point.
