Skip to content

Commit d301230

Browse files
committed
readme
1 parent 1f79d66 commit d301230

1 file changed

Lines changed: 36 additions & 48 deletions

File tree

README.md

Lines changed: 36 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -5,68 +5,70 @@
55

66
**mcp-ui** is a TypeScript SDK that adds UI capabilities to the [Model-Context Protocol](https://modelcontextprotocol.io/introduction) (MCP). It provides packages to create interactive HTML components on the server and handle their rendering on the client.
77

8-
The library will evolve as a playground to experiment with the many exciting ideas in the community.
8+
This project is a playground for new ideas in the MCP community. Expect it to evolve rapidly!
99

1010
<video src="https://github.com/user-attachments/assets/51f7c712-8133-4d7c-86d3-fdca550b9767"></video>
1111

1212
## Goal
1313

14-
The primary goal is to facilitate the creation and rendering of `HtmlResource` objects. These blocks are designed to be part of an MCP response, allowing a model or tool to send a structured HTML component or URL for a client for display.
14+
Make it simple to create and render HTML resource blocks. These are special objects you can send in an MCP response, letting your MCP server deliver a structured interactive web component for the host to display.
1515

16-
### `HtmlResource`
16+
### `HtmlResource` at a Glance
1717

18-
This is the fundamental object exchanged. It has the following structure (simplified):
18+
This is the main object exchanged between server and client:
1919

2020
```typescript
21-
interface HtmlResourceBlock {
21+
interface HtmlResource {
2222
type: "resource";
2323
resource: {
24-
uri: string; // Primary identifier. e.g., "ui://my-component/1" or "ui-app://my-app/instance-1"
25-
mimeType: "text/html"; // Always text/html for this SDK's purpose
26-
text?: string; // HTML content or an iframe URL
27-
blob?: string; // Base64 encoded HTML content or iframe URL
24+
uri: string; // e.g., "ui://my-component/1" or "ui-app://my-app/instance-1"
25+
mimeType: "text/html";
26+
text?: string; // HTML content OR external app URL
27+
blob?: string; // Base64 encoded HTML content or external app URL
2828
}
2929
}
3030
```
3131

32-
* **`uri`**: A unique identifier for the resource.
33-
* `ui://<unique-id>`: Indicates the resource content is self-contained HTML, intended to be rendered directly by the client (e.g., in an iframe sandbox with `srcDoc`). The `text` or `blob` field will contain the HTML string.
34-
* `ui-app://<app-id>/<instance-id>`: Indicates the resource is an external application or a more complex UI that should be rendered within an iframe using a URL. The `text` or `blob` field will contain the URL for the iframe's `src` attribute.
35-
* **`mimeType`**: For this SDK, it will always be `"text/html"`.
36-
* **`text` vs. `blob`**: This defines how the content (HTML string or URL string) is delivered:
37-
* `text`: The content is provided as a direct string.
38-
* `blob`: The content is provided as a Base64 encoded string. This is useful for ensuring content integrity or for embedding larger HTML payloads without issues in JSON.
32+
- **`uri`**: Uniquely identifies the resource.
33+
- `ui://...` means the content is self-contained HTML (rendered with `srcDoc` in an iframe).
34+
- `ui-app://...` means the content is an external app or site (rendered with `src` in an iframe).
35+
- **`mimeType`**: Always `"text/html"` for this SDK.
36+
- **`text` vs. `blob`**: Use `text` for direct strings, or `blob` for Base64-encoded content (handy for larger payloads or to avoid JSON issues).
3937

4038
## Packages
4139

42-
* **`@mcp-ui/client`**: Provides React components and hooks for the client-side. The primary component is `<HtmlResource />`.
43-
* **`@mcp-ui/server`**: Includes helper functions for server-side tools to easily construct `HtmlResource` objects.
40+
- **`@mcp-ui/client`**: React components for the client. The main export is `<HtmlResource />`—just drop it into your app to render MCP HTML resources.
41+
- **`@mcp-ui/server`**: Helpers for building `HtmlResource` objects on the server.
4442

45-
## Getting Started
43+
## Quickstart
4644

47-
1. **Clone the repository.**
48-
2. **Install dependencies from the monorepo root:**
45+
1. **Clone the repo:**
46+
```bash
47+
git clone https://github.com/idosal/mcp-ui.git
48+
cd mcp-ui
49+
```
50+
2. **Install dependencies:**
4951
```bash
50-
pnpm install
52+
pnpm install
5153
```
54+
5255
## How to Use
5356

5457
### Server-Side (`@mcp-ui/server`)
5558

56-
Use `createHtmlResource` to construct the resource block.
59+
Use `createHtmlResource` to build a resource block:
5760

5861
```typescript
5962
import { createHtmlResource } from '@mcp-ui/server';
6063

61-
// Example 1: Direct HTML content, delivered as text
64+
// Direct HTML content
6265
const directHtmlResource = createHtmlResource({
6366
uri: 'ui://my-unique-component/instance1',
6467
content: { type: 'directHtml', htmlString: '<p>Hello from direct HTML!</p>' },
6568
delivery: 'text',
6669
});
67-
// This `directHtmlResource` can now be included in the tool response.
6870

69-
// Example 2: External App URL, delivered as text
71+
// External App URL
7072
const appUrl = 'https://example.com/my-interactive-app';
7173
const externalAppResource = createHtmlResource({
7274
uri: 'ui-app://my-app-identifier/session123',
@@ -77,30 +79,17 @@ const externalAppResource = createHtmlResource({
7779

7880
### Client-Side (`@mcp-ui/client`)
7981

80-
The `@mcp-ui/client` package provides an `<HtmlResource />` component (example path: `packages/client/src/components/HtmlResource.tsx`) designed to render these blocks.
81-
82-
**Conceptual Usage:**
82+
The main export is the `<HtmlResource />` React component. Use it to render any MCP HTML resource block:
8383

8484
```tsx
8585
import React from 'react';
8686
import { HtmlResource } from '@mcp-ui/client';
8787

88-
// Dummy type for the example
89-
interface HtmlResource {
90-
type: "resource";
91-
resource: {
92-
uri: string;
93-
mimeType: "text/html";
94-
text?: string;
95-
blob?: string;
96-
}
97-
}
98-
99-
const MyComponent: React.FC<{ mcpResource: HtmlResource }> = ({ mcpResource }) => {
100-
const handleAction = async (tool: string, params: Record<string, unknown>) => {
88+
const MyComponent = ({ mcpResource }) => {
89+
const handleAction = async (tool, params) => {
10190
console.log('Action from iframe:', tool, params);
10291
// Handle actions posted from the iframe content
103-
return { TBD: "Action handled" };
92+
return { status: 'Action handled' };
10493
};
10594

10695
if (mcpResource.type === 'resource' && mcpResource.resource.mimeType === 'text/html') {
@@ -115,17 +104,16 @@ const MyComponent: React.FC<{ mcpResource: HtmlResource }> = ({ mcpResource }) =
115104
};
116105
```
117106

118-
See the specific documentation for each package for more detailed API information and advanced usage.
119-
107+
For more details and advanced usage, check out the [docs](./docs/src/guide/client/overview.md) and the [HtmlResource component guide](./docs/src/guide/client/html-resource.md).
120108

121109
## 👥 Contributing
122110

123-
Contributions, feedback, and ideas are more than welcome! Please review the [contribution](https://github.com/idosal/mco-ui/blob/main/.github/CONTRIBUTING.md) guidelines.
111+
Ideas, feedback, and contributions are always welcome! See the [contribution guidelines](https://github.com/idosal/mco-ui/blob/main/.github/CONTRIBUTING.md).
124112

125113
## 📄 License
126114

127-
This project is licensed under the [Apache License 2.0](LICENSE).
115+
Licensed under the [Apache License 2.0](LICENSE).
128116

129117
## Disclaimer
130118

131-
MCP UI is provided "as is" without warranty of any kind. Authors are not responsible for any damages or issues that may arise from its use.
119+
MCP UI is provided "as is" with no warranty. Use at your own risk.

0 commit comments

Comments
 (0)