Three.js MCP Triangle

Three.js MCP Triangle

MCP server that lets you control a Three.js triangle in the browser via natural language, including setting colors, vertex colors, and transformations (position, rotation, scale), with live updates via WebSocket.

Category
访问服务器

README

Three.js MCP Triangle

A colored Three.js triangle rendered in the browser that you control through an MCP (Model Context Protocol) server. The server exposes tools to change the triangle's color and transform (position, rotation, scale). State changes are pushed live to the browser over a WebSocket.

MCP client (Claude / VS Code Copilot)
        │  stdio (MCP protocol)
        ▼
  MCP server (src/index.js)  ── thin proxy
        │  HTTP POST /api/state
        ▼
  Web server (src/web-server.js)  ── owns the state
        │  WebSocket push (state changes)
        ▼
  Browser  →  http://localhost:3000  →  Three.js triangle

Two processes, one shared state. The web server owns the triangle state and serves the browser; the MCP server is a thin proxy that POSTs to it. This is why the MCP tools and the browser stay in sync even though your MCP client spawns the MCP server in a separate process from npm start.

Where do I type prompts? In your MCP client's chat (e.g. VS Code Copilot Chat in Agent mode) — not in the terminal. The terminal running npm start is the web server; the terminal is not a prompt box.


Project structure

Path Purpose
src/web-server.js Standalone server: owns state, serves viewer, WS + HTTP API
src/index.js MCP server — thin proxy that calls the web server's HTTP API
src/state.js Shared triangle state + change subscriptions
public/index.html Three.js scene that renders and live-updates the triangle
.vscode/mcp.json VS Code MCP server configuration

Requirements

  • Node.js 18+

Install

npm install

Run

Step 1 — start the web server (leave it running):

npm start

Then open http://localhost:3000 to see the triangle. Change the web port with the PORT environment variable (default 3000).

Step 2 — connect an MCP client (see below). The MCP server is launched by your client, not by npm start. It proxies to the web server via the WEB_URL environment variable (default http://localhost:3000).

Type your prompts in the MCP client's chat, not in the terminal.


Using it as an MCP server

VS Code (GitHub Copilot)

The included .vscode/mcp.json registers the server. First run npm start in a terminal, then open the Copilot Chat view, switch to Agent mode, and the threejs-triangle tools become available. Open http://localhost:3000 in a browser to watch changes apply in real time.

Claude Desktop

Add this to your claude_desktop_config.json:

{
  "mcpServers": {
    "threejs-triangle": {
      "command": "node",
      "args": ["src/index.js"],
      "cwd": "d:/Learning/ThreeJs_MCP",
      "env": { "WEB_URL": "http://localhost:3000" }
    }
  }
}

Run npm start first, restart Claude Desktop, then open http://localhost:3000 in a browser.


Exposed tools (the API)

set_color

Set one solid color for the whole triangle.

Param Type Description
color string Hex color, e.g. #ff8800

set_vertex_colors

Set the three vertex colors individually to create a gradient.

Param Type Description
color1 string Top vertex color
color2 string Bottom-left vertex color
color3 string Bottom-right vertex color

set_transform

Set position, rotation (degrees), and/or scale. Any omitted axis keeps its current value.

Param Type Description
position { x?, y?, z? } World position
rotation { x?, y?, z? } Rotation in degrees
scale number or { x?, y?, z? } Uniform scale, or per-axis scale

get_state

Returns the current triangle state (vertex colors + transform).

reset

Resets to defaults: red/green/blue vertices and identity transform.


Example prompts

Once the server is connected in your MCP client, try:

  • "Make the triangle solid orange."
  • "Set the vertex colors to red, green and blue."
  • "Rotate the triangle 45 degrees on the Z axis and scale it to 1.5."
  • "Move the triangle to x: 1, y: -0.5."
  • "Reset the triangle."

How it works

  1. state.js holds a single TriangleState object and a set of subscribers.
  2. web-server.js (run via npm start) owns the state, serves public/index.html, exposes the HTTP API (GET/POST /api/state, POST /api/reset), and broadcasts every change to connected browsers over WebSocket. New tabs receive the current state on connect.
  3. index.js is the MCP server your client spawns. Each tool calls the web server's HTTP API — it holds no state itself. This keeps the browser and the tools in sync across the two processes.
  4. public/index.html builds a BufferGeometry triangle with per-vertex colors and applies incoming state to the mesh's color attribute and transform.

Note: MCP uses stdout for its protocol, so the MCP server writes all logs to stderr (console.error). The web server is a normal process and logs to stdout.

Troubleshooting: If tools report "Could not reach the triangle web server", make sure npm start is running. If you see EADDRINUSE on port 3000, another process already holds it — stop it or set a different PORT (and matching WEB_URL).


License

MIT

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选