Skip to content

armgit / forma

Public Imported from GitHub
0

A 1.2 MB pure-Rust rewrite of headless Blender built for AI agents — 3D B-rep modeling engine, CLI, and MCP server

8.8 KB
Raw Blame

MCP, JS/TS/Edge, and HTTP API reference

Exact interface contracts verified against wrong-nebula/forma v0.4.5 (crates/forma-mcp/src/main.rs, bin/forma-mcp.mjs, lib/edge.mjs, lib/workerd.mjs, lib/index.mjs, lib/index.d.ts, and crates/forma-server/src/main.rs).

MCP stdio JSON-RPC 2.0 API

  • Executables: native forma-mcp (crates/forma-mcp) or npm WASM forma-3d-mcp / forma-3d mcp (bin/forma-mcp.mjs).
  • Transport: newline-delimited JSON-RPC 2.0 over stdin/stdout.
  • Protocol version: "2024-11-05".
  • Server identity: { "name": "forma-mcp", "version": "0.4.5" }.
  • Supported methods: initialize, ping, tools/list, tools/call.
  • Token footprint: 721 o200k tokens across all 4 tool definitions (hard contributor ceiling < 800).

MCP tools

Tool Arguments Defaults / behavior
eval { code: string, strict?: boolean } strict defaults to true. Executes Forma-Pipe transactionally with auto-rollback on error or strict invariant failure. Scalar variables persist across calls (and roll back with tx); _-prefixed mesh vars stay local. Embeds SPEC_PIPE in the tool description.
inspect { topic?: "deform" | "curves" | "uv" | "normals" | "remesh" | "scene" } With no topic, returns compact scene state, invariants, and tags. With topic, returns the domain specification for that topic.
tx { action: "checkpoint" | "rollback" | "undo" | "reset", tag?: string } tag defaults to "default". Mutates or restores O(1) Arc<PolyMesh> scene snapshots (including scalar variables and Scene.unit).
export { path: string, part?: string, scene?: boolean, size?: integer } Writes .glb, .step, .3mf, .stl, .obj, .svg, .blend (via local Blender bridge), or .png (size defaults to 512). When scene: true, exports or renders all named parts together (.glb, .blend, .png, or .svg).

JavaScript / TypeScript / Edge WASM API (forma-3d)

Zero runtime dependencies and zero top-level node:* imports.

Package entry points (package.json exports)

Import / Condition Target Behavior
"forma-3d" (workerd) lib/workerd.mjs Zero-boilerplate Cloudflare Workers entry; statically imports ../wasm/forma.wasm.
"forma-3d" (edge-light, fastly, browser) or "forma-3d/edge" lib/edge.mjs Pure Web-standard loader (zero node:* references); accepts WebAssembly.Module, Response, Uint8Array, or URL.
"forma-3d" (node, default) lib/index.mjs Universal entry with lazy local-file loader for Node.js (>=18), Bun, and Deno.
"forma-3d/forma.wasm" / "forma-3d/wasm" wasm/forma.wasm Prebuilt wasm32-unknown-unknown module (lib/wasm.d.ts typed as WebAssembly.Module).

Top-level functions

Function Signature Return type
loadForma loadForma(wasmSource?: WasmSource, opts?: LoadFormaOptions) Promise<FormaEngine>
evalPipe evalPipe(code: string, opts?: EvalOptions) Promise<FormaObservation>
exportMesh exportMesh(code: string, format?: "glb" | "step" | "stp" | "3mf" | "stl" | "obj" | "svg" | "png", opts?: ExportOptions) Promise<Uint8Array>
renderPng renderPng(code: string, size?: number, opts?: ExportOptions) Promise<Uint8Array>
drawSvg drawSvg(code: string, opts?: ExportOptions) Promise<string>
getSpec getSpec(opts?: SpecOptions) Promise<string>
getSpecTopic getSpecTopic(topic: string, opts?: TopicOptions) Promise<string>

Exported TypeScript types (lib/index.d.ts)

  • WasmSource: WebAssembly.Module | WebAssembly.Instance | FormaEngine | ArrayBuffer | ArrayBufferView | Response | URL | string (or a Promise resolving to any of those).
  • LoadFormaOptions: { fresh?: boolean } (fresh: true creates a new WebAssembly.Instance instead of reusing the cached engine).
  • SessionEvalOptions: { dialect?: FormaDialect; strict?: boolean; unit?: FormaUnit | string } (strict defaults to true, dialect defaults to "pipe").
  • EvalOptions extends SessionEvalOptions: adds { wasm?: WasmSource }.
  • ExportOptions extends EvalOptions: adds { part?: string; size?: number }.
  • EngineSpecOptions: { dialect?: FormaDialect; gbnf?: boolean }; SpecOptions extends EngineSpecOptions adds { wasm?: WasmSource }.
  • TopicOptions: { wasm?: WasmSource }.
  • FormaObservation: { ok: boolean; elapsed_ms: number; parts: Record<string, FormaInvariants>; diff: string; warnings: string[]; text: string }.
  • FormaInvariants: { verts, edges, faces, tris, watertight, non_manifold_edges, boundary_edges, euler, genus, consistent_winding, degenerate_faces, nan_verts, components, signed_volume, volume, surface_area, bbox_min, bbox_max, size, tags }.

FormaEngine, FormaSession, and isolate trap recovery

  • engine.spec(opts?: EngineSpecOptions): string: returns the compiled language specification or GBNF grammar.
  • engine.specTopic(topic: string): string: returns the domain specification for "deform", "curves", "uv" / "normals", "remesh", or "scene".
  • engine.createSession(): FormaSession: allocates a stateful WASM scene session.
  • session.setUnit(unit: FormaUnit | string): string: sets the session model unit (m|cm|mm|um|in|ft).
  • session.eval(code: string, opts?: SessionEvalOptions): FormaObservation: evaluates code against the persistent scene.
  • session.inspect(): FormaObservation: returns the current scene observation without mutating state.
  • session.tx(action: "checkpoint" | "rollback" | "undo" | "reset", tag?: string): string: manages O(1) scene snapshots.
  • session.exportBytes(format, opts?: { part?: string; size?: number }): Uint8Array: exports a single part or visual render.
  • session.exportSceneBytes(): Uint8Array: exports all named parts as a multi-node .glb scene graph.
  • session.invariants(part?: string): FormaInvariants: returns structured invariants for the specified or last-modified part.
  • session.free(): void: releases the WASM-allocated session handle.
  • Trap recovery: If any WASM call throws WebAssembly.RuntimeError (e.g. out-of-memory), FormaEngine automatically evicts itself from internal caches so subsequent calls instantiate a clean WebAssembly.Instance.

forma-server HTTP/1.1 API (opt-in crate)

Binary built with cargo build --profile static-release -p forma-server (excluded from default-members).

Configuration

CLI flag Environment variable Default Constraints
--bind, -b FORMA_BIND 127.0.0.1:8080 (Dockerfile sets 0.0.0.0:8080) TCP host:port bind address.
--workers, -w FORMA_WORKERS available_parallelism().clamp(1, 8) Clamped to 1..=64.

Routes

Method and path Request Response
GET /health None 200 OK JSON: {"status":"ok","version":"0.4.5","workers":N}
GET /spec Optional query gbnf=1, dialect=compact, or topic=<name> 200 OK text/plain; charset=utf-8
POST /v1/eval JSON { code, strict?, dialect?, format?, size?, part?, unit?, assets? } format="json" (default) returns JSON (ok, elapsed_ms, text, parts, diff, warnings); format="text" returns text/plain; glb, obj, stl, 3mf, step/stp, png, svg return binary + X-Forma-* headers.
POST /v1/process JSON { asset_base64, input_format?, output_format?, size?, yup?, scale?, center_z0?, decimate?, target_faces?, unit? } scale accepts a uniform number or [sx, sy, sz]; target_faces works with or without decimate. Returns binary mesh/render (output_format defaults to "glb") + X-Forma-* headers.

Binary response headers

  • X-Forma-Exec-Ms: execution duration in milliseconds.
  • X-Forma-Watertight: true or false.
  • X-Forma-NonManifold: integer count of non-manifold edges.
  • X-Forma-Verts: integer vertex count.
  • X-Forma-Faces: integer face count.

Hardcoded limits and error status codes

Limit / guard Value in crates/forma-server/src/main.rs HTTP status on violation
Host filesystem access scene.allow_fs_import = false (assets via base64 only) 422 Unprocessable Entity
Max statements per request scene.max_statements = 1_024 422 Unprocessable Entity
Max request body size MAX_BODY_BYTES = 16 MiB (16 * 1024 * 1024) 413 Payload Too Large
Max header line / header count 16 KiB per line, 128 lines, 64 unique headers 431 Request Header Fields Too Large
Chunked request bodies Rejected (Content-Length required) 501 Not Implemented
Worker queue capacity workers * 8 bounded sync_channel 503 Service Unavailable
Socket read/write timeouts 15 seconds each Connection closed
Worker panic recovery std::panic::catch_unwind 500 Internal Server Error