diff --git a/README.md b/README.md index 92043235..eb2a3423 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,10 @@ interface UIResource { The UI Resource is rendered in the `` component. It automatically detects the resource type and renders the appropriate component. +It is available as a React component and as a Web Component. + +**React Component** + It accepts the following props: - **`resource`**: The resource object from an MCP Tool response. It must include `uri`, `mimeType`, and content (`text`, `blob`) - **`onUIAction`**: Optional callback for handling UI actions from the resource: @@ -94,6 +98,27 @@ It accepts the following props: - **`library`**: Optional component library for Remote DOM resources (defaults to `basicComponentLibrary`) - **`remoteElements`**: remote element definitions for Remote DOM resources. +**Web Component** + +The Web Component is available as ``. It accepts the same props as the React component, but they must be passed as strings. + +Example: +```html + +``` + +The `onUIAction` prop can be handled by attaching an event listener to the component: +```javascript +const renderer = document.querySelector('ui-resource-renderer'); +renderer.addEventListener('onUIAction', (event) => { + console.log('Action:', event.detail); +}); +``` + +The Web Component is available in the `@mcp-ui/client` package at `dist/ui-resource-renderer.wc.js`. + ### Supported Resource Types #### HTML (`text/html` and `text/uri-list`) @@ -260,9 +285,10 @@ These guides will show you how to add a `mcp-ui` endpoint to an existing server, ## ๐ŸŒ Examples **Client Examples** -* [ui-inspector](https://github.com/idosal/ui-inspector) - inspect local `mcp-ui`-enabled servers. +* [ui-inspector](https://github.com/idosal/ui-inspector) - inspect local `mcp-ui`-enabled servers. * [MCP-UI Chat](https://github.com/idosal/scira-mcp-ui-chat) - interactive chat built with the `mcp-ui` client. Check out the [hosted version](https://scira-mcp-chat-git-main-idosals-projects.vercel.app/)! * MCP-UI RemoteDOM Playground (`examples/remote-dom-demo`) - local demo app to test RemoteDOM resources (intended for hosts) +* MCP-UI Web Component Demo (`examples/wc-demo`) - local demo app to test the Web Component **Server Examples** * **TypeScript**: A [full-featured server](examples/server) that is deployed to a hosted environment for easy testing. diff --git a/docs/src/.vitepress/config.ts b/docs/src/.vitepress/config.ts index 2ec1f5d6..8782e232 100644 --- a/docs/src/.vitepress/config.ts +++ b/docs/src/.vitepress/config.ts @@ -136,24 +136,23 @@ export default defineConfig({ link: '/guide/client/resource-renderer', }, { - text: 'Custom Component Libraries', - link: '/guide/client/custom-component-libraries', + text: 'React Usage & Examples', + link: '/guide/client/react-usage-examples' }, { - text: 'Using a Proxy', - link: '/guide/client/using-a-proxy', - }, - { - text: 'HTMLResourceRenderer', - link: '/guide/client/html-resource', - }, - { - text: 'RemoteDOMResourceRenderer', - link: '/guide/client/remote-dom-resource', - }, + text: 'Web Component Usage & Examples', + link: '/guide/client/wc-usage-examples', + } ], }, - { text: 'Usage & Examples', link: '/guide/client/usage-examples' }, + { + text: 'Custom Component Libraries', + link: '/guide/client/custom-component-libraries', + }, + { + text: 'Using a Proxy', + link: '/guide/client/using-a-proxy', + } ], }, ], diff --git a/docs/src/guide/client/html-resource.md b/docs/src/guide/client/html-resource.md index 9274a766..10ddef44 100644 --- a/docs/src/guide/client/html-resource.md +++ b/docs/src/guide/client/html-resource.md @@ -67,7 +67,7 @@ By default, the iframe stretches to 100% width and is at least 200px tall. You c ## Example Usage -See [Client SDK Usage & Examples](./usage-examples.md) for examples using the recommended `` component. +See [Client SDK Usage & Examples](./react-usage-examples.md) for examples using the recommended `` component. ## Auto-Resizing the Iframe diff --git a/docs/src/guide/client/overview.md b/docs/src/guide/client/overview.md index d0b82be9..f1955768 100644 --- a/docs/src/guide/client/overview.md +++ b/docs/src/guide/client/overview.md @@ -29,4 +29,5 @@ See the following pages for more details: - [UIResourceRenderer Component](./resource-renderer.md) - **Main entry point** - [HTMLResourceRenderer Component](./html-resource.md) - [RemoteDOMResourceRenderer Component](./remote-dom-resource.md) -- [Client SDK Usage & Examples](./usage-examples.md) +- [React Usage & Examples](./react-usage-examples.md) +- [Web Component Usage & Examples](./wc-usage-examples.md) diff --git a/docs/src/guide/client/usage-examples.md b/docs/src/guide/client/react-usage-examples.md similarity index 99% rename from docs/src/guide/client/usage-examples.md rename to docs/src/guide/client/react-usage-examples.md index 1f39945b..9ec80ace 100644 --- a/docs/src/guide/client/usage-examples.md +++ b/docs/src/guide/client/react-usage-examples.md @@ -1,6 +1,6 @@ -# @mcp-ui/client Usage & Examples +# React Usage & Examples -Here's how to use the `` component from `@mcp-ui/client`. +Here's how to use the `` component from `@mcp-ui/client` in a React environment. ## Installation diff --git a/docs/src/guide/client/resource-renderer.md b/docs/src/guide/client/resource-renderer.md index 26d95c45..3f6e0ebd 100644 --- a/docs/src/guide/client/resource-renderer.md +++ b/docs/src/guide/client/resource-renderer.md @@ -1,6 +1,17 @@ # UIResourceRenderer Component -The `` component is the **main entry point** for rendering MCP-UI resources in your React application. It automatically detects the resource type and renders the appropriate component internally. +The `UIResourceRenderer` component is the **main entry point** for rendering MCP-UI resources in your application. It automatically detects the resource type and renders the appropriate component internally. +It is available as a React component and as a Web Component. + +## React Component + +React applications may use the `` component. + +## Web Component + +For developers using frameworks other than React, a Web Component version is available. It can be used as a standard HTML element (``) and styled with regular CSS. + +[**ยป See the Web Component Usage & Examples for more details**](./wc-usage-examples.md) ## Why use `UIResourceRenderer`? @@ -348,4 +359,4 @@ const customLibrary: ComponentLibrary = { ## Examples -See [Client SDK Usage & Examples](./usage-examples.md) for complete working examples. +See [Client SDK Usage & Examples](./react-usage-examples.md) for complete working examples. diff --git a/docs/src/guide/client/wc-usage-examples.md b/docs/src/guide/client/wc-usage-examples.md new file mode 100644 index 00000000..f620a73c --- /dev/null +++ b/docs/src/guide/client/wc-usage-examples.md @@ -0,0 +1,96 @@ +# Web Component Usage & Examples + +`UIResourceRenderer` is available as a Web Component and serves as a powerful tool for integrating MCP-UI resources into non-React frameworks such as Vue, Svelte, or vanilla JavaScript. It offers the same core functionality as its React counterpart but is used as a standard HTML element. + +A full, working example is available in the `examples/wc-demo` directory of the repository, demonstrating the recommended property-based approach. + +## 1. Install the package + +```bash +npm install @mcp-ui/client +``` + +## 2. Import the Web Component + +In your project's main JavaScript or TypeScript file, import the Web Component script. This will register the `` custom element, making it available throughout your application. + +```javascript +import '@mcp-ui/client/ui-resource-renderer.wc.js'; +``` + +Your build tool (e.g., Vite, Webpack, etc.) will automatically resolve this path from `node_modules`. + +## 3. Use the Custom Element + +Once the script is imported, you can use the `` custom element in your HTML. + +```html + +``` + +## 4. Styling + +You can style the Web Component directly with CSS, just like any other HTML element. The internal `