Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

feat: avatar glb assets, template picker updates, mcp-test refinements + tests

nirholas0a41f35fac42
diff --git a/api/developer/mcp-test.js b/api/developer/mcp-test.js
index 52fac861f..e231e39f5 100644
--- a/api/developer/mcp-test.js
+++ b/api/developer/mcp-test.js
@@ -1,14 +1,32 @@
-// POST /api/developer/mcp-test — test MCP connectivity for the dashboard.
+// POST /api/developer/mcp-test — exercise the MCP server for the dashboard's
+// "Test connection" button.
//
-// Authenticates via session cookie, then dispatches tools/list through the MCP
-// dispatch layer with a synthetic auth object matching the user. Returns the
-// tools list (or an error envelope) without requiring the client to hold a
-// plaintext API key (keys are hashed server-side and can't be retrieved).
+// A real MCP client authenticates with one of the user's API keys, then runs
+// the initialize → tools/list handshake. We can't replay the user's plaintext
+// key (it's hashed at creation and never stored), so this endpoint authenticates
+// the dashboard session, then validates the SELECTED key exactly as the bearer
+// path does — owned by the caller, not revoked, not expired — and dispatches the
+// handshake with that key's real scope. The result therefore reflects the actual
+// key the user is about to hand an MCP client: a revoked/expired/foreign key
+// fails here just as it would over the wire.
+//
+// Body: { keyId: string }
+// 200: { ok, protocolVersion, serverInfo, tools: [...], scopes: [...] }
+import { sql } from '../_lib/db.js';
import { getSessionUser } from '../_lib/auth.js';
-import { cors, json, method, wrap, error } from '../_lib/http.js';
+import { cors, json, method, readJson, wrap, error, rateLimited } from '../_lib/http.js';
+import { limits } from '../_lib/rate-limit.js';
import { dispatch } from '../_mcp/dispatch.js';
+// Mirror a real MCP client's initialize params so the handshake exercises the
+// same code path Claude Desktop / Cursor hit, not a degenerate empty call.
+const INITIALIZE_PARAMS = {
+ protocolVersion: '2025-06-18',
+ clientInfo: { name: 'three-ws-dashboard', version: '1.0.0' },
+ capabilities: {},
+};
+
export default wrap(async (req, res) => {
if (cors(req, res, { methods: 'POST,OPTIONS', credentials: true })) return;
if (!method(req, res, ['POST'])) return;
@@ -16,14 +34,37 @@ export default wrap(async (req, res) => {
const user = await getSessionUser(req);
if (!user) return error(res, 401, 'unauthorized', 'sign in to test MCP');
- const auth = {
- userId: user.id,
- scope: 'avatars:read avatars:write avatars:delete profile agents:read agents:write',
- source: 'session',
- };
+ const rl = await limits.mcpUser(user.id);
+ if (!rl.success) return rateLimited(res, rl);
+
+ const { keyId } = await readJson(req, 4_000).catch(() => ({}));
+ if (!keyId || typeof keyId !== 'string')
+ return error(res, 400, 'bad_request', 'keyId is required');
+
+ const [key] = await sql`
+ select id, scope, revoked_at, expires_at
+ from api_keys where id = ${keyId} and user_id = ${user.id} limit 1
+ `;
+ if (!key) return error(res, 404, 'not_found', 'API key not found');
+ if (key.revoked_at) return error(res, 400, 'revoked', 'this key is revoked');
+ if (key.expires_at && new Date(key.expires_at) < new Date())
+ return error(res, 400, 'expired', 'this key has expired');
+
+ // Dispatch with the key's real scope — tools/call gates on scope, so this is
+ // the same principal an MCP client carrying this key would present.
+ const auth = { userId: user.id, scope: key.scope || '', source: 'apikey', apiKeyId: key.id };
+
+ const init = await dispatch({ jsonrpc: '2.0', id: 1, method: 'initialize', params: INITIALIZE_PARAMS }, auth, req);
+ if (init?.error) return json(res, 200, { ok: false, error: init.error });
- const msg = { jsonrpc: '2.0', id: 1, method: 'tools/list' };
- const result = await dispatch(msg, auth, req);
+ const list = await dispatch({ jsonrpc: '2.0', id: 2, method: 'tools/list' }, auth, req);
+ if (list?.error) return json(res, 200, { ok: false, error: list.error });
- return json(res, 200, result);
+ return json(res, 200, {
+ ok: true,
+ protocolVersion: init.result?.protocolVersion ?? null,
+ serverInfo: init.result?.serverInfo ?? null,
+ tools: (list.result?.tools || []).map((t) => ({ name: t.name })),
+ scopes: (key.scope || '').split(/\s+/).filter(Boolean),
+ });
});
diff --git a/public/avatars/brainstem.glb b/public/avatars/brainstem.glb
new file mode 100644
index 000000000..88fe89569
Binary files /dev/null and b/public/avatars/brainstem.glb differ
diff --git a/public/avatars/cesium-man.glb b/public/avatars/cesium-man.glb
new file mode 100644
index 000000000..8586c4e6a
Binary files /dev/null and b/public/avatars/cesium-man.glb differ
diff --git a/public/avatars/fox.glb b/public/avatars/fox.glb
new file mode 100644
index 000000000..1ef5c0d05
Binary files /dev/null and b/public/avatars/fox.glb differ
diff --git a/public/avatars/readyplayerme.glb b/public/avatars/readyplayerme.glb
new file mode 100644
index 000000000..191f8035c
Binary files /dev/null and b/public/avatars/readyplayerme.glb differ
diff --git a/public/avatars/rigged-figure.glb b/public/avatars/rigged-figure.glb
new file mode 100644
index 000000000..c505a33df
Binary files /dev/null and b/public/avatars/rigged-figure.glb differ
diff --git a/public/avatars/xbot.glb b/public/avatars/xbot.glb
new file mode 100644
index 000000000..3805d73e7
Binary files /dev/null and b/public/avatars/xbot.glb differ
diff --git a/public/nav.html b/public/nav.html
index 05e7363ab..c8cf65c3f 100644
--- a/public/nav.html
+++ b/public/nav.html
@@ -22,6 +22,12 @@
>Guided wizard: name, 3D body, skills, personality → ship it</span
></a
>
+ <a class="nav-mi" href="/play" role="menuitem"
+ ><span class="nav-mi-t">Worlds <span class="nav-pill-sm">New</span></span
+ ><span class="nav-mi-d"
+ >Every coin is a 3D world — drop in &amp; hang out</span
+ ></a
+ >
<a class="nav-mi" href="/create" role="menuitem"
><span class="nav-mi-t">Create avatar</span
><span class="nav-mi-d">Pick or upload a 3D body</span></a
@@ -36,20 +42,18 @@
>Sculpt face + body from scratch → export GLB</span
></a
>
- <a class="nav-mi" href="/pose" role="menuitem"
- ><span class="nav-mi-t">Pose Studio</span
- ><span class="nav-mi-d">Click-to-pose mannequin + export PNG</span></a
- >
<a class="nav-mi" href="/forge" role="menuitem"
><span class="nav-mi-t"
>Text to 3D <span class="nav-pill-sm">New</span></span
><span class="nav-mi-d">Describe an object → textured GLB</span></a
>
- <a class="nav-mi" href="/play" role="menuitem"
- ><span class="nav-mi-t">Worlds <span class="nav-pill-sm">New</span></span
- ><span class="nav-mi-d"
- >Every coin is a 3D world — drop in &amp; hang out</span
- ></a
+ <a class="nav-mi" href="/voice" role="menuitem"
+ ><span class="nav-mi-t">Voice Lab <span class="nav-pill-sm">New</span></span
+ ><span class="nav-mi-d">Clone your voice · TTS playground</span></a
+ >
+ <a class="nav-mi" href="/pose" role="menuitem"
+ ><span class="nav-mi-t">Pose Studio</span
+ ><span class="nav-mi-d">Click-to-pose mannequin + export PNG</span></a
>
<a class="nav-mi" href="/app" role="menuitem"
><span class="nav-mi-t">Viewer</span
@@ -63,10 +67,6 @@
><span class="nav-mi-t">glTF Validator</span
><span class="nav-mi-d">Khronos spec check</span></a
>
- <a class="nav-mi" href="/voice" role="menuitem"
- ><span class="nav-mi-t">Voice Lab <span class="nav-pill-sm">New</span></span
- ><span class="nav-mi-d">Clone your voice · TTS playground</span></a
- >
</div>
</div>
<div class="nav-grp">
@@ -434,16 +434,17 @@
</header>
<nav class="nav-drawer" id="nav-drawer" aria-label="Mobile" aria-hidden="true">
<div class="dr-h">Build</div>
- <a href="/create">Create agent</a>
+ <a href="/create-agent">Create an agent</a>
+ <a href="/play">Worlds</a>
+ <a href="/create">Create avatar</a>
<a href="/create/selfie">Selfie to avatar</a>
<a href="/avatar-studio">Avatar Studio</a>
- <a href="/pose">Pose Studio</a>
<a href="/forge">Text to 3D</a>
- <a href="/play">Worlds</a>
+ <a href="/voice">Voice Lab</a>
+ <a href="/pose">Pose Studio</a>
<a href="/app">Viewer</a>
<a href="/playground">Playground</a>
<a href="/validation">glTF Validator</a>
- <a href="/voice">Voice Lab</a>
<div class="dr-h">Discover</div>
<a href="/what-is">What is three.ws?</a>
<a href="/features">Features</a>
diff --git a/src/dashboard-next/pages/api.js b/src/dashboard-next/pages/api.js
index 53dc1a035..50e820d06 100644
--- a/src/dashboard-next/pages/api.js
+++ b/src/dashboard-next/pages/api.js
@@ -718,15 +718,20 @@ async function runMcpTest(host, key) {
result.innerHTML = '<span class="dn-tag">Testing…</span>';
btn.disabled = true;
try {
+ // The plaintext key is hashed server-side and can't be replayed, so the
+ // test endpoint validates this key by id (ownership, revoked, expired) and
+ // runs the initialize → tools/list handshake with its real scope.
const res = await fetch('/api/developer/mcp-test', {
method: 'POST',
credentials: 'include',
- headers: { accept: 'application/json' },
+ headers: { accept: 'application/json', 'content-type': 'application/json' },
+ body: JSON.stringify({ keyId: key.id }),
});
const data = await res.json().catch(() => null);
- if (res.ok && data?.result?.tools) {
- const tools = data.result.tools;
- result.innerHTML = `<span class="dn-tag success">OK · ${tools.length} tool${tools.length === 1 ? '' : 's'}</span>`;
+ if (res.ok && data?.ok) {
+ const toolCount = data.tools?.length || 0;
+ const scopes = data.scopes?.length ? ` · ${data.scopes.join(', ')}` : '';
+ result.innerHTML = `<span class="dn-tag success">OK · ${toolCount} tool${toolCount === 1 ? '' : 's'}${esc(scopes)}</span>`;
} else {
const msg = data?.error?.message || data?.error_description || `HTTP ${res.status}`;
result.innerHTML = `<span class="dn-tag danger">Failed: ${esc(msg)}</span>`;
diff --git a/src/shared/template-picker.css b/src/shared/template-picker.css
index 69b029164..a27c35ca0 100644
--- a/src/shared/template-picker.css
+++ b/src/shared/template-picker.css
@@ -211,18 +211,6 @@
}
/* Busy state inside the modal (reserved; staging uses the full overlay) */
-.twtpl-busy {
- position: absolute;
- inset: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- gap: 12px;
- background: rgba(0, 0, 0, 0.7);
- color: var(--text, #fff);
- font-size: 14px;
-}
-
/* Staging overlay shown after a pick while the GLB downloads */
.twtpl-stage-overlay {
position: fixed;
diff --git a/src/shared/template-picker.js b/src/shared/template-picker.js
index d8ffbb994..70eb67108 100644
--- a/src/shared/template-picker.js
+++ b/src/shared/template-picker.js
@@ -119,10 +119,6 @@ export function openTemplatePicker() {
<span class="twtpl-footer-hint">Want more options?</span>
<button type="button" class="twtpl-browse" data-role="browse-gallery">Browse the full gallery →</button>
</div>
- <div class="twtpl-busy" hidden aria-live="polite">
- <span class="twtpl-spinner" aria-hidden="true"></span>
- <span class="twtpl-busy-label">Preparing your avatar…</span>
- </div>
</div>
`;
diff --git a/tests/api-developer-mcp-test.test.js b/tests/api-developer-mcp-test.test.js
new file mode 100644
index 000000000..bac38bd2e
--- /dev/null
+++ b/tests/api-developer-mcp-test.test.js
@@ -0,0 +1,192 @@
+import { describe, it, expect, vi, beforeEach } from 'vitest';
+
+// ── Mocks ─────────────────────────────────────────────────────────────────
+const sqlMock = vi.fn();
+vi.mock('../api/_lib/db.js', () => ({ sql: sqlMock }));
+
+const getSessionUserMock = vi.fn();
+vi.mock('../api/_lib/auth.js', () => ({
+ getSessionUser: (...a) => getSessionUserMock(...a),
+}));
+
+const mcpUserMock = vi.fn();
+vi.mock('../api/_lib/rate-limit.js', () => ({
+ limits: { mcpUser: (...a) => mcpUserMock(...a) },
+}));
+
+const dispatchMock = vi.fn();
+vi.mock('../api/_mcp/dispatch.js', () => ({
+ dispatch: (...a) => dispatchMock(...a),
+}));
+
+// env throws if required vars are missing — stub before the handler imports it.
+vi.mock('../api/_lib/env.js', () => ({
+ env: { APP_ORIGIN: 'http://localhost:3000', ISSUER: 'http://test', MCP_RESOURCE: 'http://test' },
+}));
+
+const { default: handler } = await import('../api/developer/mcp-test.js');
+
+// ── Test helpers ──────────────────────────────────────────────────────────
+
+function mkReq({ method = 'POST', url = '/api/developer/mcp-test', headers = {}, body = null } = {}) {
+ return {
+ method,
+ url,
+ headers: { 'content-type': 'application/json', ...headers },
+ on(event, cb) {
+ if (event === 'data' && body != null) {
+ const buf = Buffer.from(typeof body === 'string' ? body : JSON.stringify(body));
+ queueMicrotask(() => { cb(buf); this._endCb?.(); });
+ } else if (event === 'end') {
+ this._endCb = cb;
+ if (body == null) queueMicrotask(() => cb());
+ }
+ },
+ destroy() {},
+ };
+}
+
+function mkRes() {
+ return {
+ statusCode: 200,
+ headers: {},
+ body: undefined,
+ writableEnded: false,
+ setHeader(k, v) { this.headers[k.toLowerCase()] = v; },
+ getHeader(k) { return this.headers[k.toLowerCase()]; },
+ end(body) { this.body = body; this.writableEnded = true; },
+ };
+}
+
+const parseBody = (res) => (res.body ? JSON.parse(res.body) : undefined);
+
+beforeEach(() => {
+ sqlMock.mockReset();
+ getSessionUserMock.mockReset().mockResolvedValue({ id: 'user-1' });
+ mcpUserMock.mockReset().mockResolvedValue({ success: true, limit: 1200, remaining: 1199, reset: Date.now() + 60_000 });
+ dispatchMock.mockReset();
+});
+
+const okKey = { id: 'key-1', scope: 'avatars:read profile', revoked_at: null, expires_at: null };
+
+function dispatchHappyPath() {
+ dispatchMock.mockImplementation((msg) => {
+ if (msg.method === 'initialize')
+ return Promise.resolve({ jsonrpc: '2.0', id: msg.id, result: { protocolVersion: '2025-06-18', serverInfo: { name: '3d-agent-mcp' } } });
+ if (msg.method === 'tools/list')
+ return Promise.resolve({ jsonrpc: '2.0', id: msg.id, result: { tools: [{ name: 'render_avatar' }, { name: 'list_my_avatars' }] } });
+ return Promise.resolve(null);
+ });
+}
+
+// ── Auth & method ───────────────────────────────────────────────────────────
+
+describe('mcp-test auth & method', () => {
+ it('rejects non-POST with 405', async () => {
+ const res = mkRes();
+ await handler(mkReq({ method: 'GET' }), res);
+ expect(res.statusCode).toBe(405);
+ });
+
+ it('returns 401 without a session', async () => {
+ getSessionUserMock.mockResolvedValue(null);
+ const res = mkRes();
+ await handler(mkReq({ body: { keyId: 'key-1' } }), res);
+ expect(res.statusCode).toBe(401);
+ });
+
+ it('returns 429 when the user is rate limited', async () => {
+ mcpUserMock.mockResolvedValue({ success: false, limit: 1200, remaining: 0, reset: Date.now() + 60_000 });
+ const res = mkRes();
+ await handler(mkReq({ body: { keyId: 'key-1' } }), res);
+ expect(res.statusCode).toBe(429);
+ });
+});
+
+// ── Key validation ──────────────────────────────────────────────────────────
+
+describe('mcp-test key validation', () => {
+ it('returns 400 when keyId is missing', async () => {
+ const res = mkRes();
+ await handler(mkReq({ body: {} }), res);
+ expect(res.statusCode).toBe(400);
+ expect(parseBody(res).error).toBe('bad_request');
+ });
+
+ it('returns 404 when the key is not owned by the caller', async () => {
+ sqlMock.mockResolvedValue([]); // no row
+ const res = mkRes();
+ await handler(mkReq({ body: { keyId: 'nope' } }), res);
+ expect(res.statusCode).toBe(404);
+ expect(dispatchMock).not.toHaveBeenCalled();
+ });
+
+ it('returns 400 for a revoked key', async () => {
+ sqlMock.mockResolvedValue([{ ...okKey, revoked_at: new Date().toISOString() }]);
+ const res = mkRes();
+ await handler(mkReq({ body: { keyId: 'key-1' } }), res);
+ expect(res.statusCode).toBe(400);
+ expect(parseBody(res).error).toBe('revoked');
+ expect(dispatchMock).not.toHaveBeenCalled();
+ });
+
+ it('returns 400 for an expired key', async () => {
+ sqlMock.mockResolvedValue([{ ...okKey, expires_at: new Date(Date.now() - 1000).toISOString() }]);
+ const res = mkRes();
+ await handler(mkReq({ body: { keyId: 'key-1' } }), res);
+ expect(res.statusCode).toBe(400);
+ expect(parseBody(res).error).toBe('expired');
+ expect(dispatchMock).not.toHaveBeenCalled();
+ });
+});
+
+// ── Handshake ───────────────────────────────────────────────────────────────
+
+describe('mcp-test handshake', () => {
+ it('runs initialize → tools/list and returns tools + scopes', async () => {
+ sqlMock.mockResolvedValue([okKey]);
+ dispatchHappyPath();
+ const res = mkRes();
+ await handler(mkReq({ body: { keyId: 'key-1' } }), res);
+
+ expect(res.statusCode).toBe(200);
+ const body = parseBody(res);
+ expect(body.ok).toBe(true);
+ expect(body.protocolVersion).toBe('2025-06-18');
+ expect(body.tools).toEqual([{ name: 'render_avatar' }, { name: 'list_my_avatars' }]);
+ expect(body.scopes).toEqual(['avatars:read', 'profile']);
+
+ // dispatch ran with the key's real scope, not a hardcoded all-scopes string.
+ expect(dispatchMock).toHaveBeenCalledTimes(2);
+ const [, auth] = dispatchMock.mock.calls[0];
+ expect(auth).toMatchObject({ userId: 'user-1', scope: 'avatars:read profile', source: 'apikey' });
+ });
+
+ it('surfaces a dispatch error as ok:false without throwing', async () => {
+ sqlMock.mockResolvedValue([okKey]);
+ dispatchMock.mockImplementation((msg) =>
+ Promise.resolve(
+ msg.method === 'initialize'
+ ? { jsonrpc: '2.0', id: msg.id, error: { code: -32603, message: 'boom' } }
+ : null,
+ ),
+ );
+ const res = mkRes();
+ await handler(mkReq({ body: { keyId: 'key-1' } }), res);
+
+ expect(res.statusCode).toBe(200);
+ const body = parseBody(res);
+ expect(body.ok).toBe(false);
+ expect(body.error.message).toBe('boom');
+ // tools/list is not attempted once initialize fails.
+ expect(dispatchMock).toHaveBeenCalledTimes(1);
+ });
+
+ it('reports an empty scopes array for a no-scope key', async () => {
+ sqlMock.mockResolvedValue([{ ...okKey, scope: '' }]);
+ dispatchHappyPath();
+ const res = mkRes();
+ await handler(mkReq({ body: { keyId: 'key-1' } }), res);
+ expect(parseBody(res).scopes).toEqual([]);
+ });
+});