Add a headless MCP server for agent-driven texturing#99
Open
urib94 wants to merge 1 commit into
Open
Conversation
Adds a self-contained `mcp/` Model Context Protocol server that exposes BumpMesh's mesh-processing pipeline to AI agents (STL/OBJ/3MF in, displaced STL/3MF out) with no browser, GPU, or data upload. It imports the existing `js/*.js` modules directly, so it never drifts from the app's geometry code. Tools (bumpmesh_*): list_textures, inspect_mesh, texturize, subdivide, decimate, validate_mesh, place_on_bed. Plain-JS ESM, stdio transport, no build step; zod-validated strict inputs; node:test suite (26 tests). Two pure, behavior-preserving refactors let the pipeline run headlessly: - exporter.js: extract buildSTLBytes/build3MFBytes; exportSTL/export3MF keep their signatures and browser download path. - stlLoader.js: extract parseModelBuffer; File-based loaders unchanged. Build config: add an npm-workspaces root package.json (three, fflate) so the shared js/ modules resolve their deps from one root install; stop gitignoring the tracked manifests. 3MF input works in Node via an xmldom DOMParser shim (js/ untouched). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add a headless MCP server for agent-driven texturing
What this is
A self-contained Model Context Protocol (MCP) server (
mcp/) that exposes BumpMesh'smesh-processing pipeline to AI agents and automation. It lets a tool/agent apply displacement
textures to a model programmatically — STL/OBJ/3MF in, displaced STL/3MF out — with no browser,
no GPU, and no data upload (same privacy guarantee as the web app).
Motivating use case: 3D-print prep. An assistant can grip-texture a handle, knurl a knob, or add
carbon-fiber to a panel as one step in a larger "design → texture → slice" workflow, driven from
natural language.
Why it's low-risk to the existing app
The whole thing reuses
js/*.jsdirectly — it does not reimplement any geometry code, so itcan't drift from the app. The export pipeline (
exportPipeline.js) already depends only onthree(as math),meshIndex.js, andfflate; WebGL is confined to the viewer/preview, whichthe server never touches.
Two pure, behavior-preserving refactors make the pipeline callable headlessly:
js/exporter.js— extractbuildSTLBytes(geometry)/build3MFBytes(geometry)(returnUint8Array).exportSTL/export3MFkeep their signatures and the exact browser downloadpath; output bytes are identical.
js/stlLoader.js— extractparseModelBuffer(arrayBuffer, ext)(parse + cleanup + bounds).The
File-based loaders (loadModelFile,loadSTLFile, …) keep their signatures and wrap itafter
FileReader.No changes to
viewer.js/previewMaterial.jsor any UI behavior.Tools
bumpmesh_list_texturesbumpmesh_inspect_meshbumpmesh_texturizebumpmesh_subdividebumpmesh_decimatebumpmesh_validate_meshbumpmesh_place_on_bedPlain-JS ESM, no build step, stdio transport, zod-validated strict inputs (unknown
params error), actionable error messages, stdout kept protocol-clean.
Build / install change
Adds a minimal npm-workspaces root
package.jsondeclaringthree+fflate, so the sharedjs/modules resolve their dependencies from a singlenpm installat the repo root — thisalso makes the existing
bench-*.mjs/diag-*.mjsscripts reproducible. The previously untrackedmanifests are now tracked (
node_modules/stays ignored)..3mfinput works under Node via asmall
@xmldom/xmldomDOMParsershim installed by the server before anyjs/module loads(
js/itself is untouched).Testing
node:testsuite, 26 tests, no GPU, runnable vianpm test --workspace mcp:round-trip texturize (STL byte-length invariant, re-parse, watertight output), STL/OBJ/3MF
read + round-trip, subdivide/decimate/place-on-bed,
list_textures, strict-validation andunknown-texture error paths.
Try it
Client config (Claude Desktop / Code):
{ "mcpServers": { "bumpmesh": { "command": "node", "args": ["/absolute/path/to/stlTexturizer/mcp/server.mjs"] } } }See
mcp/README.mdfor the full tool reference and parameters.