copper3d 3.10.4 → 3.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +128 -0
- package/ai-index/guides/4D-MRI-LV-rendering.md +580 -0
- package/ai-index/guides/ai-assist-api.md +382 -0
- package/ai-index/guides/camera-framing.md +238 -0
- package/ai-index/guides/control-axes.md +124 -0
- package/ai-index/guides/copper3d-4D-API.md +219 -0
- package/ai-index/guides/copper3d-rendering-optimization.md +155 -0
- package/ai-index/guides/gltf-decoders.md +105 -0
- package/ai-index/guides/heart-sensor.md +137 -0
- package/ai-index/guides/load-callbacks.md +244 -0
- package/ai-index/guides/mcp-server.md +139 -0
- package/ai-index/guides/nrrd-tools.md +1888 -0
- package/ai-index/guides/on-demand-controls.md +154 -0
- package/ai-index/guides/rotation-pivot.md +197 -0
- package/ai-index/guides/scene-resources.md +227 -0
- package/ai-index/guides/segmentation-module.md +1539 -0
- package/ai-index/guides/surface-annotation-api.md +388 -0
- package/ai-index/guides/volume-display.md +194 -0
- package/ai-index/manifest.json +144 -0
- package/ai-index/symbols.json +1 -0
- package/dist/Utils/segmentation/DrawToolCore.d.ts +19 -0
- package/dist/Utils/segmentation/DrawToolCore.js +62 -36
- package/dist/Utils/segmentation/DrawToolCore.js.map +1 -1
- package/dist/Utils/segmentation/tools/DrawingTool.js +14 -2
- package/dist/Utils/segmentation/tools/DrawingTool.js.map +1 -1
- package/dist/Utils/segmentation/tools/ToolHost.d.ts +2 -1
- package/dist/bundle.esm.js +79 -41
- package/dist/bundle.umd.js +79 -41
- package/dist/types/Utils/segmentation/DrawToolCore.d.ts +19 -0
- package/dist/types/Utils/segmentation/tools/ToolHost.d.ts +2 -1
- package/package.json +7 -4
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# Heart Sensor (Kiwrious)
|
|
2
|
+
|
|
3
|
+
`copper3d` can read a Kiwrious heart-rate sensor over Web Serial, through the
|
|
4
|
+
`copper3d_plugin_heart_k` plugin.
|
|
5
|
+
|
|
6
|
+
**As of 3.9.0 the plugin is loaded on demand.** Existing code keeps working
|
|
7
|
+
unchanged, but there is one behavioural difference worth knowing about, and one
|
|
8
|
+
new export. Both are covered below.
|
|
9
|
+
|
|
10
|
+
## Quick start
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
import Copper from "copper3d";
|
|
14
|
+
|
|
15
|
+
await Copper.configKiwriousHeart(
|
|
16
|
+
connectButton,
|
|
17
|
+
disconnectButton,
|
|
18
|
+
"/kiwrious/bin/",
|
|
19
|
+
"/kiwrious/wasm/",
|
|
20
|
+
(connected) => console.log("connected:", connected),
|
|
21
|
+
(data, status, heartRate) => console.log(status, heartRate)
|
|
22
|
+
);
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
`configKiwriousHeart` wires both buttons, forwards connection changes to the
|
|
26
|
+
fifth argument, and forwards each decoded reading to the sixth.
|
|
27
|
+
|
|
28
|
+
## What changed in 3.9.0
|
|
29
|
+
|
|
30
|
+
### The plugin is no longer imported at module scope
|
|
31
|
+
|
|
32
|
+
`copper3d_plugin_heart_k` ships as a webpack UMD bundle. Its runtime resolves a
|
|
33
|
+
public path the moment the module evaluates, reading `document.currentScript`
|
|
34
|
+
or the last `<script src>` on the page. Native ESM provides neither, so the
|
|
35
|
+
plugin threw during evaluation:
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
Error: Automatic publicPath is not supported in this browser
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Because copper3d's entry point imported it statically, and because the code is
|
|
42
|
+
a side-effectful IIFE that tree-shaking cannot remove, **every** project paid
|
|
43
|
+
for it — `import "copper3d"` threw before a single line of copper3d ran, under
|
|
44
|
+
Vite, Nuxt, and anything else serving native ES modules.
|
|
45
|
+
|
|
46
|
+
The plugin now loads through a dynamic import that supplies the value the
|
|
47
|
+
webpack runtime is looking for and restores the document afterwards. Nothing is
|
|
48
|
+
fetched until you actually reach for the sensor.
|
|
49
|
+
|
|
50
|
+
**What you get:** `import "copper3d"` works under native ESM, and projects that
|
|
51
|
+
never touch the sensor never download it.
|
|
52
|
+
|
|
53
|
+
### `configKiwriousHeart` now returns a promise
|
|
54
|
+
|
|
55
|
+
It awaits the plugin before wiring the buttons, so a click landing immediately
|
|
56
|
+
after the call cannot race the import.
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
// Before -- still valid, buttons just go live a moment later
|
|
60
|
+
Copper.configKiwriousHeart(connectBtn, disconnectBtn, binUrl, wasmUrl, onConn, onData);
|
|
61
|
+
|
|
62
|
+
// Recommended: await it, then enable your UI
|
|
63
|
+
await Copper.configKiwriousHeart(connectBtn, disconnectBtn, binUrl, wasmUrl, onConn, onData);
|
|
64
|
+
connectBtn.disabled = false;
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
If you already render the buttons disabled and enable them yourself, awaiting is
|
|
68
|
+
the only change you need.
|
|
69
|
+
|
|
70
|
+
### `Copper.kiwrious` still works synchronously
|
|
71
|
+
|
|
72
|
+
The default export is a facade over the real plugin, so none of these calls
|
|
73
|
+
need an `await`:
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
Copper.kiwrious.setBinUrl("/kiwrious/bin/");
|
|
77
|
+
Copper.kiwrious.setWasm("/kiwrious/wasm/");
|
|
78
|
+
Copper.kiwrious.serialService.onSerialData = (reading) => { /* ... */ };
|
|
79
|
+
Copper.kiwrious.serialService.onSerialConnection = (connected) => { /* ... */ };
|
|
80
|
+
|
|
81
|
+
// This is the call that triggers the download.
|
|
82
|
+
await Copper.kiwrious.serialService.connectAndReadAsync();
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
URLs and callbacks set before the plugin arrives are replayed onto it as soon as
|
|
86
|
+
it does, in the order you set them.
|
|
87
|
+
|
|
88
|
+
Two consequences of the facade, both intentional:
|
|
89
|
+
|
|
90
|
+
- `isReading` and `canResumeReading` report `false` until the plugin has
|
|
91
|
+
loaded. Nothing can be reading before it exists.
|
|
92
|
+
- `disconnectAsync()`, `resumeReading()` and `triggerStopReading()` are no-ops
|
|
93
|
+
when nothing has loaded yet. Tearing down a session you never started must
|
|
94
|
+
not be what pulls a multi-megabyte bundle over the wire.
|
|
95
|
+
|
|
96
|
+
## `loadKiwrious()`
|
|
97
|
+
|
|
98
|
+
New in 3.9.0. Imports the plugin and resolves with it. Use it when you want to
|
|
99
|
+
control *when* the download happens — for example to warm it up while the
|
|
100
|
+
reader is still on an introduction screen, so pressing **Connect** is instant.
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
import Copper from "copper3d";
|
|
104
|
+
|
|
105
|
+
// Somewhere well before the user can press Connect
|
|
106
|
+
Copper.loadKiwrious().catch(() => {
|
|
107
|
+
// Optional: the sensor page is unavailable, degrade the UI
|
|
108
|
+
});
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
The import is memoized: concurrent callers share one download, and later calls
|
|
112
|
+
resolve immediately. Calling it is never required — `connectAndReadAsync()` and
|
|
113
|
+
`configKiwriousHeart()` both trigger the same load.
|
|
114
|
+
|
|
115
|
+
## Serving the sensor assets
|
|
116
|
+
|
|
117
|
+
The plugin fetches its own `.bin` and `.wasm` from the URLs you pass to
|
|
118
|
+
`setBinUrl` / `setWasm`, so those must be reachable from your deployed site.
|
|
119
|
+
Copy them out of the package at build time rather than hot-linking a CDN:
|
|
120
|
+
|
|
121
|
+
```
|
|
122
|
+
public/
|
|
123
|
+
kiwrious/
|
|
124
|
+
bin/…
|
|
125
|
+
wasm/…
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Both paths must be absolute or resolvable against your site's base URL. On a
|
|
129
|
+
subpath deploy (GitHub Pages project sites, for instance) prefix them with the
|
|
130
|
+
base — a bare `/kiwrious/bin/` resolves against the domain root and 404s.
|
|
131
|
+
|
|
132
|
+
## Requirements
|
|
133
|
+
|
|
134
|
+
Web Serial is required. It is available in Chromium-based browsers over HTTPS
|
|
135
|
+
(or `localhost`) and is not implemented in Firefox or Safari. `connectAndReadAsync()`
|
|
136
|
+
opens the browser's port-picker dialog, so it must be called from a user
|
|
137
|
+
gesture — a click handler, not a lifecycle hook.
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
# Load Progress & Errors
|
|
2
|
+
|
|
3
|
+
Every loader in copper3d gained `onProgress` and `onError` in **3.9.0**. Before
|
|
4
|
+
that there was no way to find out that a load had failed — a broken URL, a 404,
|
|
5
|
+
a corrupt file and a very slow download all looked identical from outside: the
|
|
6
|
+
callback simply never fired.
|
|
7
|
+
|
|
8
|
+
## What was there before
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
// pre-3.9.0, copperSceneOnDemond.loadGltf
|
|
12
|
+
loader.load(
|
|
13
|
+
url,
|
|
14
|
+
(gltf) => { /* ... */ },
|
|
15
|
+
(error) => {} // <- the onPROGRESS slot, named `error`, empty
|
|
16
|
+
);
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
`GLTFLoader.load(url, onLoad, onProgress, onError)` takes four arguments. The
|
|
20
|
+
third was an empty function named `error` — which reads correctly at a glance
|
|
21
|
+
and never fires on one — and there was no fourth. `loadNrrd` had a real progress
|
|
22
|
+
handler for its built-in loading bar and no error slot either.
|
|
23
|
+
|
|
24
|
+
## `scene.loadGltf`
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
scene.loadGltf(url, callback?, {
|
|
28
|
+
onProgress: (event) => console.log(event.loaded, event.total),
|
|
29
|
+
onError: (error) => showFailure(error),
|
|
30
|
+
});
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Both are optional and both default to nothing, so existing calls are unaffected.
|
|
34
|
+
|
|
35
|
+
Available on `copperSceneOnDemond`, `copperScene` and `copperMScene`. (
|
|
36
|
+
`copperScene.loadPureGLB` already took an `onError` and is unchanged.)
|
|
37
|
+
|
|
38
|
+
## `scene.loadNrrd`
|
|
39
|
+
|
|
40
|
+
The callbacks go on the existing `opts` object:
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
scene.loadNrrd(url, loadingBar, segmentation, callback, {
|
|
44
|
+
openGui: false,
|
|
45
|
+
onProgress: (event) => { /* ... */ },
|
|
46
|
+
onError: (error) => showFailure(error),
|
|
47
|
+
});
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
`onProgress` fires **in addition to** the built-in loading bar, which keeps
|
|
51
|
+
writing its percentage into `loadingBar.progress` exactly as before. Nothing
|
|
52
|
+
about the bar changes.
|
|
53
|
+
|
|
54
|
+
::: warning One visible behaviour change
|
|
55
|
+
The NRRD loading bar is now **hidden when a load fails**. It previously had no
|
|
56
|
+
failure state at all, so a failed volume left the bar up forever, frozen at
|
|
57
|
+
whatever percentage it reached — which is precisely what made a failure
|
|
58
|
+
indistinguishable from a slow load. Nothing else about the bar changed.
|
|
59
|
+
:::
|
|
60
|
+
|
|
61
|
+
## `opts.axes`: extract only the planes you show <Badge type="tip" text="3.9.0" />
|
|
62
|
+
|
|
63
|
+
`loadNrrd` has always extracted **all three** slice planes — x, y and z —
|
|
64
|
+
whether or not you display them. `extractSlice` walks the whole volume per
|
|
65
|
+
call, and the result is retained on `volume.sliceList` for the volume's
|
|
66
|
+
lifetime. On a 50MB MRI, an axis nobody looks at costs a full pass over the
|
|
67
|
+
buffer plus a geometry, a material and a canvas-backed texture that nothing
|
|
68
|
+
frees.
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
scene.loadNrrd(url, loadingBar, false, callback, {
|
|
72
|
+
openGui: false,
|
|
73
|
+
axes: ["z"], // an axial-only viewer
|
|
74
|
+
});
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Defaults to `["x", "y", "z"]`, i.e. exactly the previous behaviour.
|
|
78
|
+
|
|
79
|
+
::: warning
|
|
80
|
+
Omitted axes are `undefined` on the `nrrdMeshes` / `nrrdSlices` your callback
|
|
81
|
+
receives. Their types still declare all three present — widening them to
|
|
82
|
+
optional would break every existing caller's compile — so if you narrow
|
|
83
|
+
`axes`, only read what you asked for.
|
|
84
|
+
:::
|
|
85
|
+
|
|
86
|
+
### Extracting a skipped axis later <Badge type="tip" text="3.10.0" />
|
|
87
|
+
|
|
88
|
+
Narrowing `axes` is only safe if you never show the other planes. `ensureAxisExtracted`
|
|
89
|
+
lifts that restriction: it extracts a plane the load skipped, on demand, the first time
|
|
90
|
+
something asks for it.
|
|
91
|
+
|
|
92
|
+
```ts
|
|
93
|
+
import { ensureAxisExtracted } from "copper3d";
|
|
94
|
+
|
|
95
|
+
// slices came from loadNrrd with axes: ["z"] — no sagittal plane yet
|
|
96
|
+
ensureAxisExtracted(slices, "x"); // extracts it now
|
|
97
|
+
ensureAxisExtracted(slices, "x", meshes); // also fills meshes.x
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
It **mutates `slices` (and `meshes`, when given) in place**, so every existing reference
|
|
101
|
+
to the same object picks up the new plane — you do not replace anything. It is a no-op
|
|
102
|
+
when the axis is already present, so calling it unconditionally is fine.
|
|
103
|
+
|
|
104
|
+
All three axes share one `Volume` instance, so whichever axis *is* already extracted is
|
|
105
|
+
where the dimensions, spacing and RAS dimensions come from. A plane extracted late also
|
|
106
|
+
inherits the `contrastOrder` stamped on its siblings, making it indistinguishable from
|
|
107
|
+
one extracted at load time.
|
|
108
|
+
|
|
109
|
+
::: tip You usually do not need to call it yourself
|
|
110
|
+
`NrrdTools.setSliceOrientation(axis)` already calls `ensureAxisExtracted` for every
|
|
111
|
+
loaded contrast before the display pipeline reads the new plane. So an axial-only load
|
|
112
|
+
(`axes: ["z"]`) that later switches to sagittal or coronal just works — you pay the
|
|
113
|
+
extraction cost at switch time instead of at load time.
|
|
114
|
+
:::
|
|
115
|
+
|
|
116
|
+
## `opts.knownMinMax`: skip the whole-volume intensity scan <Badge type="tip" text="3.10.0" />
|
|
117
|
+
|
|
118
|
+
After parsing, three's `Volume.computeMinMax()` walks every voxel to find the intensity
|
|
119
|
+
range. On a large MRI that single function is typically the largest block in a case-load
|
|
120
|
+
CPU profile — and the answer is usually already known server-side, because the backend
|
|
121
|
+
decompressed the same bytes to write its headers.
|
|
122
|
+
|
|
123
|
+
```ts
|
|
124
|
+
const { min, max } = await fetch(`/files/${caseId}/headers`).then((r) => r.json());
|
|
125
|
+
|
|
126
|
+
scene.loadNrrd(url, loadingBar, false, callback, {
|
|
127
|
+
openGui: false,
|
|
128
|
+
knownMinMax: [min, max],
|
|
129
|
+
});
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Omit it — or pass a stale value — and behaviour is exactly as before: three's own scan
|
|
133
|
+
runs, and the image comes out identical, just slower.
|
|
134
|
+
|
|
135
|
+
## `opts.signal`: cancel a superseded load <Badge type="tip" text="3.10.0" />
|
|
136
|
+
|
|
137
|
+
A case switch or series switch used to leave the old transfer running to completion and
|
|
138
|
+
merely discard its result. Pass an `AbortSignal` and the transfer itself stops.
|
|
139
|
+
|
|
140
|
+
```ts
|
|
141
|
+
let inflight: AbortController | undefined;
|
|
142
|
+
|
|
143
|
+
function loadCase(url: string) {
|
|
144
|
+
inflight?.abort(); // stop the previous download
|
|
145
|
+
inflight = new AbortController();
|
|
146
|
+
|
|
147
|
+
scene.loadNrrd(url, loadingBar, false, onLoaded, {
|
|
148
|
+
openGui: false,
|
|
149
|
+
signal: inflight.signal,
|
|
150
|
+
onError: (error) => {
|
|
151
|
+
if ((error as DOMException).name === "AbortError") return; // expected
|
|
152
|
+
showFailure(error);
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
`onError` still fires for an aborted load — the rejection reason is a `DOMException` with
|
|
159
|
+
`name === "AbortError"`. Callers that already ignore errors from a stale load need no
|
|
160
|
+
further change.
|
|
161
|
+
|
|
162
|
+
Aborting rejects **your** promise immediately; it does not wait for the worker. The
|
|
163
|
+
worker is notified separately so it can drop its own attached-count for that URL and stop
|
|
164
|
+
the real network transfer once nobody is left waiting on it.
|
|
165
|
+
|
|
166
|
+
## NRRD parsing runs in a Web Worker <Badge type="tip" text="3.10.0" />
|
|
167
|
+
|
|
168
|
+
`loadNrrd` no longer fetches and parses on the main thread. The fetch, the gunzip and the
|
|
169
|
+
NRRD header/typed-array parse all happen in a shared Web Worker
|
|
170
|
+
(`Loader/nrrdWorker.ts`, whose logic lives in `Loader/nrrdWorkerCore.ts`); the volume's
|
|
171
|
+
pixel buffer comes back as a **transferable**, and the main thread only rehydrates a real
|
|
172
|
+
`Volume` around it — microseconds regardless of volume size.
|
|
173
|
+
|
|
174
|
+
Nothing about the public API changes. `onProgress`, `onError`, the built-in loading bar
|
|
175
|
+
and the `callback` signature all behave exactly as documented above.
|
|
176
|
+
|
|
177
|
+
Two consequences worth knowing:
|
|
178
|
+
|
|
179
|
+
- **URL-level fetch dedup lives in the worker.** Two concurrent `loadNrrd` calls for the
|
|
180
|
+
same URL share one network transfer, and each still gets its own parsed `Volume`.
|
|
181
|
+
- **The worker is inlined into the bundle** (`?worker&inline`), so there is no second
|
|
182
|
+
asset file to serve. A UMD bundle mounted at a base path unknown at build time still
|
|
183
|
+
works.
|
|
184
|
+
|
|
185
|
+
## Detecting a stalled download
|
|
186
|
+
|
|
187
|
+
A flat timeout is the wrong instrument for a large volume: a 53MB NRRD on a
|
|
188
|
+
shared 6 Mbps connection legitimately takes over a minute, and a fixed deadline
|
|
189
|
+
eventually fails a download that is perfectly healthy. What you want is *no
|
|
190
|
+
progress for N seconds*, which `onProgress` makes a few lines:
|
|
191
|
+
|
|
192
|
+
```ts
|
|
193
|
+
const STALL_MS = 15_000;
|
|
194
|
+
let timer: ReturnType<typeof setTimeout>;
|
|
195
|
+
|
|
196
|
+
function armStallTimer() {
|
|
197
|
+
clearTimeout(timer);
|
|
198
|
+
timer = setTimeout(() => showFailure(new Error("download stalled")), STALL_MS);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
armStallTimer();
|
|
202
|
+
scene.loadNrrd(url, loadingBar, false, (volume, meshes, slices) => {
|
|
203
|
+
clearTimeout(timer);
|
|
204
|
+
/* ... */
|
|
205
|
+
}, {
|
|
206
|
+
openGui: false,
|
|
207
|
+
onProgress: armStallTimer,
|
|
208
|
+
onError: (error) => { clearTimeout(timer); showFailure(error); },
|
|
209
|
+
});
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
Before 3.9.0 the only liveness signal copper3d exposed was the loading bar's
|
|
213
|
+
own text, so this had to be done by pointing a `MutationObserver` at that DOM
|
|
214
|
+
node.
|
|
215
|
+
|
|
216
|
+
## `event.total` is not always there
|
|
217
|
+
|
|
218
|
+
`ProgressEvent.total` is `0` unless the server sends a `Content-Length`, and it
|
|
219
|
+
does not send one for a gzipped or chunked response. `loaded / total` is then
|
|
220
|
+
`Infinity`, and the built-in bar renders `Infinity % loaded`.
|
|
221
|
+
|
|
222
|
+
Treat that as *indeterminate*, not as stuck at zero:
|
|
223
|
+
|
|
224
|
+
```ts
|
|
225
|
+
onProgress: (event) => {
|
|
226
|
+
const pct = event.total > 0 ? (event.loaded / event.total) * 100 : null;
|
|
227
|
+
setProgress(pct); // null -> show an indeterminate spinner
|
|
228
|
+
}
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
## Upgrading from 3.8.x
|
|
232
|
+
|
|
233
|
+
Purely additive apart from the loading-bar note above. Every argument is
|
|
234
|
+
optional and every default is what happened before.
|
|
235
|
+
|
|
236
|
+
## Upgrading from 3.9.x
|
|
237
|
+
|
|
238
|
+
Also purely additive. `knownMinMax`, `signal` and `ensureAxisExtracted` are all opt-in,
|
|
239
|
+
and the move to a worker is invisible from the outside — same callbacks, same loading
|
|
240
|
+
bar, same `Volume`.
|
|
241
|
+
|
|
242
|
+
The one thing to check is any code that was reaching into `copperNrrdLoader`'s internals
|
|
243
|
+
rather than going through `loadNrrd`: the old `sharedFetchNrrdArrayBuffer` + per-caller
|
|
244
|
+
`loader.parse()` pair is gone, replaced by the worker's own fetch dedup and parse.
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# AI Coding Assistants (MCP) <Badge type="tip" text="3.11.0" />
|
|
2
|
+
|
|
3
|
+
copper3d ships a machine-readable index of its own API and guides. Point your AI assistant
|
|
4
|
+
at it through the [`copper3d-mcp`](https://www.npmjs.com/package/copper3d-mcp) server and it
|
|
5
|
+
can look up real signatures instead of inventing them.
|
|
6
|
+
|
|
7
|
+
## Why this exists
|
|
8
|
+
|
|
9
|
+
copper3d has roughly **1,200 public symbols across 42 modules**, plus the hand-written guides
|
|
10
|
+
in this site. That does not fit in any model's context window, and it is not in any model's
|
|
11
|
+
training data — so assistants tend to produce plausible-looking calls that do not exist.
|
|
12
|
+
|
|
13
|
+
The server makes that surface searchable on demand.
|
|
14
|
+
|
|
15
|
+
::: tip It carries no documentation of its own
|
|
16
|
+
It reads the index that ships inside the copper3d installed in **your** project, so what the
|
|
17
|
+
assistant sees always matches the version you actually depend on — not whatever is newest on
|
|
18
|
+
this site.
|
|
19
|
+
:::
|
|
20
|
+
|
|
21
|
+
## Requirements
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install copper3d
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
The index lives at `node_modules/copper3d/ai-index/`. Releases from before 3.11.0 do not
|
|
28
|
+
contain it.
|
|
29
|
+
|
|
30
|
+
Working on copper3d itself rather than using it? The server also recognises the copper3d
|
|
31
|
+
repository, where `npm run build` puts the index at `<repo>/ai-index`, so no extra
|
|
32
|
+
configuration is needed there either.
|
|
33
|
+
|
|
34
|
+
## Setup
|
|
35
|
+
|
|
36
|
+
### Claude Code
|
|
37
|
+
|
|
38
|
+
The working directory is handled for you, so no path is needed:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
# just you, in this project
|
|
42
|
+
claude mcp add copper3d -- npx -y copper3d-mcp
|
|
43
|
+
|
|
44
|
+
# commit to .mcp.json so the team gets it on clone
|
|
45
|
+
claude mcp add --scope project copper3d -- npx -y copper3d-mcp
|
|
46
|
+
|
|
47
|
+
# all your projects
|
|
48
|
+
claude mcp add --scope user copper3d -- npx -y copper3d-mcp
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Every other client
|
|
52
|
+
|
|
53
|
+
Other clients start the server with a working directory that is **not** your project
|
|
54
|
+
([background](https://github.com/anthropics/claude-code/issues/75266)), so they have to be
|
|
55
|
+
told where it is with `--project`.
|
|
56
|
+
|
|
57
|
+
| Client | Config file | Root key | Needs `--project` |
|
|
58
|
+
|---|---|---|---|
|
|
59
|
+
| Claude Code | `claude mcp add`, or `.mcp.json` | `mcpServers` | no |
|
|
60
|
+
| Cursor | `.cursor/mcp.json` or `~/.cursor/mcp.json` | `mcpServers` | **yes** |
|
|
61
|
+
| VS Code / Copilot | `.vscode/mcp.json` | **`servers`** | **yes** |
|
|
62
|
+
| Claude Desktop | `%APPDATA%\Claude\claude_desktop_config.json`<br>`~/Library/Application Support/Claude/claude_desktop_config.json` | `mcpServers` | **yes** |
|
|
63
|
+
| Windsurf | `~/.codeium/windsurf/mcp_config.json` | `mcpServers` | **yes** |
|
|
64
|
+
|
|
65
|
+
**Cursor / Claude Desktop / Windsurf** — same shape in all three:
|
|
66
|
+
|
|
67
|
+
```json
|
|
68
|
+
{
|
|
69
|
+
"mcpServers": {
|
|
70
|
+
"copper3d": {
|
|
71
|
+
"command": "npx",
|
|
72
|
+
"args": ["-y", "copper3d-mcp", "--project", "/absolute/path/to/your/project"]
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Claude Desktop needs the absolute path in particular: it has no project, and it ignores the
|
|
79
|
+
`cwd` field.
|
|
80
|
+
|
|
81
|
+
**VS Code / Copilot** — note the different root key, and that `${workspaceFolder}` works
|
|
82
|
+
here:
|
|
83
|
+
|
|
84
|
+
```json
|
|
85
|
+
{
|
|
86
|
+
"servers": {
|
|
87
|
+
"copper3d": {
|
|
88
|
+
"type": "stdio",
|
|
89
|
+
"command": "npx",
|
|
90
|
+
"args": ["-y", "copper3d-mcp", "--project", "${workspaceFolder}"]
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## The four tools
|
|
97
|
+
|
|
98
|
+
All read-only.
|
|
99
|
+
|
|
100
|
+
| Tool | What it does |
|
|
101
|
+
|---|---|
|
|
102
|
+
| `copper3d_search_api` | Search by name, module, summary or parameter type. Members are indexed on their own, so `aiApplyMask` finds `NrrdTools.aiApplyMask` |
|
|
103
|
+
| `copper3d_get_symbol` | One symbol in full: signature, every parameter, return type, source location, related guides |
|
|
104
|
+
| `copper3d_list_guides` | Table of contents for the hand-written guides |
|
|
105
|
+
| `copper3d_get_guide` | Full markdown of one guide |
|
|
106
|
+
|
|
107
|
+
## Options
|
|
108
|
+
|
|
109
|
+
| | |
|
|
110
|
+
|---|---|
|
|
111
|
+
| `--project <path>` | Project directory to find `node_modules/copper3d` under |
|
|
112
|
+
| `COPPER3D_INDEX_PATH` | Skip discovery entirely: point straight at an `ai-index` directory |
|
|
113
|
+
|
|
114
|
+
Without either, the server looks at the MCP workspace roots, then `CLAUDE_PROJECT_DIR`, then
|
|
115
|
+
walks up from the working directory.
|
|
116
|
+
|
|
117
|
+
::: tip A failed lookup says so
|
|
118
|
+
If it finds no index it reports that and lists every path it tried. It never quietly returns
|
|
119
|
+
empty results — an assistant reading "no matches" would conclude the library has no API.
|
|
120
|
+
:::
|
|
121
|
+
|
|
122
|
+
## Troubleshooting
|
|
123
|
+
|
|
124
|
+
| Symptom | Cause | Fix |
|
|
125
|
+
|---|---|---|
|
|
126
|
+
| Tools never appear in VS Code | Used `mcpServers` in `.vscode/mcp.json` | VS Code calls it `servers` |
|
|
127
|
+
| "AI index was not found" | copper3d not installed, or the client lost the project directory | `npm i copper3d`, then add `--project /abs/path` |
|
|
128
|
+
| Assistant still invents APIs | Server not connected | `claude mcp list`, or your client's MCP panel |
|
|
129
|
+
|
|
130
|
+
## What it does not do
|
|
131
|
+
|
|
132
|
+
Documentation lookup only. copper3d runs in a browser on WebGL; the server is a Node process.
|
|
133
|
+
It cannot render a scene, execute your code, take screenshots or inspect a live canvas.
|
|
134
|
+
|
|
135
|
+
## Versioning
|
|
136
|
+
|
|
137
|
+
`copper3d-mcp` is versioned independently of `copper3d`. Because it only reads, a copper3d
|
|
138
|
+
release does not require a new release of the server — update copper3d and the assistant sees
|
|
139
|
+
the new API straight away.
|