8000 GitHub - idosal/mcp-ui: UI over MCP. Bring rich AI experiences to the agents!
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

idosal/mcp-ui

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

84 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“¦ Model Context Protocol UI SDK

Server Version Client Version

What Is mcp-ui β€’ Installation β€’ Quickstart β€’ Core Concepts β€’ Example Implementation β€’ Roadmap β€’ Contributing β€’ License


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

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

mcpui-x.mp4

πŸ’‘ What Is mcp-ui?

mcp-ui is a TypeScript SDK comprising two packages:

  • @mcp-ui/server: Utilities to generate HtmlResourceBlock objects on your MCP server.
  • @mcp-ui/client: UI components (e.g., <HtmlResource />) 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.

✨ Core Concepts

HtmlResource

The primary payload exchanged between the server and the client:

interface HtmlResourceBlock {
  type: 'resource';
  resource: {
    uri: string;       // e.g. "ui://component/id" or "ui-app://app/instance"
    mimeType: 'text/html';
    text?: string;      // Inline HTML or exte
8000
rnal URL
    blob?: string;      // Base64-encoded HTML or URL (for large payloads)
  };
}
  • uri: Unique identifier for caching and routing
    • ui://… β€” self-contained HTML (rendered via <iframe srcDoc>)
    • ui-app://… β€” external app/site (rendered via <iframe src>)
  • mimeType: Always text/html
  • text vs. blob: Choose text for simple strings; use blob for larger or encoded content.

It's rendered in the client with the <HtmlResource> React component.

The HTML method is limited, and the external app method isn't secure enough for untrusted 3rd party sites. We need a better method. Some ideas we should explore: RSC, remotedom, etc.

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 yarn
yarn add @mcp-ui/server @mcp-ui/client

🎬 Quickstart

  1. Server-side: Build your resource blocks

    import { createHtmlResource } from '@mcp-ui/server';
    
    // Inline HTML
    const direct = createHtmlResource({
      uri: 'ui://greeting/1',
      content: { type: 'directHtml', htmlString: '<p>Hello, MCP UI!</p>' },
      delivery: 'text',
    });
    
    // External URL
    const external = createHtmlResource({
      uri: 'ui-app://widget/session-42',
      content: { type: 'externalUrl', iframeUrl: 'https://example.com/widget' },
      delivery: 'text',
    });
  2. Client-side: Render in your MCP host

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

🌍 Example implementation

Client example modelcontextprotocol/inspector#413

Server example Try out the hosted app at -

  • 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.

πŸ›£οΈ Roadmap

  • Support new SSR methods (e.g., RSC)
  • Support additional client-side libraries
  • Expand UI Action API
  • Do more with Resources and Sampling

🀝 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.

0