Ship a view

Bundle an MCP App as one HTML resource, declare its origins, and verify what Claude loads.

1.Start with a working view

Copy the starter. It serves one read-only tool, uses the React protocol hooks, and previews the same view with the Storybook fake host.

npx degit contursofran/mcpblocks/examples/starter my-mcp-app
cd my-mcp-app
npm install
npm run setup:blocks
npm run build
npm start

Use Node 20.19+ or 22.12+. Run npm run storybook to check the view before connecting Claude.

2.Serve one HTML file

The starter uses Vite and vite-plugin-singlefile to put the CSS and JavaScript into dist/view.html. Return the HTML in resources/read with MIME type text/html;profile=mcp-app. Check the built file when adding fonts, media or code splitting.

const html = await readFile("dist/view.html", "utf8")
const revision = createHash("sha256").update(html).digest("hex").slice(0, 12)
const uri = `ui://my-app/view-${revision}.html`

registerAppResource(server, "My view", uri, { mimeType: RESOURCE_MIME_TYPE }, async () => ({
  contents: [{ uri, mimeType: RESOURCE_MIME_TYPE, text: html }],
}))

// The tool's metadata points to the same uri.
// _meta: { ui: { resourceUri: uri } }

Hash the final HTML bytes. Build first, then restart the server so the URI and bytes change together.

3.Declare the origins the view uses

Add resourceDomains for external images, fonts, styles and scripts. Add connectDomains for browser requests such as fetch. Put csp on the resource content in resources/read.

_meta: {
  ui: {
    csp: {
      resourceDomains: ["https://assets.claude.ai"],
      connectDomains: ["https://api.example.com"],
    },
  },
}

Host font CSS in styles.css.fonts can point to an external origin. Include the actual font origin if you rely on that font, and keep a system fallback for views where it fails to load. Claude serves its host fonts from https://assets.claude.ai. Tool calls made through app.callServerTool use the host bridge. See the Claude font and CSP documentation.

4.Measure the bundle

The starter logs the raw and gzip sizes during npm run build. Its default budget is 225 KiB gzip. Set MCP_VIEW_GZIP_BUDGET in bytes to fit your view. Check the gzip size as you add dependencies and test time to first render in the host.

5.Verify the deployed view in Claude

With cloudflared installed, run npm run tunnel while the starter is running. Add the tunnel HTTPS URL plus /mcp as a custom connector with No sign in. The starter serves public sample data. Ask Claude to run show_record and verify that the card renders.

When tool definitions or resource URIs change, open the connector menu under Your plugins and select Refresh tools list. Use a fresh chat for the check because a chat can retain the previous tool catalog or cached HTML.

See the MCP server guide for tool registration and the protocol hooks guide for view state.