mcpb/examples/hello-world-node/server/index.js
Bryan Thompson a5d9ae8ed2
fix: repair broken examples and graduate UV runtime from experimental
- hello-world-node: wrap server startup in async main() with proper
  await on server.connect(transport) — fixes crash on initialize in
  Claude Desktop UtilityProcess runtime (closes #200)
- hello-world-uv: add required mcp_config block — v0.4 schema requires
  it but the example omitted it, causing mcpb pack to fail
- file-manager-python: convert from broken v0.1/python to v0.4/uv —
  the old manifest had privacy_policies on v0.1 (schema violation),
  used command "python" (ENOENT on macOS), and had no bundled deps.
  Now uses UV runtime with proper mcp_config (closes #47, closes #72)
- Graduate UV runtime from experimental across docs and schema comments
- Bump DEFAULT_MANIFEST_VERSION from 0.2 to 0.3

All three examples verified: pack succeeds, server responds to MCP
initialize over stdio, tools/list returns expected tools.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-12 11:16:30 -05:00

76 lines
1.6 KiB
JavaScript

#!/usr/bin/env node
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import {
CallToolRequestSchema,
ListToolsRequestSchema,
} from "@modelcontextprotocol/sdk/types.js";
const server = new Server(
{
name: "hello-world-node",
version: "1.0.0",
},
{
capabilities: {
tools: {},
},
},
);
// Handle tool listing
server.setRequestHandler(ListToolsRequestSchema, async (request) => {
return {
tools: [
{
name: "get_current_time",
description: "Get the current computer time",
inputSchema: {
type: "object",
properties: {},
},
},
],
};
});
// Handle tool execution
server.setRequestHandler(CallToolRequestSchema, async (request) => {
if (request.params.name === "get_current_time") {
const now = new Date();
const timeString = now.toLocaleString("en-US", {
weekday: "long",
year: "numeric",
month: "long",
day: "numeric",
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
timeZoneName: "short",
});
return {
content: [
{
type: "text",
text: `The current time is: ${timeString}`,
},
],
};
}
throw new Error(`Unknown tool: ${request.params.name}`);
});
// Start the server
async function main() {
const transport = new StdioServerTransport();
await server.connect(transport);
console.error("Hello World MCP server running...");
}
main().catch((error) => {
console.error("Fatal error in main():", error);
process.exit(1);
});