Skip to content

idosal/mcp-ui

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“¦ Model Context Protocol UI SDK

Server Version Client Version

What's mcp-ui? β€’ Core Concepts β€’ Installation β€’ Quickstart β€’ Core Concepts β€’ Examples β€’ Security β€’ Roadmap β€’ Contributing β€’ License


mcp-ui brings interactive web components to the Model Context Protocol (MCP). Deliver rich, dynamic UI resources directly from your MCP server to be rendered by the client. Take AI interaction to the next level!

This project is an experimental community playground for MCP UI ideas. Expect rapid iteration and enhancements!

mcpui-x.mp4

πŸ’‘ What's mcp-ui?

mcp-ui is a TypeScript SDK comprising two packages:

  • @mcp-ui/server: Utilities to generate UI resource objects (HtmlResourceBlock) on your MCP server.
  • @mcp-ui/client: UI components (e.g., <ResourceRenderer />) to render those blocks in the browser and handle their events.

Together, they let you define reusable UI resource blocks on the server side, seamlessly display them in the client, and react to their actions in the MCP host environment.

North star -

  • Enable servers to deliver rich, interactive UIs with ergonomic APIs
  • Allow any host to support UI with its own look-and-feel
  • Eliminate security concerns (limit/remove local code execution)

✨ Core Concepts

The primary component for rendering MCP resources is <ResourceRenderer />. It automatically detects the resource type and renders the appropriate component.

Supported Resource Types

HTML (text/html and text/uri-list)

Rendered using the <HtmlResource /> component, which displays content inside an <iframe>. This is suitable for self-contained HTML or embedding external apps.

  • mimeType:
    • text/html: Renders inline HTML content.
    • text/uri-list: Renders an external URL. MCP-UI uses the first valid URL.
  • Props:
    • resource: The resource object from an MCP message.
    • onUiAction: A callback function to handle events.
    • supportedContentTypes: (Optional) Array to filter content types ('rawHtml', 'externalUrl').
    • style: (Optional) Custom styles for the iframe.
    • iframeProps: (Optional) Custom iframe props.

Remote DOM (application/vnd.mcp-ui.remote-dom+javascript)

Rendered using the <RemoteDomResource /> component, which uses Shopify's remote-dom. The server responds with a script that describes the UI and events. On the host, the script is securely rendered in a sandboxed iframe, and the UI changes are communicated to the host in JSON, where they're rendered using the host's component library. This is more flexible than iframes and allows for UIs that match the host's look-and-feel.

  • mimeType: application/vnd.mcp-ui.remote-dom; flavor={react | webcomponents}
  • Props:
    • resource: The resource object from an MCP message.
    • library: A component library that maps remote element names (e.g., "button") to actual React or web components. mcp-ui provides a basicComponentLibrary for common HTML elements, and you can provide your own for custom components.
    • onUiAction: A callback function to handle events.

UI Action

UI blocks must be able to interact with the agent. In mcp-ui, this is done by hooking into events sent from the UI block and reacting to them in the host. For example, an HTML may trigger a tool call when a button is clicked by sending an event which will be caught handled by the client.

πŸ—οΈ Installation

# using npm
npm install @mcp-ui/server @mcp-ui/client

# or pnpm
pnpm add @mcp-ui/server @mcp-ui/client

# or yarn
yarn add @mcp-ui/server @mcp-ui/client

🎬 Quickstart

  1. Server-side: Build your resource blocks

    import { createHtmlResource } from '@mcp-ui/server';
    import {
     createRemoteComponent,
     createRemoteDocument,
     createRemoteText,
    } from '@remote-dom/core';
    
    // Inline HTML
    const htmlResource = createHtmlResource({
      uri: 'ui://greeting/1',
      content: { type: 'rawHtml', htmlString: '<p>Hello, MCP UI!</p>' },
      delivery: 'text',
    });
    
    // External URL
    const externalUrlResource = createHtmlResource({
      uri: 'ui://greeting/1',
      content: { type: 'externalUrl', iframeUrl: 'https://example.com' },
      delivery: 'text',
    });
  2. Client-side: Render in your MCP host

    import React from 'react';
    import { ResourceRenderer } from '@mcp-ui/client';
    
    function App({ mcpResource }) {
      if (
        mcpResource.type === 'resource' &&
        mcpResource.resource.uri?.startsWith('ui://')
      ) {
        return (
          <ResourceRenderer
            resource={mcpResource.resource}
            onUiAction={(result) => {
              console.log('Action:', result);
              return { status: 'ok' };
            }}
          />
        );
      }
      return <p>Unsupported resource</p>;
    }
  3. Enjoy interactive MCP UIs β€” no extra configuration required.

🌍 Examples

Client example

  • ui-inspector - inspect local mcp-ui-enabled servers.
  • MCP-UI Chat - interactive chat built with the mcp-ui client. Check out the hosted version!
  • MCP-UI RemoteDOM Playground (examples/remote-dom-demo) - local demo app to test RemoteDOM resources (intended for hosts)

Server example Try out the hosted app -

  • HTTP Streaming: https://remote-mcp-server-authless.idosalomon.workers.dev/mcp
  • SSE: https://remote-mcp-server-authless.idosalomon.workers.dev/sse

The app is deployed from examples/server.

Drop those URLs into any MCP-compatible host to see mcp-ui in action.

πŸ”’ Security

Host and user security is one of mcp-ui's primary concerns. In all content types, the remote code is executed in a sandboxed iframe.

πŸ›£οΈ Roadmap

  • Add online playground
  • Expand UI Action API (beyond tool calls)
  • Support Web Components
  • Support Remote-DOM
  • Add component libraries (in progress)
  • Add declarative UI content type
  • Support generative UI?

🀝 Contributing

Contributions, ideas, and bug reports are welcome! See the contribution guidelines to get started.

πŸ“„ License

Apache License 2.0 Β© The MCP UI Authors

Disclaimer

This project is provided "as is", without warranty of any kind. The mcp-ui authors and contributors shall not be held liable for any damages, losses, or issues arising from the use of this software. Use at your own risk.

About

SDK for UI over MCP. Bring rich UI experiences to the agents!

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published