Skip to content

armgit / 67.js

Public Imported from GitHub
0

3D engine that AI agents drive

Test the docs and MCP server against other clients

Nguyen Xuan Anf40b8312b03f
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 84d2c8bb..4e9f1dc4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,8 @@
## Unreleased
+- Test the docs and the MCP server on clients other than Claude Code (part of issue #69). New `npm run check:tool-schemas` and `tests/other-clients.test.js` check all 22 tool definitions against rules other clients apply: name characters and length, a description under 1024 characters, an object root, a type on every constrained schema, resolvable `$ref`, declared `required` fields, a strict JSON Schema 2020-12 compile (Ajv 8, now a dev dependency) and an empty-argument call. Reports for OpenAI `strict: true` and for Gemini's documented keyword subset list each gap with its schema path; the test fails when a new kind of gap appears. Measured: the MCP SDK client and the MCP Inspector CLI list the 22 tools and call `scene_create`; a draft-07 Ajv compile rejects every tool (`$schema`, then `prefixItems`), strict OpenAI tools would reject the optional-heavy schemas, and nothing was run on Codex, Cursor, Gemini or any non-Anthropic model. A cold Haiku read of only the README and `llms.txt` installed the package and rendered a box but found no route to a PNG without MCP, so `docs/guide.md` gains a tested "Render a PNG from a script without MCP" recipe that the README and `llms.txt` point to; `docs/mcp.md` gains an "Other clients and models" table and no longer pins the standalone launch to 0.9.1. A test checks that every page `llms.txt` and the README link to exists. Schema bytes are unchanged.
+
- Fix the next agent tool errors (part of issue #66). `scene_review` and `scene_look` with `labels` on an imported asset failed with "needs the mesh code" because asset creation loaded the on-demand scene modules only for mesh edits; it now always does, and a test walks every preview path in a fresh process. `geometries` and `materials` are optional in a recipe. A failed `scene_create` says no scene was created and to call it again. `scene_inspect` on an asset accepts a source-node ID that holds one part and names the parts of one that holds several.
- Fix the most common agent tool errors (part of issue #66). `scene_look` and `scene_review` with `labels` on an imported asset threw `Cannot read properties of undefined (reading 'map')` (an asset recipe has no materials list, and asset mesh reports are keyed by part ID); an engine fault now reaches the agent as one advice message and goes to stderr. A node that names a geometry and no material gets an explicit `default` material instead of an error. `sessionId` is optional on every tool and defaults to the active scene (189,159 to 188,872 schema bytes); an ID that names another scene is still rejected. `scene_apply` names the fix when `set-node` fields are wrapped in `node`. The bench look harness loads the on-demand scene modules, so motion recipes get a look score.
diff --git a/README.md b/README.md
index 9c3932ec..43723dbb 100644
--- a/README.md
+++ b/README.md
@@ -84,6 +84,8 @@ const renderer = new Renderer67(canvas, parts, { samples: 4, memoryBudgetMiB: 25
renderer.render({ eye: [4, 3, 6], target: [0, 1, 0] });
```
+To save a PNG from a script without a browser window or an MCP client, use the [render-from-a-script recipe](docs/guide.md#render-a-png-from-a-script-without-mcp).
+
Call `renderer.resize()` after the canvas changes size, and `renderer.dispose()` before you replace the renderer.
Use `renderer.updateParts(parts)` to move or recolour parts without a new upload.
The [guide](docs/guide.md) covers cameras, lights, effects and every material field.
diff --git a/docs/guide.md b/docs/guide.md
index a6e9e558..6e2a2e35 100644
--- a/docs/guide.md
+++ b/docs/guide.md
@@ -70,6 +70,61 @@ The page displays a rounded green cube in a WebGL2 browser. The observer redraws
For a browser import without npm, use the exact `module` URL from [release metadata](/release.json) instead of `67js`.
The bundled ES module includes its dependencies. Serve the HTML over HTTP. Release metadata provides its URL for browser-only imports.
+## Render a PNG from a script without MCP
+
+A coding agent that has no MCP client can still produce an image from the installed package.
+The renderer needs a browser, so the script serves one page over HTTP and reads the canvas back through `playwright-core`, which the package already depends on.
+It needs an installed Google Chrome. Use `executablePath` instead of `channel` for another Chromium. Run it from the folder that holds `node_modules`:
+
+```js
+import { createServer } from 'node:http';
+import { readFile, writeFile } from 'node:fs/promises';
+import { chromium } from 'playwright-core';
+
+const page = `<!doctype html>
+<script type="importmap">{ "imports": { "67js": "/node_modules/67js/build/67.module.js" } }</script>
+<canvas width="512" height="512"></canvas>
+<script type="module">
+ import { Renderer67, box } from '67js';
+ const parts = [{
+ name: 'Box',
+ geometry: box(),
+ matrix: new Float32Array([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]),
+ material: { color: [0.8, 0.3, 0.2], metallic: 0, roughness: 0.35, emission: 0 },
+ }];
+ const canvas = document.querySelector('canvas');
+ new Renderer67(canvas, parts, { samples: 4, memoryBudgetMiB: 256 }).render({ eye: [3, 2.5, 4], target: [0, 0, 0] });
+ window.pngDataUrl = canvas.toDataURL('image/png');
+</script>`;
+
+const server = createServer(async (request, response) => {
+ if (request.url === '/') {
+ response.writeHead(200, { 'Content-Type': 'text/html' }).end(page);
+ return;
+ }
+ try {
+ const file = await readFile(`.${request.url}`);
+ response.writeHead(200, { 'Content-Type': 'text/javascript' }).end(file);
+ } catch {
+ response.writeHead(404).end();
+ }
+});
+await new Promise(resolve => server.listen(0, '127.0.0.1', resolve));
+
+const browser = await chromium.launch({ channel: 'chrome' });
+const tab = await browser.newPage();
+await tab.goto(`http://127.0.0.1:${server.address().port}/`);
+await tab.waitForFunction(() => window.pngDataUrl);
+const dataUrl = await tab.evaluate(() => window.pngDataUrl);
+await writeFile('box.png', Buffer.from(dataUrl.split(',')[1], 'base64'));
+await browser.close();
+server.close();
+```
+
+The canvas is read in the same task as the render, so no `preserveDrawingBuffer` option is needed.
+The `matrix` is a column-major 4x4 transform, and `box()` is a unit cube centred on the origin.
+The MCP server (`67js-mcp`) is the route for scene recipes, review grids and video, and `npm run render` in a source checkout exports video.
+
## Parts and geometry
A scene is an array of parts. Each part has a unique `name`, a shared `geometry`, a column-major 16-value `Float32Array` `matrix`, and a `material`.
diff --git a/docs/mcp.md b/docs/mcp.md
index 17678853..6f58c757 100644
--- a/docs/mcp.md
+++ b/docs/mcp.md
@@ -30,7 +30,7 @@ The MCP connection uses stdin and stdout, without an HTTP MCP listener.
```
Run the installed command with `npx 67js-mcp --backend gpu --memory 192`.
- For a standalone launch, use `npx --package @codepawlhq/[email protected] 67js-mcp --backend gpu --memory 192`.
+ For a standalone launch, use `npx --package @codepawlhq/67js 67js-mcp --backend gpu --memory 192`. Add `@<version>` after the package name to pin one.
`67js-mcp --help` lists options. `67js-mcp --version` reports the installed version.
2. Configure your MCP client with absolute paths to Node and the installed CLI:
@@ -67,6 +67,26 @@ The process runs below normal priority to reduce interference with other work.
Stdout contains only MCP protocol messages, while errors go to stderr.
Closing stdin or sending `SIGINT` or `SIGTERM` closes the runtime and releases its browser resources.
+## Other clients and models
+
+Every recorded agent run used Claude Code. This table says what was tried elsewhere on 2026-10-31 and what was not.
+
+| Client or check | Result |
+|---|---|
+| Official MCP SDK client over stdio (`npm run smoke:mcp-package`) | Passes. |
+| MCP Inspector CLI (`npx @modelcontextprotocol/inspector --cli node node_modules/67js/bin/67js-mcp.mjs --method tools/list`) | Lists all 22 tools. A `tools/call` of `scene_create` with a box recipe returned a session and inspection. |
+| JSON Schema 2020-12 validator with strict mode (Ajv 8), run in `npm test` | Every tool input schema compiles. |
+| Tool names and descriptions | Names are 9 to 24 characters from `[a-z_]`, within the 64-character limit OpenAI, Gemini and Anthropic share. No description is over 1024 characters. |
+| Codex, Cursor, Gemini CLI, Claude Desktop, VS Code, any OpenAI or Gemini model | Not run. No account or client was available. Configure them with the same `command` and `args` as above, which is unverified. |
+| Install by `npm install 67js@npm:@codepawlhq/67js`, then `npx 67js-mcp`, or `npx --package @codepawlhq/67js 67js-mcp`, or the absolute path to `bin/67js-mcp.mjs` | All four start and report the version. |
+
+Known gaps, checked by `npm run check:tool-schemas`:
+
+- The schemas declare JSON Schema 2020-12, the MCP default. A client that compiles them with a draft-07 validator rejects them: Ajv in its default draft-07 mode throws on `$schema`, and then on `prefixItems`, which is how fixed-length vectors are written.
+- OpenAI `strict: true` function tools would reject them: most properties are optional, objects do not set `additionalProperties: false`, and `oneOf`, `prefixItems` and `propertyNames` are outside the documented subset. A client that sends MCP tools as non-strict functions is unaffected.
+- Gemini function declarations document a smaller keyword subset than we use (`const`, `oneOf`, `$ref`, `exclusiveMinimum`). Open-ended records (`select` rules, material graphs, relations) are schemas with no `type`. A client that converts schemas for Gemini needs to inline `$ref` and drop or rewrite those keywords.
+- Whether a weaker or non-Anthropic model finds the tools is unmeasured: the agent-modeling suite ran only on Claude Sonnet and Haiku.
+
## Workflow
1. Call `scene_capabilities` to read supported features and runtime limits.
diff --git a/package-lock.json b/package-lock.json
index 2681d909..6e797589 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -19,6 +19,8 @@
"@dimforge/rapier3d-compat": "0.21.0",
"@modelcontextprotocol/client": "2.4.0",
"@modelcontextprotocol/server": "2.4.0",
+ "ajv": "^8.20.0",
+ "ajv-formats": "^3.0.1",
"esbuild": "0.28.2",
"gl-matrix": "3.4.4",
"highlight.js": "11.12.0",
@@ -2038,6 +2040,41 @@
"dev": true,
"license": "MIT"
},
+ "node_modules/ajv": {
+ "version": "8.20.0",
+ "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.20.0.tgz",
+ "integrity": "sha512-Thbli+OlOj+iMPYFBVBfJ3OmCAnaSyNn4M1vz9T6Gka5Jt9ba/HIR56joy65tY6kx/FCF5VXNB819Y7/GUrBGA==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "fast-deep-equal": "^3.1.3",
+ "fast-uri": "^3.0.1",
+ "json-schema-traverse": "^1.0.0",
+ "require-from-string": "^2.0.2"
+ },
+ "funding": {
+ "type": "github",
+ "url": "https://github.com/sponsors/epoberezkin"
+ }
+ },
+ "node_modules/ajv-formats": {
+ "version": "3.0.1",
+ "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-3.0.1.tgz",
+ "integrity": "sha512-8iUql50EUR+uUcdRQ3HDqa6EVyo3docL8g5WJ3FNcWmu62IbkGUue/pEyLBW8VGKKucTPgqeks4fIU1DA4yowQ==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "ajv": "^8.0.0"
+ },
+ "peerDependencies": {
+ "ajv": "^8.0.0"
+ },
+ "peerDependenciesMeta": {
+ "ajv": {
+ "optional": true
+ }
+ }
+ },
"node_modules/anynum": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/anynum/-/anynum-1.0.1.tgz",
@@ -2243,6 +2280,30 @@
"node": ">=18.0.0"
}
},
+ "node_modules/fast-deep-equal": {
+ "version": "3.1.3",
+ "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz",
+ "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==",
+ "dev": true,
+ "license": "MIT"
+ },
+ "node_modules/fast-uri": {
+ "version": "3.1.9",
+ "resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.1.9.tgz",
+ "integrity": "sha512-hS/0Wt3Ya043oKXs0sIxrMpKQITXhMLIrVAKKXi4gozGC9v7YRWVnXIZzjNPTO02M9BdxLCWqK1yRXgNziVyJQ==",
+ "dev": true,
+ "funding": [
+ {
+ "type": "github",
+ "url": "https://github.com/sponsors/fastify"
+ },
+ {
+ "type": "opencollective",
+ "url": "https://opencollective.com/fastify"
+ }
+ ],
+ "license": "BSD-3-Clause"
+ },
"node_modules/fast-xml-builder": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/fast-xml-builder/-/fast-xml-builder-1.3.1.tgz",
@@ -2395,6 +2456,13 @@
"url": "https://github.com/sponsors/panva"
}
},
+ "node_modules/json-schema-traverse": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz",
+ "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==",
+ "dev": true,
+ "license": "MIT"
+ },
"node_modules/kleur": {
"version": "4.1.5",
"resolved": "https://registry.npmjs.org/kleur/-/kleur-4.1.5.tgz",
@@ -3046,6 +3114,16 @@
}
}
},
+ "node_modules/require-from-string": {
+ "version": "2.0.2",
+ "resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz",
+ "integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": ">=0.10.0"
+ }
+ },
"node_modules/rolldown": {
"version": "1.2.16",
"resolved": "https://registry.npmjs.org/rolldown/-/rolldown-1.2.16.tgz",
diff --git a/package.json b/package.json
index 30f2b4d9..1d4fee31 100644
--- a/package.json
+++ b/package.json
@@ -120,7 +120,8 @@
"parity": "node scripts/parity-report.mjs",
"reference": "node bench/reference/run.mjs",
"size": "node scripts/measure-size.mjs",
- "benchmark:runtime": "node bench/runtime/run.mjs"
+ "benchmark:runtime": "node bench/runtime/run.mjs",
+ "check:tool-schemas": "node scripts/check-tool-schemas.mjs"
},
"peerDependencies": {
"@dimforge/rapier3d-compat": "0.21.0",
@@ -142,6 +143,8 @@
"@dimforge/rapier3d-compat": "0.21.0",
"@modelcontextprotocol/client": "2.4.0",
"@modelcontextprotocol/server": "2.4.0",
+ "ajv": "^8.20.0",
+ "ajv-formats": "^3.0.1",
"esbuild": "0.28.2",
"gl-matrix": "3.4.4",
"highlight.js": "11.12.0",
diff --git a/public/llms.txt b/public/llms.txt
index 8a649b10..65a59b2b 100644
--- a/public/llms.txt
+++ b/public/llms.txt
@@ -61,7 +61,7 @@ Topology changes reconcile rigid, untextured GPU parts. Geometry stays immutable
Tools accept bounded JSON and configured local assets. They expose no arbitrary code, remote asset providers or caller-selected file paths.
- [Release metadata](https://67js.codepawl.com/release.json): package name, version, publication status, install command, module URL and commit.
-- [Complete plain-text guide](https://67js.codepawl.com/guide.md): renderer, parts, materials, cameras, animation, lifecycle, export and troubleshooting.
+- [Complete plain-text guide](https://67js.codepawl.com/guide.md): renderer, parts, materials, cameras, animation, lifecycle, export and troubleshooting. The section "Render a PNG from a script without MCP" is a tested script for an agent with no MCP client.
- [GLB contract](https://67js.codepawl.com/gltf.md): supported assets and conversion limits. Read before selecting or importing a model.
- [Documentation](https://67js.codepawl.com/docs.html): the human reading interface for the same guide.
diff --git a/scripts/check-tool-schemas.mjs b/scripts/check-tool-schemas.mjs
new file mode 100644
index 00000000..e998b033
--- /dev/null
+++ b/scripts/check-tool-schemas.mjs
@@ -0,0 +1,227 @@
+import { pathToFileURL } from 'node:url';
+import { listTools } from './measure-tool-cost.mjs';
+
+/*
+ * Checks every MCP tool definition against rules other clients apply, without needing an account.
+ *
+ * Profiles:
+ * portable Rules every client we know of enforces. A finding here is a bug in our schema.
+ * openai-strict OpenAI Structured Outputs with `strict: true` function tools.
+ * Source: https://platform.openai.com/docs/guides/structured-outputs (supported schemas, 2026-10-31).
+ * gemini-subset Keywords outside the subset Gemini documents for structured output and function declarations.
+ * Sources: https://ai.google.dev/gemini-api/docs/structured-output and
+ * https://ai.google.dev/gemini-api/docs/function-calling (2026-10-31).
+ *
+ * The MCP specification makes JSON Schema 2020-12 the default dialect, so `$schema` and `prefixItems` are legal and
+ * are not reported as portable findings.
+ */
+
+export const TOOL_NAME_PATTERN = /^[A-Za-z_][A-Za-z0-9_-]{0,63}$/;
+export const MAX_DESCRIPTION_CHARACTERS = 1024;
+export const OPENAI_STRICT_MAX_PROPERTIES = 5000;
+export const OPENAI_STRICT_MAX_DEPTH = 10;
+export const OPENAI_STRICT_MAX_ENUM_VALUES = 1000;
+
+const ANNOTATION_KEYWORDS = new Set(['description', 'title', 'default', '$comment', 'examples']);
+const TYPE_DETERMINING_KEYWORDS = ['type', '$ref', 'anyOf', 'oneOf', 'allOf', 'const', 'enum', 'not'];
+const SCHEMA_MAP_KEYWORDS = ['properties', '$defs', 'patternProperties'];
+const SCHEMA_LIST_KEYWORDS = ['anyOf', 'oneOf', 'allOf', 'prefixItems'];
+const SCHEMA_VALUE_KEYWORDS = ['items', 'additionalProperties', 'not', 'propertyNames'];
+const JSON_SCHEMA_TYPES = new Set(['string', 'number', 'integer', 'boolean', 'object', 'array', 'null']);
+const OPENAI_STRICT_UNSUPPORTED_KEYWORDS = ['allOf', 'not', 'dependentRequired', 'dependentSchemas', 'if', 'then', 'else', 'oneOf', 'prefixItems', 'propertyNames', 'patternProperties'];
+const GEMINI_UNSUPPORTED_KEYWORDS = ['const', 'oneOf', 'allOf', 'not', 'exclusiveMinimum', 'exclusiveMaximum', 'propertyNames', 'patternProperties', 'uniqueItems'];
+
+function isPlainObject(value) {
+ return value !== null && typeof value === 'object' && !Array.isArray(value);
+}
+
+/** Calls visit(schema, path, depth) for every schema node below and including the given one. */
+export function visitSchemaNodes(schema, path, visit, depth = 1) {
+ if (!isPlainObject(schema)) return;
+ visit(schema, path, depth);
+ for (const keyword of SCHEMA_MAP_KEYWORDS) {
+ if (!isPlainObject(schema[keyword])) continue;
+ for (const [key, child] of Object.entries(schema[keyword])) {
+ visitSchemaNodes(child, `${path}.${keyword}.${key}`, visit, depth + 1);
+ }
+ }
+ for (const keyword of SCHEMA_LIST_KEYWORDS) {
+ if (!Array.isArray(schema[keyword])) continue;
+ schema[keyword].forEach((child, index) => visitSchemaNodes(child, `${path}.${keyword}[${index}]`, visit, depth + 1));
+ }
+ for (const keyword of SCHEMA_VALUE_KEYWORDS) {
+ visitSchemaNodes(schema[keyword], `${path}.${keyword}`, visit, depth + 1);
+ }
+}
+
+/** An empty schema, or one with only annotations, accepts any JSON value. It is legal, but some clients want a type. */
+export function isAnyValueSchema(node) {
+ return Object.keys(node).every(keyword => ANNOTATION_KEYWORDS.has(keyword));
+}
+
+function finding(profile, rule, tool, path, detail) {
+ return { profile, rule, tool, path, detail };
+}
+
+function resolveLocalReference(reference, root) {
+ if (reference === '#') return root;
+ const prefix = '#/$defs/';
+ if (!reference.startsWith(prefix)) return undefined;
+ return isPlainObject(root.$defs) ? root.$defs[reference.slice(prefix.length)] : undefined;
+}
+
+function checkToolDefinition(tool) {
+ const findings = [];
+ const root = tool.inputSchema;
+ if (!TOOL_NAME_PATTERN.test(tool.name)) {
+ findings.push(finding('portable', 'tool-name', tool.name, tool.name, `name must match ${TOOL_NAME_PATTERN}`));
+ }
+ if (typeof tool.description !== 'string' || tool.description.length === 0) {
+ findings.push(finding('portable', 'description-missing', tool.name, 'description', 'a tool needs a description'));
+ } else if (tool.description.length > MAX_DESCRIPTION_CHARACTERS) {
+ findings.push(finding('portable', 'description-length', tool.name, 'description', `${tool.description.length} characters, over ${MAX_DESCRIPTION_CHARACTERS}`));
+ }
+ if (!isPlainObject(root) || root.type !== 'object' || !isPlainObject(root.properties)) {
+ findings.push(finding('portable', 'root-object', tool.name, 'inputSchema', 'the input schema must be type object with a properties map'));
+ return findings;
+ }
+ if (tool.outputSchema !== undefined && !isPlainObject(tool.outputSchema)) {
+ findings.push(finding('portable', 'output-schema', tool.name, 'outputSchema', 'an output schema must be an object'));
+ }
+ visitSchemaNodes(root, `${tool.name}.inputSchema`, (node, path) => {
+ findings.push(...checkPortableNode(tool.name, root, node, path));
+ });
+ return findings;
+}
+
+function checkPortableNode(toolName, root, node, path) {
+ const findings = [];
+ if (!isAnyValueSchema(node) && !TYPE_DETERMINING_KEYWORDS.some(keyword => keyword in node)) {
+ findings.push(finding('portable', 'missing-type', toolName, path, 'no type, $ref, anyOf, const or enum'));
+ }
+ if ('type' in node) {
+ const types = Array.isArray(node.type) ? node.type : [node.type];
+ if (!types.every(type => JSON_SCHEMA_TYPES.has(type))) {
+ findings.push(finding('portable', 'unknown-type', toolName, path, `type ${JSON.stringify(node.type)}`));
+ }
+ }
+ if ('$ref' in node && resolveLocalReference(node.$ref, root) === undefined) {
+ findings.push(finding('portable', 'unresolved-ref', toolName, path, `${node.$ref} does not point into this tool's own schema`));
+ }
+ if (Array.isArray(node.enum) && node.enum.length === 0) {
+ findings.push(finding('portable', 'empty-enum', toolName, path, 'enum has no values'));
+ }
+ if (Array.isArray(node.required) && isPlainObject(node.properties)) {
+ for (const name of node.required.filter(name => !(name in node.properties))) {
+ findings.push(finding('portable', 'required-not-declared', toolName, path, `required property ${name} is not in properties`));
+ }
+ }
+ return findings;
+}
+
+function countEnumValues(root) {
+ let total = 0;
+ visitSchemaNodes(root, '', node => {
+ if (Array.isArray(node.enum)) total += node.enum.length;
+ });
+ return total;
+}
+
+function countProperties(root) {
+ let total = 0;
+ visitSchemaNodes(root, '', node => {
+ if (isPlainObject(node.properties)) total += Object.keys(node.properties).length;
+ });
+ return total;
+}
+
+function checkOpenAiStrict(tool) {
+ const findings = [];
+ const root = tool.inputSchema;
+ if (!isPlainObject(root)) return findings;
+ if ('anyOf' in root) {
+ findings.push(finding('openai-strict', 'root-any-of', tool.name, `${tool.name}.inputSchema`, 'the root must not be anyOf'));
+ }
+ let deepest = 0;
+ visitSchemaNodes(root, `${tool.name}.inputSchema`, (node, path, depth) => {
+ deepest = Math.max(deepest, depth);
+ if (isPlainObject(node.properties)) {
+ if (node.additionalProperties !== false) {
+ findings.push(finding('openai-strict', 'additional-properties-not-false', tool.name, path, 'every object needs additionalProperties: false'));
+ }
+ const required = new Set(node.required ?? []);
+ const optional = Object.keys(node.properties).filter(name => !required.has(name));
+ if (optional.length > 0) {
+ findings.push(finding('openai-strict', 'optional-properties', tool.name, path, `${optional.length} properties are not required`));
+ }
+ }
+ if (isAnyValueSchema(node)) {
+ findings.push(finding('openai-strict', 'any-value-schema', tool.name, path, 'strict mode needs a type on every schema'));
+ }
+ for (const keyword of OPENAI_STRICT_UNSUPPORTED_KEYWORDS) {
+ if (keyword in node) findings.push(finding('openai-strict', `keyword-${keyword}`, tool.name, path, `${keyword} is not in the documented supported subset`));
+ }
+ });
+ if (deepest > OPENAI_STRICT_MAX_DEPTH) {
+ findings.push(finding('openai-strict', 'nesting-depth', tool.name, `${tool.name}.inputSchema`, `${deepest} levels, over ${OPENAI_STRICT_MAX_DEPTH}`));
+ }
+ const propertyTotal = countProperties(root);
+ if (propertyTotal > OPENAI_STRICT_MAX_PROPERTIES) {
+ findings.push(finding('openai-strict', 'property-count', tool.name, `${tool.name}.inputSchema`, `${propertyTotal} properties, over ${OPENAI_STRICT_MAX_PROPERTIES}`));
+ }
+ const enumTotal = countEnumValues(root);
+ if (enumTotal > OPENAI_STRICT_MAX_ENUM_VALUES) {
+ findings.push(finding('openai-strict', 'enum-count', tool.name, `${tool.name}.inputSchema`, `${enumTotal} enum values, over ${OPENAI_STRICT_MAX_ENUM_VALUES}`));
+ }
+ return findings;
+}
+
+function checkGeminiSubset(tool) {
+ const findings = [];
+ if (!isPlainObject(tool.inputSchema)) return findings;
+ visitSchemaNodes(tool.inputSchema, `${tool.name}.inputSchema`, (node, path) => {
+ if (isAnyValueSchema(node)) {
+ findings.push(finding('gemini-subset', 'any-value-schema', tool.name, path, 'Gemini function declarations need a type on every schema'));
+ }
+ for (const keyword of GEMINI_UNSUPPORTED_KEYWORDS) {
+ if (keyword in node) findings.push(finding('gemini-subset', `keyword-${keyword}`, tool.name, path, `${keyword} is outside the documented subset`));
+ }
+ if ('$ref' in node) {
+ findings.push(finding('gemini-subset', 'keyword-$ref', tool.name, path, '$ref needs a client that inlines references'));
+ }
+ });
+ return findings;
+}
+
+export function checkToolSchemas(tools) {
+ const findings = [];
+ const seenNames = new Set();
+ for (const tool of tools) {
+ if (seenNames.has(tool.name)) {
+ findings.push(finding('portable', 'duplicate-name', tool.name, tool.name, 'two tools share this name'));
+ }
+ seenNames.add(tool.name);
+ findings.push(...checkToolDefinition(tool));
+ findings.push(...checkOpenAiStrict(tool));
+ findings.push(...checkGeminiSubset(tool));
+ }
+ return findings;
+}
+
+export function summarizeFindings(findings) {
+ const summary = {};
+ for (const { profile, rule } of findings) {
+ summary[profile] ??= {};
+ summary[profile][rule] = (summary[profile][rule] ?? 0) + 1;
+ }
+ return summary;
+}
+
+if (import.meta.url === pathToFileURL(process.argv[1]).href) {
+ const tools = await listTools();
+ const findings = checkToolSchemas(tools);
+ console.log(JSON.stringify({ tools: tools.length, summary: summarizeFindings(findings) }, null, 2));
+ for (const item of findings.filter(candidate => candidate.profile === 'portable')) {
+ console.log(`${item.rule} ${item.path}: ${item.detail}`);
+ }
+}
diff --git a/tests/other-clients.test.js b/tests/other-clients.test.js
new file mode 100644
index 00000000..507ff89c
--- /dev/null
+++ b/tests/other-clients.test.js
@@ -0,0 +1,85 @@
+import test from 'node:test';
+import assert from 'node:assert/strict';
+import { existsSync, readFileSync } from 'node:fs';
+import { fileURLToPath } from 'node:url';
+import Ajv2020 from 'ajv/dist/2020.js';
+import addFormats from 'ajv-formats';
+import { listTools } from '../scripts/measure-tool-cost.mjs';
+import { checkToolSchemas, summarizeFindings, TOOL_NAME_PATTERN } from '../scripts/check-tool-schemas.mjs';
+
+const repositoryRoot = fileURLToPath(new URL('..', import.meta.url));
+const siteOrigin = 'https://67js.codepawl.com';
+const tools = await listTools();
+
+function createStrictValidator() {
+ const validator = new Ajv2020({ strict: true });
+ addFormats(validator);
+ return validator;
+}
+const findings = checkToolSchemas(tools);
+
+function formatFindings(items) {
+ return items.map(item => `${item.rule} ${item.path}: ${item.detail}`).join('\n');
+}
+
+test('every tool passes the rules all clients enforce', () => {
+ const portableFindings = findings.filter(item => item.profile === 'portable');
+ assert.equal(portableFindings.length, 0, formatFindings(portableFindings));
+});
+
+test('tool names use only the characters and length that OpenAI, Gemini and Anthropic accept', () => {
+ for (const tool of tools) {
+ assert.match(tool.name, TOOL_NAME_PATTERN);
+ }
+});
+
+test('every input schema compiles under a strict JSON Schema 2020-12 validator', () => {
+ for (const tool of tools) {
+ const validator = createStrictValidator();
+ assert.doesNotThrow(() => validator.compile(tool.inputSchema), `${tool.name} does not compile in strict mode`);
+ }
+});
+
+test('every tool accepts an empty-argument call only when it has no required fields', () => {
+ for (const tool of tools) {
+ const validate = createStrictValidator().compile(tool.inputSchema);
+ const required = tool.inputSchema.required ?? [];
+ assert.equal(validate({}), required.length === 0, `${tool.name} required fields ${JSON.stringify(required)}`);
+ }
+});
+
+test('strict-mode and subset gaps are the known ones, so a new kind of gap is noticed', () => {
+ const knownGaps = {
+ 'openai-strict': ['optional-properties', 'keyword-oneOf', 'keyword-prefixItems', 'any-value-schema', 'keyword-propertyNames', 'nesting-depth'],
+ 'gemini-subset': ['keyword-const', 'keyword-oneOf', 'keyword-$ref', 'any-value-schema', 'keyword-propertyNames', 'keyword-exclusiveMinimum', 'keyword-exclusiveMaximum'],
+ };
+ const summary = summarizeFindings(findings);
+ for (const [profile, rules] of Object.entries(knownGaps)) {
+ const unexpected = Object.keys(summary[profile] ?? {}).filter(rule => !rules.includes(rule));
+ assert.deepEqual(unexpected, [], `${profile} gained a new kind of finding; fix it or list it in docs/mcp.md`);
+ }
+});
+
+function linkedPaths(text) {
+ const absolute = [...text.matchAll(new RegExp(`${siteOrigin.replaceAll('.', '\\.')}(/[A-Za-z0-9._/-]*)`, 'g'))].map(match => match[1]);
+ const bare = [...text.matchAll(/`(\/[a-z0-9-]+\.(?:md|html|txt|json))`/g)].map(match => match[1]);
+ return [...new Set([...absolute, ...bare])];
+}
+
+function pageSources(path) {
+ const name = path.replace(/^\//, '');
+ return [`public/${name}`, `docs/${name}`, name, name === 'changelog.md' ? 'CHANGELOG.md' : null].filter(Boolean);
+}
+
+test('every page that llms.txt and the README link to exists in the package or on the site', () => {
+ const documents = ['public/llms.txt', 'README.md'].map(file => ({ file, text: readFileSync(`${repositoryRoot}${file}`, 'utf8') }));
+ const missing = [];
+ for (const { file, text } of documents) {
+ for (const path of linkedPaths(text)) {
+ if (path === '/' || path === '/release.json') continue;
+ const found = pageSources(path).some(source => existsSync(`${repositoryRoot}${source}`));
+ if (!found) missing.push(`${file} links ${path}`);
+ }
+ }
+ assert.deepEqual(missing, []);
+});