Three.js MCP Triangle

Three.js MCP Triangle

Enables controlling a Three.js triangle rendered in the browser through MCP tools, allowing color changes and transforms (position, rotation, scale) with live updates via WebSocket.

Category
Visit Server

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

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured