index.ts: Blockbench plugin entry (registers MCP server and UI).server/: MCP server glue (server.ts),tools/,resources.ts,prompts.ts.ui/: Panel UI and settings (index.ts,settings.ts).lib/: Shared utilities and factories (constants.ts,factories.ts,util.ts,zodObjects.ts).prompts/andmacros/: Prompt templates and helpers.dist/: Build output (mcp.js, maps, copied assets likeicon.svg,about.md).docs/: Auto-generated documentation (api.json,index.html,style.css).build/: Build scripts (index.ts,utils.ts,plugins.ts,docs.ts,docs-manifest.ts).
bun install: Install dependencies.bun run dev: Build once with sourcemaps.bun run dev:watch: Rebuild on change (watch mode).bun run build: Minified production build todist/mcp.js.bun run ./build.ts --clean: Removedist/before a fresh build.bun run docs:build: Generate API documentation from Zod schemas todocs/.bun run docs:serve: Serve the generated docs locally with Tailwind processing.bunx @modelcontextprotocol/inspector: Launch MCP Inspector for local testing.
Every tool file in server/tools/ follows a two-part pattern:
- Export parameter schemas and a
toolDocsarray at module level (no Blockbench globals):
import { z } from "zod";
import { createTool, type ToolSpec } from "@/lib/factories";
export const myToolParameters = z.object({
name: z.string().describe("Name of the thing."),
});
export const myToolDocs: ToolSpec[] = [
{
name: "my_tool",
description: "Does something useful.",
annotations: { title: "My Tool", destructiveHint: true },
parameters: myToolParameters,
status: "stable",
},
];- Register with
createTool()inside aregisterXxxTools()function, spreading from the spec:
export function registerMyTools() {
createTool(myToolDocs[0].name, {
...myToolDocs[0],
async execute({ name }) {
// Blockbench globals (Undo, Canvas, etc.) are safe here
return `Hello, ${name}!`;
},
}, myToolDocs[0].status);
}-
Update the docs manifest in
build/docs-manifest.ts:- Import the
toolDocsarray from your tool file. - Add it to
toolManifestwith the appropriate category.
- Import the
-
Register in
server/tools.ts: Import and call yourregisterXxxTools()function. -
Regenerate docs: Run
bun run docsto updatedocs/api.jsonanddocs/index.html.
Parameter schemas are imported at build time by the doc generator, which runs outside Blockbench. Never use Blockbench runtime globals (e.g., BarItems, Formats, Plugins) in schema construction. Use z.string().describe("...") instead of dynamic enums, and do runtime validation inside execute().
Documentation is auto-generated from Zod schemas at build time:
build/docs-manifest.ts: Imports alltoolDocsarrays from tool files plus inline prompt/resource specs. This is the single source of truth for what appears in the docs.build/docs.ts: Reads the manifest, converts Zod schemas to JSON Schema viazod-to-json-schema, and outputsdocs/api.json(machine-readable) anddocs/index.html(Tailwind-styled page).lib/factories.ts: DefinesToolSpec,PromptSpec, andResourceSpecinterfaces used by both tool files and the manifest.
Prompt and resource specs are defined inline in the manifest (not imported from their source files) because server/prompts.ts uses Bun macros and server/resources.ts accesses Blockbench globals at module level.
- Language: TypeScript (strict), ESNext modules, CJS output for the plugin.
- Paths: Use alias
@/*(seetsconfig.json). - Indentation: 2 spaces; prefer explicit return types and narrow types.
- Keep UI text concise; avoid blocking calls in plugin lifecycle hooks.
- Schema naming:
{camelCaseToolName}Parameters(e.g.,placeCubeParameters). - Docs array naming:
{domainName}ToolDocs(e.g.,cubeToolDocs).
- Automated tests are not set up yet. For changes, provide manual verification steps.
- Validate builds with Blockbench by loading
dist/mcp.jsand exercising changed tools/resources. - When adding tests, prefer Bun's test runner or Vitest; co-locate near source or use
tests/.
- Commits: Use conventional prefixes (
feat:,fix:,chore:,docs:,refactor:). Avoid vague "update"; be specific (e.g.,feat: add mesh selection tools). - PRs: Include scope/summary, linked issues, screenshots/GIFs for UI changes, and steps to reproduce/test. Note any new tools, resources, settings, or breaking changes.
- Server config lives in Blockbench Settings: MCP port and endpoint (defaults
:3000/bb-mcp). - Do not commit secrets. Keep network calls behind tools; validate all inputs (use
zod). - Keep bundle lean: add only necessary deps; prefer tree-shakeable utilities.