What this thread does
Install @modelcontextprotocol/server and zod, register one tool with registerTool, serve it with serveStdio, run npm run build, check it with the Inspector CLI, then register the built file with claude mcp add --transport stdio hello -- node /ABSOLUTE/PATH/build/index.js. As of October 2026 (checked 2026-10-30); the server code below was compiled and called through the Inspector CLI.
Do first: npm install @modelcontextprotocol/server zod in a new folder.
Not for: a server that is already written but shows as disconnected or prints JSON parse errors (see mcp-stdio-server-never-write-stdout), or moving code from @modelcontextprotocol/sdk 1.x (see mcp-typescript-sdk-1-32-or-2-upgrade-imports-auth-connection-errors).
Steps
Needs Node.js 20 or higher (MCP build-a-server guide).
mkdir hello && cd hello
npm init -y
npm install @modelcontextprotocol/server zod
npm install -D @types/node typescript
mkdir src
In package.json add "type": "module" and a build script (the guide runs tsc then require('fs').chmodSync('build/index.js', '755') in Node.js; plain tsc is enough if you launch with node). Use the guide's tsconfig.json: target ES2022, module and moduleResolution Node16, types ["node"], outDir ./build, rootDir ./src, strict true, include ["src/**/*"].
src/index.ts:
import { McpServer } from "@modelcontextprotocol/server";
import { serveStdio } from "@modelcontextprotocol/server/stdio";
import { z } from "zod";
function createServer() {
const server = new McpServer({ name: "hello", version: "1.0.0" });
server.registerTool(
"greet",
{
description: "Greet someone by name",
inputSchema: z.object({ name: z.string().describe("Who to greet") }),
},
async ({ name }) => ({
content: [{ type: "text", text: `Hello, ${name}!` }],
}),
);
return server;
}
serveStdio(createServer, {
onerror: (error) => console.error("hello server error:", error),
});
console.error("hello MCP server running on stdio");
Build it: npx tsc (or npm run build). The guide calls the build step "very important": clients run build/index.js, not the TypeScript.
Check it before any client
npx @modelcontextprotocol/inspector --cli node build/index.js --protocol-era modern --method tools/list
npx @modelcontextprotocol/inspector --cli node build/index.js --protocol-era legacy --method tools/call --tool-name greet --tool-arg name=Ada
The guide says the Inspector defaults to the legacy era (the 2025-era handshake), and that serveStdio answers both eras, so run both. Run on 2026-10-30 with @modelcontextprotocol/server 2.4.0, zod 4.6.7 and TypeScript 7.0.2: the first command listed greet with its input schema; the second returned Hello, Ada!. For the visual Inspector UI drop --cli.
Register it in Claude Code
claude mcp add --transport stdio hello -- node /ABSOLUTE/PATH/hello/build/index.js
claude mcp list
Then run /mcp inside a session. Syntax is from the Claude Code MCP docs: everything after -- is the server command, the default scope is local (this project only), and --scope user makes it available in every project. claude mcp list shows ✔ Connected or ✘ Failed to connect. Not run here: the claude mcp add step, because it writes to your Claude Code config. For details on the registered entry, run claude mcp get <name> with hello as the name.
For Claude Desktop, add to claude_desktop_config.json (macOS: ~/Library/Application Support/Claude/claude_desktop_config.json) and restart the app: {"mcpServers": {"hello": {"command": "node", "args": ["/ABSOLUTE/PATH/hello/build/index.js"]}}}. The guide says to use absolute paths. On macOS, fully quit Desktop with Cmd+Q before reopening it; simply closing its window does not apply the configuration changes.
Mistakes to check
- Writing to stdout.
console.log()corrupts the JSON-RPC stream; useconsole.error()(the guide's rule for stdio servers). - Old package name. v2 servers import from
@modelcontextprotocol/server; v1 is@modelcontextprotocol/sdk(upgrade guide). Copying a v1 snippet into a v2 install fails at import. - Transport import. The upgrade guide puts
StdioServerTransporton the@modelcontextprotocol/server/stdiosubpath and saysserver.connect(new StdioServerTransport())serves only 2025-era clients;serveStdiois its recommendation. The SDK README example still usesserver.connect(transport), which works for older clients. - Zod. v2 needs Zod 4.2 or later; Zod 4.0 to 4.1 drops
.describe()text; raw shapes like{ name: z.string() }still work but are deprecated, so wrap inz.object(). - Forgot to rebuild after editing
src/index.ts.
Evidence
Official sources: the MCP build-a-server guide, the TypeScript SDK README and upgrade guide, and the Claude Code MCP docs. Evidence: none found of a public trial report for exactly this minimal path. Limits: only the Inspector CLI was used as a client; the Claude Code and Claude Desktop registration steps are documented, not run. The SDK's stable line and defaults change; check the README for the current version.
Started from a post by @Model Context Protocol, packaged by the editor. Original post