mcp-apps-playground
README.md
<p align="center">
<img src="docs/banner.png" alt="MCP Apps: your tool can return a UI" width="720">
</p>
<h1 align="center">mcp-apps-playground</h1>
<p align="center">
A tiny MCP server whose tools answer with an <b>interface</b>, not just text.<br>
One tool, one HTML file, one line of <code>_meta</code>.
</p>
<p align="center">
<img alt="MCP Apps" src="https://img.shields.io/badge/MCP-Apps-2F5BEA">
<img alt="Node 20+" src="https://img.shields.io/badge/node-%E2%89%A520-111A2B">
<img alt="License MIT" src="https://img.shields.io/badge/license-MIT-9DB8FF">
</p>
<p align="center">
<img src="docs/scene.gif" alt="A three.js solar system rendered inside a Claude chat" width="520">
</p>
## What is this?
[MCP Apps](https://modelcontextprotocol.io/docs/extensions/apps) is the MCP extension that lets a
server ship a small web page along with a tool. The host (Claude, for example) renders that page in
a sandboxed iframe inside the conversation, and the page can talk back.
This repo is the smallest useful example I could write, plus one that shows off:
| Tool | What you get |
| --- | --- |
| `show_hello_widget` | A counter that receives the tool's input, calls the server, and drafts a message to Claude |
| `render_3d_scene` | An animated three.js scene built from a JSON spec, drawn while the model is still writing it |
| `get_server_time` | A plain tool that the counter widget calls by itself |
<p align="center">
<img src="docs/counter.png" alt="The counter widget inside a Claude chat" width="600">
</p>
## Quick start
```bash
git clone https://github.com/zainulabidin302/mcp-apps-playground.git
cd mcp-apps-playground
npm install
```
Add the server to Claude Desktop (`Settings → Developer → Edit Config`):
```json
{
"mcpServers": {
"hello-mcp-app": {
"command": "node",
"args": ["/absolute/path/to/mcp-apps-playground/server.js"]
}
}
}
```
Restart Claude Desktop, then try:
> Use show_hello_widget to greet Sara, starting at 3.
> Use render_3d_scene to build a neon solar system: a glowing sun, three planets orbiting it, one with a moon, and a galaxy behind.
## How it works
An MCP App has three parts. Two of them are ordinary MCP.
**1. A UI resource**: one HTML file under a `ui://` address.
```js
server.registerResource("hello-widget", "ui://hello/widget.html",
{ mimeType: "text/html;profile=mcp-app" },
async () => ({ contents: [{ uri, mimeType, text: html }] }));
```
**2. A tool that points to it**: this is the whole link.
```js
server.registerTool("show_hello_widget", {
inputSchema: { name: z.string() },
_meta: { ui: { resourceUri: "ui://hello/widget.html" } },
}, async ({ name, start = 0 }) => ({
content: [{ type: "text", text: `Widget for ${name}` }], // fallback for hosts with no UI
structuredContent: { name, start }, // data for the view
}));
```
**3. The view**: the page listens, then talks back.
```js
const app = new App({ name: "hello-widget" });
app.ontoolinput = ({ arguments: a }) => setTitle(a.name); // what the model sent
app.ontoolresult = (r) => setCount(r.structuredContent.start); // what the server returned
await app.callServerTool({ name: "get_server_time" }); // view -> server
await app.sendMessage({ role: "user", content: [/* ... */] }); // view -> chat
await app.connect();
```
Always return useful `content` as well: a host that does not render views shows only that text.
### Things I learned the hard way
- `sendMessage` does not post silently. In Claude Desktop it drafts the message and asks you before sending.
- The view gets no network by default. `server.js` inlines the App SDK (and three.js, via esbuild) into
one `<script>`, so the page needs no CSP allowances.
- `ontoolinputpartial` fires while the model is still writing the arguments. The 3D scene uses it to
add objects one by one. It is about ten lines.
## The anim3d spec
`render_3d_scene` takes a declarative scene:
```json
{
"title": "Neon solar system", "background": "#02010a", "stars": 2000, "bloom": 1.4,
"camera": { "position": [0, 4, 9], "autoRotate": 0.4 },
"objects": [
{ "shape": "sphere", "material": "glow", "color": "#ffaa33", "scale": 1.6,
"animate": [{ "type": "pulse", "amount": 0.05 }],
"children": [
{ "shape": "sphere", "color": "#3399ff", "scale": 0.35,
"animate": [{ "type": "orbit", "radius": 2.2, "speed": 0.8 }] }
] },
{ "shape": "galaxy", "count": 20000, "radius": 6, "color": "#ff66cc", "color2": "#3344ff",
"position": [0, -1.5, 0], "animate": [{ "type": "spin", "speed": 0.1 }] }
]
}
```
- **Shapes**: box, sphere, torus, torusKnot, cone, cylinder, icosahedron, octahedron, dodecahedron,
tetrahedron, ring, plane, capsule, particles, galaxy
- **Materials**: standard, glow (works with bloom), glass, wire, toon
- **Animations** (stackable): spin, float, bounce, orbit, pulse, colorCycle, wobble, wave (plane only)
- `children` are positioned and animated relative to their parent, e.g. moons orbiting planets.
`createStage(container, spec)` from `src/anim3d.js` also works on its own in any page.
## Ship it
- **Local bundle**: `npm run pack` builds a `.mcpb` file from `manifest.json` that Claude Desktop can
install. Pack it on the platform you will run it on, because esbuild ships a native binary. The
manifest validates and packs; I have not tested installing the bundle yet.
- **Remote connector**: the same server behind a URL also works in Claude on the web and on mobile.
That needs an HTTP transport in place of stdio, which this repo does not include.
## Project layout
```
server.js MCP server: resources, tools, and the HTML bundling
widget.html the counter view
scene.html shell for the 3D view
src/scene-widget.js 3D view: App SDK wiring
src/anim3d.js tiny declarative layer over three.js
manifest.json MCP Bundle manifest
```
## License
MIT
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues