The MCP server instance
Human-readable resource name
Resource URI (should match the _meta.ui field in tool config)
Resource configuration
Callback that returns the resource contents
registerAppResource(
server,
"Weather View",
"ui://weather/view.html",
{
description: "Interactive weather display",
},
async () => ({
contents: [
{
uri: "ui://weather/view.html",
mimeType: RESOURCE_MIME_TYPE,
text: await fs.readFile("dist/view.html", "utf-8"),
},
],
}),
);
registerAppResource(
server,
"Music Player",
"ui://music/player.html",
{
description: "Audio player with external soundfonts",
},
async () => ({
contents: [
{
uri: "ui://music/player.html",
mimeType: RESOURCE_MIME_TYPE,
text: musicPlayerHtml,
_meta: {
ui: {
csp: {
resourceDomains: ["https://cdn.example.com"], // For scripts/styles/images
connectDomains: ["https://api.example.com"], // For fetch/WebSocket
},
},
},
},
],
}),
);
registerAppTool to register tools that reference this resource
Register an app resource with the MCP server.
This is a convenience wrapper around
server.registerResourcethat:RESOURCE_MIME_TYPE("text/html;profile=mcp-app")