Sıfırdan Yeni Bir Depo Başlatın:
Mevcut Bir Git Deposu veya Klasörü Gönderin:
Hataları Geri Alma, İptal & Temizlik:
Son commit'i geri al (yapılan değişiklikleri korur):
git reset --soft HEAD~1
Yapılan yerel değişiklikleri iptal et (çalışma ağacını temizler):
git restore .
Takip edilmeyen gereksiz dosyaları sil:
git clean -fd
Değişiklikleri geçici sakla ve geri getir (stash):
git stash git stash pop
Dal (Branch) ve Sürüm Etiketleri:
Yeni dal aç ve geçiş yap:
git checkout -b yeni-ozellik git push -u origin yeni-ozellik
Sürüm etiketi (tag) oluştur ve gönder:
git tag -a v1.0.0 -m "Sürüm 1.0.0" git push origin --tags
Additive fork feature letting an MCP server (driven by Claude) push parametric WorkplaneShape[] scenes into the running SketchForge editor. The Node side never writes browser storage; it stages a command file that an in-page poller applies through the editor's existing updateProjectShapes() save path. - Phase 1: apps/web/src/app/api/scene/route.ts — stages/serves commands behind the existing same-origin guard, with its own monotonic stagingRevision (separate from the app's project revision). - Phase 2: apps/web/src/lib/sceneBridge.ts (SceneTransport seam + polling transport) and a useSceneBridge poller hook in page.tsx (gated on ?bridge=1), which creates unknown projects and hydrates via updateProjectShapes; defers while dragging. - Phase 3: apps/mcp/ MCP server — set_scene/get_scene/add_shapes/list_kinds. zod validates the ShapeKind union enum + base numerics, then reuses the app's own sceneShape/canonicalizeShape for defaults/canonicalisation (no hand-authored ranges). - Phase 4: docs/scene-bridge/README.md plus vitest cases for the route handler and the schema validator. Staged scenes live under .codex/pending-scenes/ (gitignored). MCP registered via .mcp.json. npm run test: 29 passing. Co-Authored-By: Claude Opus 4.8 <[email protected]>
6.1 KiB
AI Scene Bridge
Push parametric 3D scenes from Claude (via an MCP server) into the running SketchForge
editor. Claude emits WorkplaneShape[] JSON; the editor's existing save path hydrates it
into the viewport. Manifold WASM (client-side) does all the actual CSG/meshing — the bridge
never does mesh maths.
The loop
Claude ──(MCP tool call)──▶ apps/mcp ──POST /api/scene──▶ Next route (server)
│ stages a command file:
│ .codex/pending-scenes/<id>.json
▼
editor viewport ◀── rehydration effect ◀── updateProjectShapes() ◀── poller in Home (page.tsx)
(renders shapes) (initialShapes/ (writes IndexedDB + GET /api/scene?sinceStaging=
projectRevision) localStorage + revision)
An MCP server is a Node process and cannot write the browser's IndexedDB/localStorage — that storage is sandboxed to the page origin. So the bridge always goes through the HTTP route + an in-page poller that reuses the app's own save path.
Two independent counters
stagingRevision— the bridge's own monotonic counter (per project, in the staged file). The poller pollsGET /api/scene?sinceStaging=<last applied>and only applies newer commands.- project
revision— the app's existing per-project revision, owned entirely byupdateProjectShapes(). The bridge never sets it.
These are kept separate on purpose: the bridge can re-deliver without fighting the app's own revisioning, and the editor defers an incoming push while the user is mid-drag.
Running it
- Start the app:
npm run dev # http://127.0.0.1:3000 - Open the editor in bridge mode, choosing any project id you like:
The id need not exist yet — the first
http://127.0.0.1:3000/?bridge=1&project=my-first-sceneset_scenecreates and opens it. - The MCP server is registered for Claude Code in
.mcp.jsonat the repo root (sketchforge-scene-bridge). It launches vianpm run start --prefix apps/mcpand talks to the app atSKETCHFORGE_BASE_URL(defaulthttp://127.0.0.1:3000). Claude Code picks up.mcp.jsonon startup — restart it once after first checkout and approve the server.
You can also run the server standalone for an MCP inspector:
SKETCHFORGE_BASE_URL=http://127.0.0.1:3000 npm run start --prefix apps/mcp
Tools
| Tool | Args | What it does |
|---|---|---|
list_kinds |
— | Lists every shape kind, its default dimensions, which optional fields matter, and example scenes. Call this first. |
set_scene |
projectId, shapes[], name? |
Replaces the project's scene. Unknown ids are created automatically. |
add_shapes |
projectId, shapes[] |
Appends shapes to the current scene (merge + re-stage). |
get_scene |
projectId |
Reads the current staged shapes back, so you can iterate. |
The data contract
WorkplaneShape (apps/web/src/types/sketchforge.ts) is THE contract. For authoring:
- Units are millimetres.
x/zposition on the workplane;elevationis height above it. - Every shape needs
kind+width+depth+height.color/nameauto-fill if omitted; position defaults to the origin. - A cutter is any shape with
hole: true. - A boolean/combined result carries its parts in
groupedShapes: WorkplaneShape[]. kindmust be one of the 18ShapeKindvalues (list_kinds). Some kinds need extra data (text→text/font;mesh→ imported geometry) and aren't directly generatable.
Validation
The MCP validates with zod against the ShapeKind union enum + the base numerics only,
then runs the app's own sceneShape/canonicalizeShape to fill defaults and canonicalise.
There are no hand-authored parameter ranges — the app's canonicaliser is the single
source of truth. So:
- a bad kind or malformed (non-numeric) field is rejected with a useful message, nothing is staged;
- a valid-but-extreme shape (e.g.
rotation: 725) is canonicalised (→5), not rejected.
Example prompts → scenes
- "a 40 mm phone stand with a cable slot" → base box + tilted backrest + front lip +
a
hole: truecylinder for the cable slot. - "a pen holder, a 50 mm cylinder hollowed from the top" → outer cylinder + inner
hole: truecylinder. - "a little toy house" → a box body + a
roofon top.
Iterating on a scene
get_scene(projectId) # read the current shapes
# edit the shape you want, e.g. widen the cable slot by 5 mm
set_scene(projectId, shapes) # re-stage; the editor updates in place
Because the scene lives in IndexedDB, it persists across reloads. While the user is dragging a shape, an incoming push is deferred (not fought) and applied when the drag ends.
Tests
npm run test
tests/unit/sceneRoute.test.ts— the/api/sceneroute handler (stage/poll, monotonicstagingRevision, same-origin 403, validation 400, 204 semantics).tests/unit/sceneSchema.test.ts— the MCP schema validator (defaults via the app's defaulter, cutter/grouped preserved, bad kind / malformed rejected, extreme canonicalised).
File map
| Path | Role |
|---|---|
apps/web/src/app/api/scene/route.ts |
Bridge route (stages/serves commands). |
apps/web/src/lib/sceneBridge.ts |
SceneTransport interface + polling transport (V2 swap point). |
apps/web/src/app/page.tsx |
useSceneBridge poller hook + applyBridgeCommand (in Home). |
apps/mcp/ |
MCP server: tools, zod schema, app-reused defaulter, example scenes. |
.codex/pending-scenes/<id>.json |
Staged command (gitignored). |
V2 (later)
The SceneTransport interface in sceneBridge.ts is the only forward-compatibility seam:
V2 replaces the polling transport with a WebSocket (subscribe()) so the MCP becomes the
live source of truth, while the route stays as a fallback and the WorkplaneShape contract
is unchanged. See PLAN.md → V2.