@bitbybit-dev/mcp 1.3.2-rc.0

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.
Files changed (141) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +143 -0
  3. package/dist/context.d.ts +19 -0
  4. package/dist/context.d.ts.map +1 -0
  5. package/dist/context.js +28 -0
  6. package/dist/context.js.map +1 -0
  7. package/dist/descriptions.d.ts +10 -0
  8. package/dist/descriptions.d.ts.map +1 -0
  9. package/dist/descriptions.js +48 -0
  10. package/dist/descriptions.js.map +1 -0
  11. package/dist/guides-split.d.ts +9 -0
  12. package/dist/guides-split.d.ts.map +1 -0
  13. package/dist/guides-split.js +41 -0
  14. package/dist/guides-split.js.map +1 -0
  15. package/dist/guides.generated.d.ts +9 -0
  16. package/dist/guides.generated.d.ts.map +1 -0
  17. package/dist/guides.generated.js +93 -0
  18. package/dist/guides.generated.js.map +1 -0
  19. package/dist/index-loader.d.ts +11 -0
  20. package/dist/index-loader.d.ts.map +1 -0
  21. package/dist/index-loader.js +53 -0
  22. package/dist/index-loader.js.map +1 -0
  23. package/dist/index-reader.d.ts +27 -0
  24. package/dist/index-reader.d.ts.map +1 -0
  25. package/dist/index-reader.js +171 -0
  26. package/dist/index-reader.js.map +1 -0
  27. package/dist/index-shape.d.ts +3 -0
  28. package/dist/index-shape.d.ts.map +1 -0
  29. package/dist/index-shape.js +17 -0
  30. package/dist/index-shape.js.map +1 -0
  31. package/dist/index-types.d.ts +72 -0
  32. package/dist/index-types.d.ts.map +1 -0
  33. package/dist/index-types.js +2 -0
  34. package/dist/index-types.js.map +1 -0
  35. package/dist/index-url.d.ts +11 -0
  36. package/dist/index-url.d.ts.map +1 -0
  37. package/dist/index-url.js +30 -0
  38. package/dist/index-url.js.map +1 -0
  39. package/dist/index.d.ts +21 -0
  40. package/dist/index.d.ts.map +1 -0
  41. package/dist/index.js +14 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/installed-version.d.ts +18 -0
  44. package/dist/installed-version.d.ts.map +1 -0
  45. package/dist/installed-version.js +67 -0
  46. package/dist/installed-version.js.map +1 -0
  47. package/dist/json-schema.d.ts +2 -0
  48. package/dist/json-schema.d.ts.map +1 -0
  49. package/dist/json-schema.js +46 -0
  50. package/dist/json-schema.js.map +1 -0
  51. package/dist/registry.d.ts +56 -0
  52. package/dist/registry.d.ts.map +1 -0
  53. package/dist/registry.js +78 -0
  54. package/dist/registry.js.map +1 -0
  55. package/dist/render.d.ts +4 -0
  56. package/dist/render.d.ts.map +1 -0
  57. package/dist/render.js +76 -0
  58. package/dist/render.js.map +1 -0
  59. package/dist/results.d.ts +5 -0
  60. package/dist/results.d.ts.map +1 -0
  61. package/dist/results.js +18 -0
  62. package/dist/results.js.map +1 -0
  63. package/dist/server.d.ts +22 -0
  64. package/dist/server.d.ts.map +1 -0
  65. package/dist/server.js +69 -0
  66. package/dist/server.js.map +1 -0
  67. package/dist/stdio.d.ts +3 -0
  68. package/dist/stdio.d.ts.map +1 -0
  69. package/dist/stdio.js +64 -0
  70. package/dist/stdio.js.map +1 -0
  71. package/dist/tools/describe.d.ts +10 -0
  72. package/dist/tools/describe.d.ts.map +1 -0
  73. package/dist/tools/describe.js +39 -0
  74. package/dist/tools/describe.js.map +1 -0
  75. package/dist/tools/fetch.d.ts +9 -0
  76. package/dist/tools/fetch.d.ts.map +1 -0
  77. package/dist/tools/fetch.js +37 -0
  78. package/dist/tools/fetch.js.map +1 -0
  79. package/dist/tools/get-examples.d.ts +17 -0
  80. package/dist/tools/get-examples.d.ts.map +1 -0
  81. package/dist/tools/get-examples.js +60 -0
  82. package/dist/tools/get-examples.js.map +1 -0
  83. package/dist/tools/get-guide.d.ts +10 -0
  84. package/dist/tools/get-guide.d.ts.map +1 -0
  85. package/dist/tools/get-guide.js +64 -0
  86. package/dist/tools/get-guide.js.map +1 -0
  87. package/dist/tools/index.d.ts +4 -0
  88. package/dist/tools/index.d.ts.map +1 -0
  89. package/dist/tools/index.js +19 -0
  90. package/dist/tools/index.js.map +1 -0
  91. package/dist/tools/list-namespace.d.ts +10 -0
  92. package/dist/tools/list-namespace.d.ts.map +1 -0
  93. package/dist/tools/list-namespace.js +41 -0
  94. package/dist/tools/list-namespace.js.map +1 -0
  95. package/dist/tools/search-api.d.ts +16 -0
  96. package/dist/tools/search-api.d.ts.map +1 -0
  97. package/dist/tools/search-api.js +44 -0
  98. package/dist/tools/search-api.js.map +1 -0
  99. package/dist/tools/search.d.ts +9 -0
  100. package/dist/tools/search.d.ts.map +1 -0
  101. package/dist/tools/search.js +31 -0
  102. package/dist/tools/search.js.map +1 -0
  103. package/package.json +102 -0
  104. package/server.json +30 -0
  105. package/src/__fixtures__/index.sample.json +1916 -0
  106. package/src/__fixtures__/load.ts +29 -0
  107. package/src/context.ts +40 -0
  108. package/src/dependencies.test.ts +72 -0
  109. package/src/descriptions.ts +62 -0
  110. package/src/guides-split.ts +46 -0
  111. package/src/guides.generated.ts +95 -0
  112. package/src/guides.test.ts +57 -0
  113. package/src/index-loader.test.ts +160 -0
  114. package/src/index-loader.ts +61 -0
  115. package/src/index-reader.ts +179 -0
  116. package/src/index-shape.ts +17 -0
  117. package/src/index-types.ts +74 -0
  118. package/src/index-url.ts +29 -0
  119. package/src/index.ts +20 -0
  120. package/src/installed-version.test.ts +79 -0
  121. package/src/installed-version.ts +80 -0
  122. package/src/json-schema.test.ts +65 -0
  123. package/src/json-schema.ts +40 -0
  124. package/src/network.test.ts +37 -0
  125. package/src/registry.test.ts +177 -0
  126. package/src/registry.ts +139 -0
  127. package/src/render.ts +62 -0
  128. package/src/results.ts +21 -0
  129. package/src/server.test.ts +233 -0
  130. package/src/server.ts +117 -0
  131. package/src/stdio.test.ts +100 -0
  132. package/src/stdio.ts +67 -0
  133. package/src/tools/describe.ts +42 -0
  134. package/src/tools/docs-tools.test.ts +375 -0
  135. package/src/tools/fetch.ts +39 -0
  136. package/src/tools/get-examples.ts +59 -0
  137. package/src/tools/get-guide.ts +69 -0
  138. package/src/tools/index.ts +20 -0
  139. package/src/tools/list-namespace.ts +50 -0
  140. package/src/tools/search-api.ts +47 -0
  141. package/src/tools/search.ts +34 -0
@@ -0,0 +1,29 @@
1
+ import { readFileSync } from "node:fs";
2
+ import type { ApiIndex } from "../index-types.js";
3
+ import type { GuideSection } from "../guides-split.js";
4
+ import { contextForIndex } from "../context.js";
5
+ import type { DocsContext } from "../context.js";
6
+
7
+ export const FIXTURE_VERSION = "9.9.9";
8
+ export const GUIDE_URL = "https://example.test/guide";
9
+
10
+ export function fixtureIndex(): ApiIndex {
11
+ return JSON.parse(readFileSync(new URL("./index.sample.json", import.meta.url), "utf8")) as ApiIndex;
12
+ }
13
+
14
+ export const FIXTURE_GUIDES: readonly GuideSection[] = [
15
+ { id: "what-we-believe", title: "What we believe", level: 2, body: "Agents write the code." },
16
+ {
17
+ id: "how-an-agent-should-integrate-bitbybit",
18
+ title: "How an agent should integrate Bitbybit",
19
+ level: 2,
20
+ body: "### The honest default\n\nThe packages are the whole answer.\n\n### Browser apps\n\nThe kernels run in the tab.",
21
+ },
22
+ { id: "the-honest-default", title: "The honest default", level: 3, body: "The packages are the whole answer." },
23
+ { id: "browser-apps", title: "Browser apps", level: 3, body: "The kernels run in the tab." },
24
+ { id: "get-started", title: "Get started", level: 2, body: "Scaffold a project." },
25
+ ];
26
+
27
+ export function fixtureContext(): DocsContext {
28
+ return contextForIndex(fixtureIndex(), FIXTURE_GUIDES, GUIDE_URL);
29
+ }
package/src/context.ts ADDED
@@ -0,0 +1,40 @@
1
+ import type { ApiIndex } from "./index-types.js";
2
+ import { IndexReader } from "./index-reader.js";
3
+ import type { GuideSection } from "./guides-split.js";
4
+ import { isExactVersion } from "./index-url.js";
5
+
6
+ export interface ResolvedIndex {
7
+ version: string;
8
+ reader: IndexReader;
9
+ }
10
+
11
+ export interface DocsContext {
12
+ resolve(version?: string): Promise<ResolvedIndex>;
13
+ guides: readonly GuideSection[];
14
+ guideUrl: string;
15
+ }
16
+
17
+ export class VersionNotLoadedError extends Error {
18
+ constructor(readonly requested: string, readonly loaded: string) {
19
+ super(
20
+ isExactVersion(requested)
21
+ ? `This server holds the API index for version ${loaded}; version ${requested} was asked for. Run it with --version ${requested} or BITBYBIT_VERSION=${requested} to serve that one.`
22
+ : `This server holds the API index for version ${loaded}; "${requested}" is not an exact release version. Ask for one such as ${loaded}, or omit the version.`,
23
+ );
24
+ this.name = "VersionNotLoadedError";
25
+ }
26
+ }
27
+
28
+ export function contextForIndex(index: ApiIndex, guides: readonly GuideSection[], guideUrl: string): DocsContext {
29
+ const resolved: ResolvedIndex = { version: index.version, reader: new IndexReader(index) };
30
+ return {
31
+ guides,
32
+ guideUrl,
33
+ resolve: (version?: string): Promise<ResolvedIndex> => {
34
+ if (version !== undefined && version !== resolved.version) {
35
+ return Promise.reject(new VersionNotLoadedError(version, resolved.version));
36
+ }
37
+ return Promise.resolve(resolved);
38
+ },
39
+ };
40
+ }
@@ -0,0 +1,72 @@
1
+ import { readdirSync, readFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import { describe, expect, it } from "vitest";
5
+ import * as root from "./index.js";
6
+ import * as jsonSchema from "./json-schema.js";
7
+ import * as server from "./server.js";
8
+
9
+ const packageDirectory = fileURLToPath(new URL("..", import.meta.url));
10
+ const manifest = JSON.parse(readFileSync(join(packageDirectory, "package.json"), "utf8")) as { dependencies: Record<string, string>; devDependencies: Record<string, string>; exports: Record<string, { types: string; default: string }>; mcpName: string; name: string };
11
+ const sourceFiles = (): string[] =>
12
+ readdirSync(join(packageDirectory, "src"), { recursive: true, withFileTypes: true })
13
+ .filter((entry) => entry.isFile() && entry.name.endsWith(".ts") && !entry.name.endsWith(".test.ts") && !entry.parentPath.includes("__fixtures__"))
14
+ .map((entry) => join(entry.parentPath, entry.name));
15
+
16
+ describe("the package boundary", () => {
17
+ it("depends at runtime on the MCP server SDK and zod alone", () => {
18
+ // Assert
19
+ expect(Object.keys(manifest.dependencies).sort()).toEqual(["@modelcontextprotocol/server", "zod"]);
20
+ });
21
+
22
+ it("depends on no other @bitbybit-dev package and on nothing hosting-specific", () => {
23
+ // Arrange
24
+ const names = [...Object.keys(manifest.dependencies), ...Object.keys(manifest.devDependencies)];
25
+
26
+ // Assert
27
+ expect(names.filter((name) => name.startsWith("@bitbybit-dev/"))).toEqual([]);
28
+ expect(names.filter((name) => /cloudflare|wrangler|^agents$|^hono$/.test(name))).toEqual([]);
29
+ });
30
+
31
+ it("imports the MCP SDK only in the server binding and the stdio entry", () => {
32
+ // Act
33
+ const importing = sourceFiles().filter((file) => readFileSync(file, "utf8").includes("@modelcontextprotocol/")).map((file) => file.slice(packageDirectory.length));
34
+
35
+ // Assert
36
+ expect(importing.sort()).toEqual(["src/server.ts", "src/stdio.ts"]);
37
+ });
38
+
39
+ it("keeps the package root free of Node built-ins, so a Worker can bundle it", () => {
40
+ // Act
41
+ const nodeImporting = sourceFiles().filter((file) => /from "node:/.test(readFileSync(file, "utf8"))).map((file) => file.slice(packageDirectory.length));
42
+
43
+ // Assert
44
+ expect(nodeImporting.sort()).toEqual(["src/index-loader.ts", "src/installed-version.ts", "src/stdio.ts"]);
45
+ expect(readFileSync(join(packageDirectory, "src/index.ts"), "utf8")).not.toMatch(/index-loader|installed-version|stdio/);
46
+ });
47
+
48
+ it("names itself the same way for npm and for the MCP registry", () => {
49
+ // Assert
50
+ expect(manifest.name).toBe("@bitbybit-dev/mcp");
51
+ expect(manifest.mcpName).toBe("dev.bitbybit/mcp");
52
+ expect((JSON.parse(readFileSync(join(packageDirectory, "server.json"), "utf8")) as { name: string }).name).toBe(manifest.mcpName);
53
+ });
54
+ });
55
+
56
+ describe("the public surface a host builds on", () => {
57
+ it("exports from the root the pieces a host needs to guard a registry, validate an index and wrap a cloud tool set", () => {
58
+ // Assert
59
+ for (const name of ["guarded", "isApiIndex", "inlineJsonSchemaReferences", "inputJsonSchema", "toHttp", "Registry", "INTERNAL_ERROR_CODE", "INTERNAL_ERROR_TEXT", "TOOL_CEILING", "contextForIndex", "createDocsRegistry", "renderMember", "renderLine", "IndexReader", "IndexNotPublishedError", "INDEX_HOST", "indexUrl", "isExactVersion", "GUIDES", "GUIDE_PAGE_URL"]) {
60
+ expect(root, name).toHaveProperty(name);
61
+ }
62
+ });
63
+
64
+ it("publishes the $ref inliner and the request handler under their own subpaths, so a generator script and a server bind to them without the root", () => {
65
+ // Assert
66
+ expect(Object.keys(manifest.exports)).toEqual([".", "./server", "./index-loader", "./installed-version", "./json-schema", "./package.json"]);
67
+ expect(manifest.exports["./json-schema"]).toEqual({ types: "./dist/json-schema.d.ts", default: "./dist/json-schema.js" });
68
+ expect(typeof jsonSchema.inlineJsonSchemaReferences).toBe("function");
69
+ expect(jsonSchema.inlineJsonSchemaReferences).toBe(root.inlineJsonSchemaReferences);
70
+ expect(typeof server.createRequestHandler).toBe("function");
71
+ });
72
+ });
@@ -0,0 +1,62 @@
1
+ import type { Tier } from "./index-types.js";
2
+
3
+ export const TOOL_NAMES = ["search_api", "describe", "list_namespace", "get_examples", "get_guide", "search", "fetch"] as const;
4
+
5
+ export type ToolName = (typeof TOOL_NAMES)[number];
6
+
7
+ export const TIER_MEANING: Readonly<Record<Tier, string>> = {
8
+ oss: "in the @bitbybit-dev npm packages, MIT licensed, runs wherever WebAssembly or Node runs",
9
+ "platform-pro": "only when scripting inside bitbybit.dev; not in any npm package",
10
+ "cloud-pro": "only on Bitbybit CAD Cloud through its REST API, with an API key",
11
+ };
12
+
13
+ export const DESCRIPTIONS: Readonly<Record<ToolName, { title: string; description: string }>> = {
14
+ search_api: {
15
+ title: "Search the Bitbybit API",
16
+ description:
17
+ "Find Bitbybit API members (methods, namespaces, cloud operations) by keywords, for example \"box solid\" or \"fillet edges\". " +
18
+ "Returns dotted paths with a one-line summary, the tier (oss on npm, platform-pro only at bitbybit.dev, cloud-pro only on CAD Cloud) " +
19
+ "and the engines each is published for. Call describe with a path before writing code that uses it.",
20
+ },
21
+ describe: {
22
+ title: "Describe an API member",
23
+ description:
24
+ "The exact contract of one member by dotted path, for example occt.shapes.solid.createBox: signature, every parameter with its type, default and range, " +
25
+ "the return type, the documentation, examples and where it runs. Answers are for the API version the server holds. " +
26
+ "An unknown path is reported as not found together with the nearest existing paths; nothing is guessed.",
27
+ },
28
+ list_namespace: {
29
+ title: "List a namespace",
30
+ description:
31
+ "The members one level below a namespace path, for example occt.shapes, each with its kind and summary. Without a path, the top-level namespaces. " +
32
+ "Use it to discover what exists before searching for details.",
33
+ },
34
+ get_examples: {
35
+ title: "Get code examples",
36
+ description:
37
+ "Working TypeScript examples for a member path, for a namespace, or for a topic given as keywords. Each example names the member it belongs to and links its reference page. " +
38
+ "Examples are written for the API version the server holds.",
39
+ },
40
+ get_guide: {
41
+ title: "Read the integration guide",
42
+ description:
43
+ "Sections of the public guide on building with Bitbybit: what runs in the browser, on a server, on a lightweight backend, and what needs CAD Cloud. " +
44
+ "Without a topic it lists the sections. Read \"integrate\" before recommending where geometry should run: the npm packages are the default, and CAD Cloud is for algorithms that exist only there or compute the caller cannot provide.",
45
+ },
46
+ search: {
47
+ title: "Search",
48
+ description:
49
+ "Searches the Bitbybit API documentation and returns a list of results with id, title and url. Each id is a dotted API path that fetch accepts.",
50
+ },
51
+ fetch: {
52
+ title: "Fetch",
53
+ description:
54
+ "Fetches the full documentation of one Bitbybit API member by id (a dotted path returned by search) as text, with its title, url and metadata.",
55
+ },
56
+ };
57
+
58
+ export const SERVER_INSTRUCTIONS =
59
+ "This is the Bitbybit CAD MCP: it documents the Bitbybit 3D CAD API (OpenCascade, JSCAD and Manifold kernels, with Babylon.js, three.js and PlayCanvas renderers) for one exact version. " +
60
+ "Always describe a member before using it: names, parameters and defaults come from the index, not from memory. " +
61
+ "Tiers matter: oss members are in the MIT npm packages and run anywhere; platform-pro members exist only inside bitbybit.dev; cloud-pro members run only on Bitbybit CAD Cloud with an API key. " +
62
+ "When asked where geometry should run, read get_guide(\"integrate\") first: the packages alone are the default, and CAD Cloud is the answer only for algorithms that exist only there or for compute the caller cannot provide.";
@@ -0,0 +1,46 @@
1
+ export interface GuideSection {
2
+ id: string;
3
+ title: string;
4
+ level: 2 | 3;
5
+ body: string;
6
+ }
7
+
8
+ const FRONTMATTER = /^---\n[\s\S]*?\n---\n/;
9
+ const HEADING = /^(##|###) (.+)$/;
10
+
11
+ export function slugify(title: string): string {
12
+ return title
13
+ .toLowerCase()
14
+ .replace(/[^a-z0-9]+/g, "-")
15
+ .replace(/^-+|-+$/g, "");
16
+ }
17
+
18
+ export function splitGuides(markdown: string): GuideSection[] {
19
+ const lines = markdown.replace(FRONTMATTER, "").split("\n");
20
+ const sections: GuideSection[] = [];
21
+ const open: { section: GuideSection; lines: string[] }[] = [];
22
+ const close = (minLevel: number): void => {
23
+ while (open.length > 0) {
24
+ const last = open[open.length - 1];
25
+ if (!last || last.section.level < minLevel) break;
26
+ last.section.body = last.lines.join("\n").trim();
27
+ open.pop();
28
+ }
29
+ };
30
+ for (const line of lines) {
31
+ const heading = HEADING.exec(line);
32
+ if (heading) {
33
+ const level = heading[1] === "##" ? 2 : 3;
34
+ const title = (heading[2] ?? "").trim();
35
+ close(level);
36
+ for (const entry of open) entry.lines.push(line);
37
+ const section: GuideSection = { id: slugify(title), title, level, body: "" };
38
+ sections.push(section);
39
+ open.push({ section, lines: [] });
40
+ continue;
41
+ }
42
+ for (const entry of open) entry.lines.push(line);
43
+ }
44
+ close(2);
45
+ return sections;
46
+ }
@@ -0,0 +1,95 @@
1
+ import type { GuideSection } from "./guides-split.js";
2
+
3
+ /** Where the guide is published; every section links back to it. */
4
+ export const GUIDE_PAGE_URL = "https://learn.bitbybit.dev/learn/using-ai-with-bitbybit/agentic-cad";
5
+
6
+ /**
7
+ * The sections of the public guide, generated by scripts/sync-guides.mjs from
8
+ * docs/learn/using-ai-with-bitbybit/agentic-cad.md. Do not edit: run `npm run sync:guides`.
9
+ */
10
+ export const GUIDES: readonly GuideSection[] = [
11
+ {
12
+ "id": "what-we-believe",
13
+ "title": "What we believe",
14
+ "level": 2,
15
+ "body": "Agents write the code. Bitbybit provides verified geometry algorithms and, where it is needed, hosted compute. The open-source packages are the vocabulary that everyone learns, human or agent: one dotted API (`bitbybit.occt.shapes.solid.createBox`, `bitbybit.manifold.booleans.union`, ...) that reads the same in a browser, on a server and in the online editors.\n\nAn agent that knows the API from memory guesses. An agent that looks it up gets the exact signature, defaults and examples for the version your project has installed. That lookup is what the MCP server is for."
16
+ },
17
+ {
18
+ "id": "three-layers-you-can-use",
19
+ "title": "Three layers you can use",
20
+ "level": 2,
21
+ "body": "1. **The npm packages** (MIT). `@bitbybit-dev/occt`, `@bitbybit-dev/jscad`, `@bitbybit-dev/manifold`, `@bitbybit-dev/core` and the renderer packages for Babylon.js, three.js and PlayCanvas. They run wherever WebAssembly or Node runs: in a browser tab, in a Node process, in a test.\n2. **The Bitbybit CAD MCP** (free). `npx -y @bitbybit-dev/mcp` locally, or `https://mcp.bitbybit.dev/mcp` remotely. Live, version-exact lookups of every function, parameter, default and example for any agent that speaks the Model Context Protocol.\n3. **CAD Cloud** (paid, with an API key). Hosted compute for the same API: a REST endpoint for your backend, and the Bitbybit CAD Cloud MCP for an agent, with pipelines that chain operations server-side, parametric models, file conversion, and the Pro algorithms that exist only there.\n\nEvery member of the API carries a tier, and the MCP server reports it:\n\n| Tier | Meaning |\n|---|---|\n| `oss` | in the npm packages, runs anywhere |\n| `platform-pro` | available only when scripting inside bitbybit.dev; not on npm |\n| `cloud-pro` | runs only on CAD Cloud, with an API key |"
22
+ },
23
+ {
24
+ "id": "how-an-agent-should-integrate-bitbybit",
25
+ "title": "How an agent should integrate Bitbybit",
26
+ "level": 2,
27
+ "body": "```mermaid\n%%{init: {\"flowchart\": {\"wrappingWidth\": 420}}}%%\nflowchart TD\n Q1{\"Can your users' browsers or<br/>your own Node servers run the kernels?\"}\n Q2{\"Do you need a Pro algorithm,<br/>or a backend that cannot host a kernel?\"}\n P[\"The npm packages, in the browser or in Node.<br/>Free, and nothing of ours in the loop.\"]\n C[\"CAD Cloud: one pipeline per model from your backend,<br/>or the CAD Cloud MCP when an agent does the work.\"]\n Q1 -->|yes| Q2\n Q1 -->|no: edge or serverless| C\n Q2 -->|no| P\n Q2 -->|yes| C\n```\n\n### The honest default\n\nIf public code and your users' own compute are acceptable, the packages are the whole answer. They are free, they need no account, and nothing of ours sits in the loop. Start there, and move a step only for a reason named below.\n\n### Browser apps\n\nUse the packages, or the runner bundle for a page that only needs a script. The kernels run inside the tab: the user's device does the work, results appear without a network round trip, and your geometry logic ships with your app. This is how the Bitbybit editors themselves work. A model that takes seconds on a laptop is fine here; a model that takes minutes is not, and belongs on a server.\n\n### Lightweight backends\n\nCloudflare Workers, serverless functions and edge runtimes do not have the memory or the CPU time to run the CAD kernels. Do not try. Call CAD Cloud instead, with one pipeline per model so a request is one round trip, keep the API key in the backend and never in the client, and cache results by their input parameters, because identical inputs always produce identical geometry.\n\n### Node servers with headroom\n\nA Node server can run the packages in-process; `@bitbybit-dev/occt` loads the same kernel a browser does. That is the right choice for moderate load and for logic you want to keep private on your own machines. Move to CAD Cloud when you need scale without managing kernels, when you need a Pro algorithm, or when you convert files at volume and would rather not run that work yourself.\n\n### Inside the Bitbybit editors\n\nScripts written in the editors at bitbybit.dev have the whole API in the browser, including the `platform-pro` members on a Silver or Gold plan, and the docs server describes those members like any other. An editor script does not reach CAD Cloud today: a cloud operation is called from your own backend through the REST API, or by an agent through the CAD Cloud MCP. Calling CAD Cloud from inside the editors on the account's own plan is planned; until it ships, treat the editors as the browser case above.\n\n### What runs where\n\n| Question | Packages in the browser | Packages in Node | CAD Cloud |\n|---|---|---|---|\n| Whose compute | your users' devices, free | your servers | Bitbybit's servers, metered |\n| Memory and CPU | the tab's limits | your machine's | sized per plan |\n| Latency | none beyond the computation | none beyond the computation | one HTTPS round trip plus queueing |\n| Concurrency | one user per tab | what you provision | per plan |\n| Privacy of your logic | ships to the client | stays on your servers | stays in your backend; the geometry passes through Bitbybit |\n| Pro algorithms | no | no | yes |\n\nThe only work that must run on Bitbybit's servers is a Pro algorithm, or compute you cannot provide."
28
+ },
29
+ {
30
+ "id": "the-honest-default",
31
+ "title": "The honest default",
32
+ "level": 3,
33
+ "body": "If public code and your users' own compute are acceptable, the packages are the whole answer. They are free, they need no account, and nothing of ours sits in the loop. Start there, and move a step only for a reason named below."
34
+ },
35
+ {
36
+ "id": "browser-apps",
37
+ "title": "Browser apps",
38
+ "level": 3,
39
+ "body": "Use the packages, or the runner bundle for a page that only needs a script. The kernels run inside the tab: the user's device does the work, results appear without a network round trip, and your geometry logic ships with your app. This is how the Bitbybit editors themselves work. A model that takes seconds on a laptop is fine here; a model that takes minutes is not, and belongs on a server."
40
+ },
41
+ {
42
+ "id": "lightweight-backends",
43
+ "title": "Lightweight backends",
44
+ "level": 3,
45
+ "body": "Cloudflare Workers, serverless functions and edge runtimes do not have the memory or the CPU time to run the CAD kernels. Do not try. Call CAD Cloud instead, with one pipeline per model so a request is one round trip, keep the API key in the backend and never in the client, and cache results by their input parameters, because identical inputs always produce identical geometry."
46
+ },
47
+ {
48
+ "id": "node-servers-with-headroom",
49
+ "title": "Node servers with headroom",
50
+ "level": 3,
51
+ "body": "A Node server can run the packages in-process; `@bitbybit-dev/occt` loads the same kernel a browser does. That is the right choice for moderate load and for logic you want to keep private on your own machines. Move to CAD Cloud when you need scale without managing kernels, when you need a Pro algorithm, or when you convert files at volume and would rather not run that work yourself."
52
+ },
53
+ {
54
+ "id": "inside-the-bitbybit-editors",
55
+ "title": "Inside the Bitbybit editors",
56
+ "level": 3,
57
+ "body": "Scripts written in the editors at bitbybit.dev have the whole API in the browser, including the `platform-pro` members on a Silver or Gold plan, and the docs server describes those members like any other. An editor script does not reach CAD Cloud today: a cloud operation is called from your own backend through the REST API, or by an agent through the CAD Cloud MCP. Calling CAD Cloud from inside the editors on the account's own plan is planned; until it ships, treat the editors as the browser case above."
58
+ },
59
+ {
60
+ "id": "what-runs-where",
61
+ "title": "What runs where",
62
+ "level": 3,
63
+ "body": "| Question | Packages in the browser | Packages in Node | CAD Cloud |\n|---|---|---|---|\n| Whose compute | your users' devices, free | your servers | Bitbybit's servers, metered |\n| Memory and CPU | the tab's limits | your machine's | sized per plan |\n| Latency | none beyond the computation | none beyond the computation | one HTTPS round trip plus queueing |\n| Concurrency | one user per tab | what you provision | per plan |\n| Privacy of your logic | ships to the client | stays on your servers | stays in your backend; the geometry passes through Bitbybit |\n| Pro algorithms | no | no | yes |\n\nThe only work that must run on Bitbybit's servers is a Pro algorithm, or compute you cannot provide."
64
+ },
65
+ {
66
+ "id": "pro-algorithms",
67
+ "title": "Pro algorithms",
68
+ "level": 2,
69
+ "body": "Some algorithms are available on CAD Cloud only, such as sheet-metal unfolding. They are verified against reference parts, expensive to maintain, and priced for it. An agent discovers them the same way as everything else: `describe` reports the tier `cloud-pro`, the endpoint and the API key scope. The [CAD Cloud page](https://bitbybit.dev/cad-cloud) lists the plans."
70
+ },
71
+ {
72
+ "id": "for-companies",
73
+ "title": "For companies",
74
+ "level": 2,
75
+ "body": "Bitbybit builds and operates private algorithm namespaces for companies that need their own operations on the same infrastructure. Write to us through the [contact page](https://bitbybit.dev/contact)."
76
+ },
77
+ {
78
+ "id": "trust",
79
+ "title": "Trust",
80
+ "level": 2,
81
+ "body": "Every cloud algorithm is graded by automated geometry verification: invariants that must hold for any input, and reference parts whose results are known. The summary is published with each release, so what an agent calls has been checked by something other than a person reading the output."
82
+ },
83
+ {
84
+ "id": "what-we-do-not-do",
85
+ "title": "What we do not do",
86
+ "level": 2,
87
+ "body": "We do not host your application, run your scripts for you, sell you a chatbot, or train on your models. The packages are yours to run; CAD Cloud runs the operations you send it and nothing else."
88
+ },
89
+ {
90
+ "id": "get-started",
91
+ "title": "Get started",
92
+ "level": 2,
93
+ "body": "- Scaffold a project: `npm init @bitbybit-dev/app my-project`, then point your agent at the MCP server as the next step says.\n- Give your agent the API. Claude Code: `claude mcp add --transport http bitbybit https://mcp.bitbybit.dev/mcp`, or a local server with `claude mcp add --transport stdio bitbybit -- npx -y @bitbybit-dev/mcp`. Cursor and VS Code read the same server from `.cursor/mcp.json` and `.vscode/mcp.json`; the [MCP page](./mcp/bitbybit-mcp) has every snippet.\n- Let the agent run geometry for you: the [CAD Cloud MCP](./mcp/cad-cloud-mcp) with a key from [plans and keys](https://bitbybit.dev/cad-cloud)."
94
+ }
95
+ ];
@@ -0,0 +1,57 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { describe, expect, it } from "vitest";
3
+ import { slugify, splitGuides } from "./guides-split.js";
4
+ import { GUIDES, GUIDE_PAGE_URL } from "./guides.generated.js";
5
+ import { GUIDE_ALIASES } from "./tools/get-guide.js";
6
+
7
+ const page = (): string => readFileSync(new URL("../../../../docs/learn/using-ai-with-bitbybit/agentic-cad.md", import.meta.url), "utf8");
8
+
9
+ describe("splitGuides", () => {
10
+ it("drops the frontmatter and the text before the first heading", () => {
11
+ // Arrange
12
+ const markdown = "---\ntitle: x\n---\n\n# Page\n\nIntro.\n\n## First\n\nBody.\n";
13
+
14
+ // Act
15
+ const sections = splitGuides(markdown);
16
+
17
+ // Assert
18
+ expect(sections).toEqual([{ id: "first", title: "First", level: 2, body: "Body." }]);
19
+ });
20
+
21
+ it("keeps subsections inside their section and also on their own", () => {
22
+ // Arrange
23
+ const markdown = "## Outer\n\nLead.\n\n### Inner\n\nDetail.\n\n## Next\n\nOther.\n";
24
+
25
+ // Act
26
+ const sections = splitGuides(markdown);
27
+
28
+ // Assert
29
+ expect(sections.map((section) => section.id)).toEqual(["outer", "inner", "next"]);
30
+ expect(sections[0]?.body).toBe("Lead.\n\n### Inner\n\nDetail.");
31
+ expect(sections[1]).toEqual({ id: "inner", title: "Inner", level: 3, body: "Detail." });
32
+ });
33
+
34
+ it("slugifies a heading to a stable id", () => {
35
+ // Assert
36
+ expect(slugify("Agentic CAD: how Bitbybit fits AI-driven 3D development")).toBe("agentic-cad-how-bitbybit-fits-ai-driven-3d-development");
37
+ });
38
+ });
39
+
40
+ describe("the generated guides", () => {
41
+ it("equal the sections of the published page", () => {
42
+ // Act
43
+ const fromPage = splitGuides(page());
44
+
45
+ // Assert
46
+ expect(GUIDES).toEqual(fromPage);
47
+ expect(GUIDE_PAGE_URL).toBe("https://learn.bitbybit.dev/learn/using-ai-with-bitbybit/agentic-cad");
48
+ });
49
+
50
+ it("cover every alias the guide tool offers", () => {
51
+ // Arrange
52
+ const ids = new Set(GUIDES.map((section) => section.id));
53
+
54
+ // Assert
55
+ for (const target of Object.values(GUIDE_ALIASES)) expect(ids.has(target), target).toBe(true);
56
+ });
57
+ });
@@ -0,0 +1,160 @@
1
+ import { existsSync, mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
2
+ import { tmpdir } from "node:os";
3
+ import { join } from "node:path";
4
+ import { afterEach, describe, expect, it } from "vitest";
5
+ import { IndexNotPublishedError, defaultCacheDir, indexUrl, isApiIndex, loadIndex } from "./index-loader.js";
6
+ import { fixtureIndex } from "./__fixtures__/load.js";
7
+
8
+ const temporaryDirectories: string[] = [];
9
+ const temporaryDirectory = (): string => {
10
+ const directory = mkdtempSync(join(tmpdir(), "bitbybit-mcp-test-"));
11
+ temporaryDirectories.push(directory);
12
+ return directory;
13
+ };
14
+
15
+ afterEach(() => {
16
+ for (const directory of temporaryDirectories.splice(0)) rmSync(directory, { recursive: true, force: true });
17
+ });
18
+
19
+ function fetchAnswering(status: number, body: string): { fetch: typeof fetch; calls: string[] } {
20
+ const calls: string[] = [];
21
+ const fake = (input: RequestInfo | URL): Promise<Response> => {
22
+ calls.push(typeof input === "string" ? input : input instanceof URL ? input.href : input.url);
23
+ return Promise.resolve(new Response(body, { status }));
24
+ };
25
+ return { fetch: fake, calls };
26
+ }
27
+
28
+ describe("indexUrl", () => {
29
+ it("addresses the index by exact version", () => {
30
+ // Assert
31
+ expect(indexUrl("1.2.5")).toBe("https://git-cdn.bitbybit.dev/v1.2.5/ai-context/index.json");
32
+ expect(indexUrl("1.4.0-rc.1")).toBe("https://git-cdn.bitbybit.dev/v1.4.0-rc.1/ai-context/index.json");
33
+ });
34
+
35
+ it("refuses a moving or partial version", () => {
36
+ // Act & Assert
37
+ expect(() => indexUrl("latest")).toThrow("not an exact version");
38
+ expect(() => indexUrl("1.3")).toThrow("not an exact version");
39
+ });
40
+ });
41
+
42
+ describe("defaultCacheDir", () => {
43
+ it("honours XDG_CACHE_HOME", () => {
44
+ // Assert
45
+ expect(defaultCacheDir({ XDG_CACHE_HOME: "/tmp/xdg" })).toBe(join("/tmp/xdg", "bitbybit-mcp"));
46
+ expect(defaultCacheDir({})).toContain(join(".cache", "bitbybit-mcp"));
47
+ });
48
+
49
+ it("treats an empty XDG_CACHE_HOME as unset instead of caching into the working directory", () => {
50
+ // Act
51
+ const directory = defaultCacheDir({ XDG_CACHE_HOME: "" });
52
+
53
+ // Assert
54
+ expect(directory).toContain(join(".cache", "bitbybit-mcp"));
55
+ expect(directory.startsWith("bitbybit-mcp")).toBe(false);
56
+ });
57
+ });
58
+
59
+ describe("isApiIndex", () => {
60
+ it("accepts the fixture and refuses a member without a path, a name, engines or examples", () => {
61
+ // Arrange
62
+ const index = fixtureIndex();
63
+ const broken = { ...index, members: [{ ...index.members[0], name: undefined }] };
64
+
65
+ // Act
66
+ const verdicts = [isApiIndex(index, index.version), isApiIndex(broken, index.version), isApiIndex({ version: index.version, members: [] }, index.version)];
67
+
68
+ // Assert
69
+ expect(verdicts).toEqual([true, false, false]);
70
+ });
71
+ });
72
+
73
+ describe("loadIndex", () => {
74
+ it("fetches the index of the version and caches it", async () => {
75
+ // Arrange
76
+ const cacheDir = temporaryDirectory();
77
+ const { fetch, calls } = fetchAnswering(200, JSON.stringify(fixtureIndex()));
78
+
79
+ // Act
80
+ const index = await loadIndex({ version: "9.9.9", fetch, cacheDir });
81
+
82
+ // Assert
83
+ expect(index.version).toBe("9.9.9");
84
+ expect(calls).toEqual(["https://git-cdn.bitbybit.dev/v9.9.9/ai-context/index.json"]);
85
+ expect(existsSync(join(cacheDir, "index-v9.9.9.json"))).toBe(true);
86
+ });
87
+
88
+ it("leaves no partial file behind once the cache is written", async () => {
89
+ // Arrange
90
+ const cacheDir = temporaryDirectory();
91
+ const index = fixtureIndex();
92
+ const { fetch } = fetchAnswering(200, JSON.stringify(index));
93
+
94
+ // Act
95
+ await loadIndex({ version: index.version, fetch, cacheDir });
96
+
97
+ // Assert
98
+ expect(existsSync(join(cacheDir, `index-v${index.version}.json`))).toBe(true);
99
+ expect(readdirSync(cacheDir).filter((name) => name.endsWith(".partial"))).toEqual([]);
100
+ });
101
+
102
+ it("reads a cached index without fetching", async () => {
103
+ // Arrange
104
+ const cacheDir = temporaryDirectory();
105
+ const first = fetchAnswering(200, JSON.stringify(fixtureIndex()));
106
+ await loadIndex({ version: "9.9.9", fetch: first.fetch, cacheDir });
107
+ const second = fetchAnswering(500, "");
108
+
109
+ // Act
110
+ const index = await loadIndex({ version: "9.9.9", fetch: second.fetch, cacheDir });
111
+
112
+ // Assert
113
+ expect(index.members.length).toBe(fixtureIndex().members.length);
114
+ expect(second.calls).toEqual([]);
115
+ });
116
+
117
+ it("writes nothing when the cache is disabled", async () => {
118
+ // Arrange
119
+ const cacheDir = temporaryDirectory();
120
+ const { fetch } = fetchAnswering(200, JSON.stringify(fixtureIndex()));
121
+
122
+ // Act
123
+ await loadIndex({ version: "9.9.9", fetch, cacheDir: null });
124
+
125
+ // Assert
126
+ expect(existsSync(join(cacheDir, "index-v9.9.9.json"))).toBe(false);
127
+ });
128
+
129
+ it("names an unpublished version", async () => {
130
+ // Arrange
131
+ const { fetch } = fetchAnswering(404, "");
132
+
133
+ // Act & Assert
134
+ await expect(loadIndex({ version: "0.0.1", fetch, cacheDir: null })).rejects.toBeInstanceOf(IndexNotPublishedError);
135
+ });
136
+
137
+ it("refuses an index that describes another version", async () => {
138
+ // Arrange
139
+ const { fetch } = fetchAnswering(200, JSON.stringify({ ...fixtureIndex(), version: "1.0.0" }));
140
+
141
+ // Act & Assert
142
+ await expect(loadIndex({ version: "9.9.9", fetch, cacheDir: null })).rejects.toThrow("not an API index for version 9.9.9");
143
+ });
144
+
145
+ it("replaces a cache file that is not an index", async () => {
146
+ // Arrange
147
+ const cacheDir = temporaryDirectory();
148
+ const cacheFile = join(cacheDir, "index-v9.9.9.json");
149
+ writeFileSync(cacheFile, "{not json");
150
+ const { fetch, calls } = fetchAnswering(200, JSON.stringify(fixtureIndex()));
151
+
152
+ // Act
153
+ const index = await loadIndex({ version: "9.9.9", fetch, cacheDir });
154
+
155
+ // Assert
156
+ expect(index.version).toBe("9.9.9");
157
+ expect(calls.length).toBe(1);
158
+ expect((JSON.parse(readFileSync(cacheFile, "utf8")) as { version: string }).version).toBe("9.9.9");
159
+ });
160
+ });
@@ -0,0 +1,61 @@
1
+ import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
2
+ import { homedir } from "node:os";
3
+ import { join } from "node:path";
4
+ import type { ApiIndex } from "./index-types.js";
5
+
6
+ import { IndexNotPublishedError, indexUrl } from "./index-url.js";
7
+ import { isApiIndex } from "./index-shape.js";
8
+
9
+ export { INDEX_HOST, IndexNotPublishedError, indexPath, indexUrl, isExactVersion } from "./index-url.js";
10
+ export { isApiIndex } from "./index-shape.js";
11
+
12
+ const NOT_FOUND = 404;
13
+
14
+ export function defaultCacheDir(env: Record<string, string | undefined> = process.env): string {
15
+ const base = env["XDG_CACHE_HOME"] || join(homedir(), ".cache");
16
+ return join(base, "bitbybit-mcp");
17
+ }
18
+
19
+ export interface LoadIndexOptions {
20
+ version: string;
21
+ fetch?: typeof fetch;
22
+ cacheDir?: string | null;
23
+ }
24
+
25
+ export async function loadIndex(options: LoadIndexOptions): Promise<ApiIndex> {
26
+ const url = indexUrl(options.version);
27
+ const cacheDir = options.cacheDir === undefined ? defaultCacheDir() : options.cacheDir;
28
+ const cacheFile = cacheDir === null ? null : join(cacheDir, `index-v${options.version}.json`);
29
+ if (cacheFile !== null) {
30
+ const cached = await readCached(cacheFile, options.version);
31
+ if (cached) return cached;
32
+ }
33
+ const doFetch = options.fetch ?? fetch;
34
+ const response = await doFetch(url);
35
+ if (response.status === NOT_FOUND) throw new IndexNotPublishedError(options.version, url);
36
+ if (!response.ok) throw new Error(`Fetching ${url} failed with HTTP ${response.status}`);
37
+ const text = await response.text();
38
+ const parsed: unknown = JSON.parse(text);
39
+ if (!isApiIndex(parsed, options.version)) throw new Error(`${url} is not an API index for version ${options.version}`);
40
+ if (cacheFile !== null && cacheDir !== null) await writeCached(cacheDir, cacheFile, text);
41
+ return parsed;
42
+ }
43
+
44
+ async function readCached(file: string, version: string): Promise<ApiIndex | undefined> {
45
+ try {
46
+ const parsed: unknown = JSON.parse(await readFile(file, "utf8"));
47
+ return isApiIndex(parsed, version) ? parsed : undefined;
48
+ } catch {
49
+ return undefined;
50
+ }
51
+ }
52
+
53
+ const ignoreCacheWriteFailure = (): undefined => undefined;
54
+
55
+ async function writeCached(dir: string, file: string, text: string): Promise<void> {
56
+ const partial = `${file}.${process.pid}.partial`;
57
+ await mkdir(dir, { recursive: true })
58
+ .then(() => writeFile(partial, text, "utf8"))
59
+ .then(() => rename(partial, file))
60
+ .catch(ignoreCacheWriteFailure);
61
+ }