$npx -y skills add vercel-labs/json-render --skill mcpMCP Apps integration for json-render. Use when building MCP servers that render interactive UIs in Claude, ChatGPT, Cursor, or VS Code, or when integrating json-render with the Model Context Protocol.
| 1 | # @json-render/mcp |
| 2 | |
| 3 | MCP Apps integration that serves json-render UIs as interactive MCP Apps inside Claude, ChatGPT, Cursor, VS Code, and other MCP-capable clients. |
| 4 | |
| 5 | ## Quick Start |
| 6 | |
| 7 | ### Server (Node.js) |
| 8 | |
| 9 | ```typescript |
| 10 | import { createMcpApp } from "@json-render/mcp"; |
| 11 | import { defineCatalog } from "@json-render/core"; |
| 12 | import { schema } from "@json-render/react/schema"; |
| 13 | import { shadcnComponentDefinitions } from "@json-render/shadcn/catalog"; |
| 14 | import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"; |
| 15 | import fs from "node:fs"; |
| 16 | |
| 17 | const catalog = defineCatalog(schema, { |
| 18 | components: { ...shadcnComponentDefinitions }, |
| 19 | actions: {}, |
| 20 | }); |
| 21 | |
| 22 | const server = createMcpApp({ |
| 23 | name: "My App", |
| 24 | version: "1.0.0", |
| 25 | catalog, |
| 26 | html: fs.readFileSync("dist/index.html", "utf-8"), |
| 27 | }); |
| 28 | |
| 29 | await server.connect(new StdioServerTransport()); |
| 30 | ``` |
| 31 | |
| 32 | ### Client (React, inside iframe) |
| 33 | |
| 34 | ```tsx |
| 35 | import { useJsonRenderApp } from "@json-render/mcp/app"; |
| 36 | import { JSONUIProvider, Renderer } from "@json-render/react"; |
| 37 | |
| 38 | function McpAppView({ registry }) { |
| 39 | const { spec, loading, error } = useJsonRenderApp(); |
| 40 | if (error) return <div>Error: {error.message}</div>; |
| 41 | if (!spec) return <div>Waiting...</div>; |
| 42 | return ( |
| 43 | <JSONUIProvider registry={registry} initialState={spec.state ?? {}}> |
| 44 | <Renderer spec={spec} registry={registry} loading={loading} /> |
| 45 | </JSONUIProvider> |
| 46 | ); |
| 47 | } |
| 48 | ``` |
| 49 | |
| 50 | ## Architecture |
| 51 | |
| 52 | 1. `createMcpApp()` creates an `McpServer` that registers a `render-ui` tool and a `ui://` HTML resource |
| 53 | 2. The tool description includes the catalog prompt so the LLM knows how to generate valid specs |
| 54 | 3. The HTML resource is a Vite-bundled single-file React app with json-render renderers |
| 55 | 4. Inside the iframe, `useJsonRenderApp()` connects to the host via `postMessage` and renders specs |
| 56 | |
| 57 | ## Server API |
| 58 | |
| 59 | - `createMcpApp(options)` - main entry, creates a full MCP server |
| 60 | - `registerJsonRenderTool(server, options)` - register a json-render tool on an existing server |
| 61 | - `registerJsonRenderResource(server, options)` - register the UI resource |
| 62 | |
| 63 | ## Client API (`@json-render/mcp/app`) |
| 64 | |
| 65 | - `useJsonRenderApp(options?)` - React hook, returns `{ spec, loading, connected, error, callServerTool }` |
| 66 | - `buildAppHtml(options)` - generate HTML from bundled JS/CSS |
| 67 | |
| 68 | ## Building the iframe HTML |
| 69 | |
| 70 | Bundle the React app into a single self-contained HTML file using Vite + `vite-plugin-singlefile`: |
| 71 | |
| 72 | ```typescript |
| 73 | // vite.config.ts |
| 74 | import { defineConfig } from "vite"; |
| 75 | import react from "@vitejs/plugin-react"; |
| 76 | import { viteSingleFile } from "vite-plugin-singlefile"; |
| 77 | |
| 78 | export default defineConfig({ |
| 79 | plugins: [react(), viteSingleFile()], |
| 80 | build: { outDir: "dist" }, |
| 81 | }); |
| 82 | ``` |
| 83 | |
| 84 | ## Client Configuration |
| 85 | |
| 86 | ### Cursor (`.cursor/mcp.json`) |
| 87 | |
| 88 | ```json |
| 89 | { |
| 90 | "mcpServers": { |
| 91 | "my-app": { |
| 92 | "command": "npx", |
| 93 | "args": ["tsx", "server.ts", "--stdio"] |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 | ``` |
| 98 | |
| 99 | ### Claude Desktop |
| 100 | |
| 101 | ```json |
| 102 | { |
| 103 | "mcpServers": { |
| 104 | "my-app": { |
| 105 | "command": "npx", |
| 106 | "args": ["tsx", "/path/to/server.ts", "--stdio"] |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | ``` |
| 111 | |
| 112 | ## Dependencies |
| 113 | |
| 114 | ```bash |
| 115 | # Server |
| 116 | npm install @json-render/mcp @json-render/core @modelcontextprotocol/sdk |
| 117 | |
| 118 | # Client (iframe) |
| 119 | npm install @json-render/react @json-render/shadcn react react-dom |
| 120 | |
| 121 | # Build tools |
| 122 | npm install -D vite @vitejs/plugin-react vite-plugin-singlefile |
| 123 | ``` |