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.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
fix(mcp-studio): fetch the widget's model through the CORS-open glb proxy
nirholas7001b266bb97
diff --git a/api/_mcp-studio/component.js b/api/_mcp-studio/component.jsindex 5f1c7d2c4..0df5decbe 100644--- a/api/_mcp-studio/component.js+++ b/api/_mcp-studio/component.js@@ -193,13 +193,28 @@ export const COMPONENT_HTML = `<!doctype html>function isHttps(u) { return typeof u === 'string' && /^https:\\/\\//.test(u); }+ // model-viewer FETCHES the GLB (XHR), so the bytes have to arrive from an+ // origin that answers with access-control-allow-origin. Generated models sit+ // on the public asset bucket, which sends no CORS header at all and refuses+ // the preflight, so a direct src dies as "Failed to fetch" inside ChatGPT's+ // cross-origin widget sandbox and error-states every generation. /api/glb+ // re-serves the same public object from three.ws with open CORS, which is the+ // same proxy the site's own viewers use. Links (open, download, AR) keep the+ // raw URL: those are navigations, and CORS does not apply to them.+ function fetchable(glb) {+ if (!isHttps(glb)) return glb;+ try { if (new URL(glb).hostname === 'three.ws') return glb; } catch (e) { return glb; }+ return 'https://three.ws/api/glb?src=' + encodeURIComponent(glb);+ }+// Swap the displayed GLB with a cross-fade (no hard pop). Used both for the// initial refined result and for clicking an earlier version in the strip.function swapTo(glb) {- if (!isHttps(glb) || mv.getAttribute('src') === glb) return;+ var next = fetchable(glb);+ if (!isHttps(glb) || mv.getAttribute('src') === next) return;swapping = true;mv.classList.add('fading');- setTimeout(function () { mv.setAttribute('src', glb); armWatchdog(); }, 200);+ setTimeout(function () { mv.setAttribute('src', next); armWatchdog(); }, 200);}// Build the version strip from a lineage. Each chip swaps its GLB in on click;@@ -269,7 +284,7 @@ export const COMPONENT_HTML = `<!doctype html>// instant the widget renders, while the GLB is still streaming in.if (isHttps(out.referenceImageUrl)) { mv.setAttribute('poster', out.referenceImageUrl); }else { mv.removeAttribute('poster'); }- mv.setAttribute('src', glb);+ mv.setAttribute('src', fetchable(glb));armWatchdog();var kind = (out.kind || 'model').replace(/_/g, ' ');diff --git a/tests/mcp-studio.test.js b/tests/mcp-studio.test.jsindex 2cc6375bd..38c049161 100644--- a/tests/mcp-studio.test.js+++ b/tests/mcp-studio.test.js@@ -241,6 +241,42 @@ describe('mcp-studio dispatch', () => {expect(COMPONENT_HTML).toContain('poster');});+ it('routes the widget model fetch through /api/glb so it survives the ChatGPT sandbox origin', async () => {+ // model-viewer FETCHES the GLB, so the bytes need an+ // access-control-allow-origin the widget's origin is covered by. The+ // public asset bucket's CORS policy is an origin allowlist naming+ // https://three.ws, so a raw bucket URL loads on our own pages and+ // dies as "Failed to fetch" inside ChatGPT's cross-origin widget+ // sandbox, error-stating every single generation. /api/glb re-serves+ // the same public object with open CORS. Measured against the live+ // bucket 2026-09-09: Origin https://three.ws gets the header back,+ // ChatGPT's sandbox origin gets none.+ const { COMPONENT_HTML } = await import('../api/_mcp-studio/component.js');+ const src = COMPONENT_HTML.match(/function fetchable\(glb\) \{[\s\S]*?\n \}/);+ const guard = COMPONENT_HTML.match(/function isHttps\(u\) \{[^\n]*\}/);+ expect(src, 'the widget must define a fetchable() indirection').not.toBeNull();+ expect(guard, 'fetchable() leans on the widget isHttps() guard').not.toBeNull();+ // eslint-disable-next-line no-new-func -- exercising the shipped widget source, not a copy of it+ const fetchable = new Function(`${guard[0]}; ${src[0]}; return fetchable;`)();++ const bucket = 'https://pub-2534e921bf9c4314addcd4d8a6e98b7b.r2.dev/forge/anon/x.glb';+ expect(fetchable(bucket)).toBe(`https://three.ws/api/glb?src=${encodeURIComponent(bucket)}`);+ // Already on an origin that answers with CORS: no pointless extra hop.+ expect(fetchable('https://three.ws/avatars/cesium-man.glb')).toBe('https://three.ws/avatars/cesium-man.glb');+ // Non-https and junk are handed back untouched for the caller's own guard.+ expect(fetchable('not a url')).toBe('not a url');++ // Every model-viewer source assignment has to go through it, or one+ // code path silently reintroduces the raw cross-origin URL.+ const assignments = COMPONENT_HTML.match(/mv\.setAttribute\('src',[^)]*\)/g) || [];+ expect(assignments.length).toBeGreaterThan(0);+ for (const a of assignments) expect(a).toMatch(/fetchable\(|next/);++ // The links stay on the raw URL: those are navigations, and a download+ // through the proxy would hand the user a file named after the proxy.+ expect(COMPONENT_HTML).toContain('downloadEl.href = glb;');+ });+it('avatar results carry the IRL living-agent handoff; props stay static (AR bridges agents into the real world)', async () => {globalThis.fetch = vi.fn(async () => ({ok: true,