@@ -6,7 +6,6 @@ import { registerAppTool, registerAppResource, RESOURCE_MIME_TYPE, RESOURCE_URI_
66import { startServer } from "./src/server-utils.js" ;
77
88const DIST_DIR = path . join ( import . meta. dirname , "dist" ) ;
9- const RESOURCE_URI = "ui://get-time/mcp-app.html" ;
109
1110/**
1211 * Creates a new MCP server instance with tools and resources registered.
@@ -17,37 +16,37 @@ function createServer(): McpServer {
1716 version : "1.0.0" ,
1817 } ) ;
1918
20- // MCP Apps require two-part registration: a tool (what the LLM calls) and a
21- // resource (the UI it renders). The `_meta` field on the tool links to the
22- // resource URI, telling hosts which UI to display when the tool executes.
19+ // Two-part registration: tool + resource, tied together by the resource URI.
20+ const resourceUri = "ui://get-time/mcp-app.html" ;
21+
22+ // Register a tool with UI metadata. When the host calls this tool, it reads
23+ // `_meta[RESOURCE_URI_META_KEY]` to know which resource to fetch and render
24+ // as an interactive UI.
2325 registerAppTool ( server ,
2426 "get-time" ,
2527 {
2628 title : "Get Time" ,
2729 description : "Returns the current server time as an ISO 8601 string." ,
2830 inputSchema : { } ,
29- _meta : { [ RESOURCE_URI_META_KEY ] : RESOURCE_URI } ,
31+ _meta : { [ RESOURCE_URI_META_KEY ] : resourceUri } ,
3032 } ,
3133 async ( ) : Promise < CallToolResult > => {
3234 const time = new Date ( ) . toISOString ( ) ;
33- return {
34- content : [ { type : "text" , text : JSON . stringify ( { time } ) } ] ,
35- } ;
35+ return { content : [ { type : "text" , text : time } ] } ;
3636 } ,
3737 ) ;
3838
39+ // Register the resource, which returns the bundled HTML/JavaScript for the UI.
3940 registerAppResource ( server ,
40- RESOURCE_URI ,
41- RESOURCE_URI ,
41+ resourceUri ,
42+ resourceUri ,
4243 { mimeType : RESOURCE_MIME_TYPE } ,
4344 async ( ) : Promise < ReadResourceResult > => {
4445 const html = await fs . readFile ( path . join ( DIST_DIR , "mcp-app.html" ) , "utf-8" ) ;
4546
4647 return {
4748 contents : [
48- // Per the MCP App specification, "text/html;profile=mcp-app" signals
49- // to the Host that this resource is indeed for an MCP App UI.
50- { uri : RESOURCE_URI , mimeType : RESOURCE_MIME_TYPE , text : html } ,
49+ { uri : resourceUri , mimeType : RESOURCE_MIME_TYPE , text : html } ,
5150 ] ,
5251 } ;
5352 } ,
0 commit comments