Skip to content

Commit 1eb59a6

Browse files
Restructure threejs-server README to match marketing examples
- Update title format to "Example: Three.js App" - Constrain screenshot width using table layout - Add Features section with key capabilities - Reorganize Running section with Tool Input subsection - Add Architecture section describing server and app components - Remove implementation-focused sections (WidgetProps, Creating a New Widget) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 94d45a1 commit 1eb59a6

File tree

1 file changed

+60
-81
lines changed

1 file changed

+60
-81
lines changed

examples/threejs-server/README.md

Lines changed: 60 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,45 @@
1-
# Three.js MCP Server
1+
# Example: Three.js App
22

33
Interactive 3D scene renderer using Three.js. Demonstrates streaming code preview and full MCP App integration.
44

5-
![Screenshot](https://modelcontextprotocol.github.io/ext-apps/screenshots/threejs-server/screenshot.png)
5+
<table>
6+
<tr>
7+
<td><a href="https://modelcontextprotocol.github.io/ext-apps/screenshots/threejs-server/screenshot.png"><img src="https://modelcontextprotocol.github.io/ext-apps/screenshots/threejs-server/screenshot.png" alt="Three.js scene" width="400"></a></td>
8+
</tr>
9+
</table>
610

7-
## Tools
11+
## Features
812

9-
| Tool | Description |
10-
| -------------------- | ------------------------------------ |
11-
| `show_threejs_scene` | Render 3D scene from JavaScript code |
12-
| `learn_threejs` | Get documentation and examples |
13+
- **Interactive 3D Rendering**: Execute JavaScript code to create and animate Three.js scenes
14+
- **Streaming Preview**: See the scene build in real-time as code is being written
15+
- **Built-in Helpers**: Pre-configured `OrbitControls`, post-processing effects (bloom), and render passes
16+
- **Documentation Tool**: `learn_threejs` provides API docs and code examples on demand
1317

14-
## Quick Start
18+
## Running
1519

16-
```bash
17-
# Build
18-
npm run build
20+
1. Install dependencies:
1921

20-
# Run (stdio mode for Claude Desktop)
21-
bun server.ts --stdio
22+
```bash
23+
npm install
24+
```
2225

23-
# Run (HTTP mode for basic-host)
24-
bun server.ts
25-
```
26-
27-
## Code Structure
28-
29-
```
30-
threejs-server/
31-
├── server.ts # MCP server with tools
32-
├── mcp-app.html # Entry HTML
33-
└── src/
34-
├── mcp-app-wrapper.tsx # Generic MCP App wrapper (reusable)
35-
├── threejs-app.tsx # Three.js widget component
36-
└── global.css # Styles
37-
```
26+
2. Build and start the server:
3827

39-
## Key Files
40-
41-
### `src/mcp-app-wrapper.tsx`
42-
43-
Generic wrapper handling MCP connection. Provides `WidgetProps` interface:
44-
45-
```tsx
46-
interface WidgetProps<TToolInput> {
47-
toolInputs: TToolInput | null; // Complete tool input
48-
toolInputsPartial: TToolInput | null; // Streaming partial input
49-
toolResult: CallToolResult | null; // Tool execution result
50-
hostContext: McpUiHostContext | null; // Theme, viewport, locale
51-
callServerTool: App["callServerTool"]; // Call MCP server tools
52-
sendMessage: App["sendMessage"]; // Send chat messages
53-
sendOpenLink: App["sendOpenLink"]; // Open URLs in browser
54-
sendLog: App["sendLog"]; // Debug logging
55-
}
56-
```
28+
```bash
29+
npm start
30+
# OR for stdio:
31+
npm run build && bun server.ts --stdio
32+
```
5733

58-
### `src/threejs-app.tsx`
34+
The server will listen on `http://localhost:3001/mcp`.
5935

60-
Widget component receiving all props. Uses:
36+
3. View using the [`basic-host`](https://github.com/modelcontextprotocol/ext-apps/tree/main/examples/basic-host) example or another MCP Apps-compatible host.
6137

62-
- `toolInputs.code` - JavaScript to execute
63-
- `toolInputsPartial.code` - Streaming preview
64-
- `toolInputs.height` - Canvas height
38+
### Tool Input
6539

66-
### `server.ts`
40+
To test the example, copy the contents of [`test-input.json`](test-input.json) into the tool input field in `basic-host`.
6741

68-
MCP server with:
69-
70-
- `show_threejs_scene` tool linked to UI resource
71-
- `learn_threejs` documentation tool
72-
- stdio + HTTP transport support
73-
74-
## Available Three.js Globals
75-
76-
```javascript
77-
THREE; // Three.js library
78-
canvas; // Pre-created canvas
79-
(width, height); // Canvas dimensions
80-
OrbitControls; // Camera controls
81-
EffectComposer; // Post-processing
82-
RenderPass; // Render pass
83-
UnrealBloomPass; // Bloom effect
84-
```
85-
86-
## Test Input
87-
88-
Copy contents of `test-input.json` to test in basic-host (`http://localhost:8080`).
89-
90-
## Example Code
42+
The test input creates a simple scene with a rotating cube:
9143

9244
```javascript
9345
const scene = new THREE.Scene();
@@ -128,10 +80,37 @@ function animate() {
12880
animate();
12981
```
13082

131-
## Creating a New Widget
83+
#### Available Three.js Globals
84+
85+
When writing custom code, these globals are available:
86+
87+
```javascript
88+
THREE; // Three.js library
89+
canvas; // Pre-created canvas element
90+
width; // Canvas width
91+
height; // Canvas height
92+
OrbitControls; // Camera controls
93+
EffectComposer; // Post-processing composer
94+
RenderPass; // Render pass
95+
UnrealBloomPass; // Bloom effect
96+
```
97+
98+
## Architecture
99+
100+
### Server (`server.ts`)
101+
102+
Exposes two tools:
103+
104+
- `show_threejs_scene` - Renders a 3D scene from JavaScript code
105+
- `learn_threejs` - Returns documentation and code examples for Three.js APIs
106+
107+
Supports Streamable HTTP and stdio transports.
108+
109+
### App (`src/threejs-app.tsx`)
110+
111+
React component that:
132112

133-
1. Copy this example
134-
2. Rename `threejs-app.tsx` to your widget name
135-
3. Define your `ToolInput` interface
136-
4. Implement your widget using the `WidgetProps`
137-
5. Update `server.ts` with your tools
113+
- Receives tool inputs via the MCP App SDK
114+
- Displays streaming preview from `toolInputsPartial.code` as code arrives
115+
- Executes final code from `toolInputs.code` when complete
116+
- Renders to a pre-created canvas with configurable height

0 commit comments

Comments
 (0)