Restore educational comments in basic-server-* examples
PR #184 accidentally removed/reverted educational comments from `basic-server-react` and `basic-server-vanillajs` that were established in PR #182. This restores consistency with the other basic-server examples (Vue, Svelte, Preact, Solid). Changes: - Add back the three-comment pattern explaining two-part registration - Restore full tool description ("as an ISO 8601 string") - Change vanillajs to return plain text instead of JSON (matching #182) - Use local `resourceUri` variable instead of top-level constant Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
b273279849
commit
8b8ecbea64
1 changed files with 19 additions and 13 deletions
|
|
@ -17,21 +17,27 @@ export function createServer(): McpServer {
|
|||
version: "1.0.0",
|
||||
});
|
||||
|
||||
// Two-part registration: tool + resource, tied together by the resource URI.
|
||||
const resourceUri = "ui://get-time/mcp-app.html";
|
||||
|
||||
// Register a tool with UI metadata. When the host calls this tool, it reads
|
||||
// `_meta[RESOURCE_URI_META_KEY]` to know which resource to fetch and render
|
||||
// as an interactive UI.
|
||||
registerAppTool(server,
|
||||
"get-time",
|
||||
{
|
||||
title: "Get Time",
|
||||
description: "Returns the current server time.",
|
||||
description: "Returns the current server time as an ISO 8601 string.",
|
||||
inputSchema: {},
|
||||
_meta: { [RESOURCE_URI_META_KEY]: resourceUri },
|
||||
},
|
||||
async (): Promise<CallToolResult> => {
|
||||
return { content: [{ type: "text", text: new Date().toISOString() }] };
|
||||
const time = new Date().toISOString();
|
||||
return { content: [{ type: "text", text: time }] };
|
||||
},
|
||||
);
|
||||
|
||||
// Register the resource, which returns the bundled HTML/JavaScript for the UI.
|
||||
registerAppResource(server,
|
||||
resourceUri,
|
||||
resourceUri,
|
||||
|
|
|
|||
Loading…
Reference in a new issue