threlte-mcp
An MCP server for inspecting and manipulating Three.js/Threlte scenes in real-time.
README
Threlte MCP
An MCP (Model Context Protocol) server that enables AI agents to inspect and manipulate Three.js/Threlte scenes in real-time.
✅ Compatible With
- Claude Desktop - Anthropic's desktop app
- Antigravity - Google's AI IDE
- Claude Code - CLI tool for Claude
- Cursor - AI-powered code editor
- Windsurf - Codeium's AI IDE
- Continue - VS Code AI extension
- Any MCP-compatible client
See detailed compatibility guide →
Features
- 🔍 Scene Inspection - View the full 3D scene hierarchy, find objects by name/type
- 🎯 Object Manipulation - Move, rotate, scale, show/hide objects
- 🎨 Materials & Assets - Apply materials, load GLTF models, change environment
- 🧪 Asset Analysis - Inspect GLTF structure and validate performance
- dYZ+ Asset Optimization - Simplify meshes, compress textures, prune unused data
- dY"? Svelte Export - Generate Threlte/Svelte components from GLTF
- dYZ? Camera Presets - Save, load, and animate camera views
- ⚡ Physics Control - Add physics bodies, apply impulses, set gravity
- 🎭 Vibe Presets - Apply mood presets (cozy, spooky, neon, etc.)
Installation
npm install threlte-mcp
Quick Start
1. Install the package
npm install threlte-mcp
2. Configure your IDE (one-time setup)
npx threlte-mcp setup
This auto-detects your IDE (Antigravity, Cursor, Claude Desktop) and creates the MCP config.
3. Add the component to your Threlte app
Requires Svelte 5 for the MCPBridge component.
<script>
import { MCPBridgeComponent } from 'threlte-mcp/client';
</script>
<!-- Add inside your <Canvas> -->
<MCPBridgeComponent />
That's it! The AI can now inspect and manipulate your scene.
<details> <summary>📋 Manual Configuration (Alternative)</summary>
If npx threlte-mcp setup doesn't work for your IDE, manually add to your config:
{
"mcpServers": {
"threlte-mcp": {
"command": "npx",
"args": ["-y", "threlte-mcp"]
}
}
}
Config file locations:
- Antigravity:
~/.gemini/antigravity/mcp_config.json - Cursor:
~/.cursor/mcp.json - Claude Desktop:
~/Library/Application Support/Claude/claude_desktop_config.json(Mac)
</details>
<details> <summary>🔧 Advanced: TypeScript API</summary>
import { MCPBridge } from 'threlte-mcp/client';
import { useThrelte } from '@threlte/core';
const { scene } = useThrelte();
// Create bridge (auto-connects in dev mode)
const bridge = new MCPBridge(scene, {
url: 'ws://127.0.0.1:8082', // default
autoConnect: true, // default in dev
reconnectDelay: 60000, // 1 minute
});
// In render loop
bridge.update();
// Get scene state
bridge.getSceneState();
// Find objects
bridge.findObjects({ nameContains: 'player' });
</details>
Option B: Per-Scene (Simple for prototyping)
<script lang="ts">
import { onMount, onDestroy } from 'svelte';
import { useThrelte } from '@threlte/core';
const { scene } = useThrelte();
let ws: WebSocket | null = null;
onMount(() => {
ws = new WebSocket('ws://localhost:8082');
ws.onopen = () => {
console.log('[MCPBridge] Connected');
// Send initial scene state
ws?.send(JSON.stringify({
type: 'sceneState',
data: serializeScene(scene)
}));
};
ws.onmessage = (event) => {
const command = JSON.parse(event.data);
handleCommand(command);
};
});
onDestroy(() => {
ws?.close();
});
function serializeScene(obj: THREE.Object3D, depth = 0, maxDepth = 3) {
if (depth > maxDepth) return null;
return {
name: obj.name,
type: obj.type,
position: obj.position.toArray(),
rotation: obj.rotation.toArray().slice(0, 3),
scale: obj.scale.toArray(),
visible: obj.visible,
children: obj.children.map(c => serializeScene(c, depth + 1, maxDepth)).filter(Boolean)
};
}
function handleCommand(cmd: any) {
const { action, requestId, ...params } = cmd;
let result;
switch (action) {
case 'getFullSceneState':
result = { data: serializeScene(scene, 0, params.maxDepth || 3) };
break;
case 'moveSceneObject':
const obj = scene.getObjectByName(params.name || params.path);
if (obj && params.position) {
obj.position.set(...params.position);
result = { success: true };
}
break;
// Add more handlers as needed
}
if (requestId) {
ws?.send(JSON.stringify({ ...result, requestId }));
}
}
</script>
3. Run your app and start using MCP tools
Once both the MCP server and your Threlte app are running, AI agents can:
"Get the scene state"
"Find all objects named 'Player'"
"Move the 'Camera' to position [0, 5, 10]"
"Apply the 'neon' vibe to the scene"
Available Tools
Scene Inspection
| Tool | Description |
|---|---|
get_scene_state |
Get full scene hierarchy |
find_objects |
Search by name, type, or userData |
get_object_position |
Get position of specific object |
log_positions |
Export positions for code |
Camera
| Tool | Description |
|---|---|
set_camera_position |
Set camera position, lookAt, and lens settings |
save_camera_preset |
Save current camera view as a preset |
load_camera_preset |
Load a saved camera view |
list_camera_presets |
List all saved camera presets |
delete_camera_preset |
Delete a saved camera preset |
animate_camera_presets |
Animate through a sequence of presets |
Hierarchy Management
| Tool | Description |
|---|---|
spawn_entity |
Create primitive (box, sphere, etc.) |
destroy_entity |
Remove object from scene |
move_object |
Set object position |
set_transform |
Set position, rotation, scale |
set_visibility |
Show/hide object |
rename_entity |
Rename object |
duplicate_entity |
Clone object |
Physics
| Tool | Description |
|---|---|
make_physical |
Add physics body |
remove_physics |
Remove physics body |
apply_impulse |
Apply force |
set_gravity |
Set global gravity |
Asset Processing
| Tool | Description |
|---|---|
analyze_gltf |
Inspect GLTF/GLB structure |
validate_asset |
Validate GLTF/GLB for issues |
optimize_gltf |
Optimize GLTF/GLB assets |
export_to_svelte |
Generate Threlte/Svelte component |
Materials & Assets
| Tool | Description |
|---|---|
load_asset |
Load GLTF/GLB model |
apply_material |
Set material |
set_environment |
Set skybox/environment |
Atmosphere
| Tool | Description |
|---|---|
apply_vibe |
Apply mood preset |
get_bridge_status |
Check connection status |
Configuration
WebSocket Connection
The server uses port 8082 by default for WebSocket communication.
Environment Variables
The MCPBridge auto-connects in development mode. For production, you can enable it via environment variable:
# Add to .env file:
VITE_MCP_ENABLED=true
This is useful for:
- Testing in production builds
- Demo environments
- Debugging production issues
Note: Auto-enabled in development mode (npm run dev), no configuration needed.
Development
# Clone the repo
git clone https://github.com/RaulContreras123/threlte-mcp.git
cd threlte-mcp
# Install dependencies
npm install
# Run in development
npm run dev
# Build for production
npm run build
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
MIT © Raul Contreras
Links
Built with Claude 🤖
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。