Shader Lab MCP server: layer control and custom shader authoring#107
Open
git-chad wants to merge 11 commits into
Open
Shader Lab MCP server: layer control and custom shader authoring#107git-chad wants to merge 11 commits into
git-chad wants to merge 11 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…e, runtime enumeration)
- packages/shader-lab-mcp: stdio MCP server + localhost WebSocket bridge (18 tools: project state, layer CRUD/reorder, schema-validated param updates with clamp-and-report, custom shader write with compile ack, runtime-enumerated shader API reference, screenshot via export pipeline) - src/lib/agent-bridge: flag-gated editor client (?agent=1), command executor over zustand stores, compile-result events, screenshot capture - custom-shader-pass emits revision-keyed compile results for the ack loop - e2e test: real server + MCP client + fake editor tab over the bridge
8a68baa to
aa91405
Compare
- file-per-tool in src/tools (18 tools), shader-api resource in src/resources - server config (stdio transport, instructions, serverInfo) in xmcp.config.ts - bridge rewritten on ws (node-compatible, xmcp bundle runs under node) - shader reference reads app sources from disk (repo-root resolution from cwd) - zod v4 (xmcp runtime requires v4 _zod markers), xmcp checker disabled (OOMs) - e2e test builds and spawns the real dist/stdio.js bundle
- agent-bridge zustand store: enabled (persisted to localStorage) + live status - client reports connecting/connected through a status callback - topbar button with the xmcp logo: off / waiting (amber pulse) / connected (green dot) - ?agent=1 still force-enables for URL-based onboarding - root tsc excludes packages/shader-lab-mcp (own alias config); CI gets a dedicated MCP package typecheck step
A failed bind previously left the bridge dead forever while every tool reported 'no editor tab connected'. Now the bind retries every 2s and tools report the real cause (port in use) until it succeeds.
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.
MCP server that drives a running Shader Lab editor tab: create/remove/reorder/tweak layers, and — the headline — write custom TSL shaders with a real feedback loop (compile errors and canvas screenshots returned to the agent). Implements
plans/009-shader-lab-mcp.md(included). Built with xmcp.Architecture
packages/shader-lab-mcp/— private xmcp app: one file per tool insrc/tools/(18 tools), theshader-lab://shader-apiresource insrc/resources/, server config (stdio transport, instructions, serverInfo) inxmcp.config.ts.xmcp buildbundles todist/stdio.js; registered in.mcp.jsonso Claude Code picks it up per-session.src/lib/bridge.ts, onws, localhost-only, origin-checked, optional token) relays tool calls into the editor tab.src/lib/agent-bridge/in the app — the editor-side client, command executor over the existing zustand store actions, compile-result events, screenshot capture. All mutations land in the normal undo history (Cmd+Z works on everything the agent does).?agent=1still force-enables for URL-based onboarding.Tools (18)
get_project_state,get_layer,list_layer_types,describe_layer_type(param schema from the layer registry),screenshot(export-pipeline render → PNG image content)add_layer,remove_layers,duplicate_layer,reorder_layer,rename_layer,set_layer_visibility,select_layer,update_layer,update_layer_params(clamp-and-report validation),reset_layer_paramswrite_custom_shader(revision-keyed compile ack; returns the exact sanitizer/transpile/eval error),get_custom_shader,get_shader_api_reference(house util sources read from disk +three/tslexports enumerated at runtime — can't drift)Verified live
Driven end-to-end against a real Chrome Canary tab: wrote shaders that compiled on the GPU (fbm/cosine plasma, liquid-mercury chrome with RGB-split refraction, a Kuwahara oil-paint filter over a live webcam), tweaked params with live clamping, reordered layers, and screenshotted the results back. One doc fix came out of it: layer stacking is Photoshop-style (index 0 = top, applied last).
Testing
dist/stdio.js, connect an MCP client over stdio, and fake an editor tab over the real bridge.bun test110 pass, lint clean, root + package typechecks green (CI gets a dedicated MCP typecheck step).Notes
typescript.skipTypeCheckinxmcp.config.ts; the package's owntsc --noEmitis the type gate (in CI)._zodtraits check) — package uses zod ^4.3.6, matching the app..gitignorebroadened tonode_modules/+ xmcp build outputs; changesets ignores the private MCP package.