The complete file
The whole server is one small program.
import { McpServer } from "@modelcontextprotocol/server";
import { StdioServerTransport } from "@modelcontextprotocol/server/stdio";
import { z } from "zod";
const server = new McpServer({
name: "clock",
version: "1.0.0",
});
server.registerTool(
"get_current_time",
{
description: "Return the current time in UTC",
inputSchema: z.object({}),
},
async () => ({
content: [{ type: "text", text: new Date().toISOString() }],
}),
);
const transport = new StdioServerTransport();
await server.connect(transport);
The imports provide the protocol machinery. The middle describes and performs the capability. The final two lines open the local connection.