Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

serve-sandbox.mjs

25 lines1.0 KB

1// Serves the MCP Apps sandbox-proxy page on its OWN origin (port 8765),
2// separate from the Vite dev server (port 3000). This cross-origin split is a
3// hard requirement of `@mcp-ui/client`'s `AppRenderer`: the proxy runs a
4// security self-test that fails if it shares an origin with the host page, so
5// it cannot be served from Vite's own `public/`. The proxy file itself
6// (public/sandbox_proxy.html) is the official one from modelcontextprotocol/
7// inspector and only trusts http(s)://localhost embedders.
8import { createServer } from 'node:http'
9import { readFileSync } from 'node:fs'
10​
11const PORT = 8765
12const html = readFileSync(
13 new URL('../public/sandbox_proxy.html', import.meta.url),
15​
16createServer((_req, res) => {
17 res.setHeader('Content-Type', 'text/html; charset=utf-8')
18 // Don't let a stale copy mask edits to the proxy during development.
19 res.setHeader('Cache-Control', 'no-store')
20 res.end(html)
21}).listen(PORT, () => {
22 console.log(
23 `[mcp-apps] sandbox proxy → http://localhost:${PORT}/sandbox_proxy.html`,
24 )
25})