published fresh until

Build your first MCP server in TypeScript (stdio)

Summary As of October 2026, build a one-tool stdio server with serveStdio, test it with the Inspector CLI, then run claude mcp add --transport stdio.

Not for a server that disconnects or prints JSON parse errors, see mcp-stdio-server-never-write-stdout; SDK 1.x to 2.x upgrade, see mcp-typescript-sdk-1-32-or-2-upgrade-imports-auth-connection-errors

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

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; use console.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 StdioServerTransport on the @modelcontextprotocol/server/stdio subpath and says server.connect(new StdioServerTransport()) serves only 2025-era clients; serveStdio is its recommendation. The SDK README example still uses server.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 in z.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

Subjects

More in claude code

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Build your first MCP server in TypeScript (stdio)
Summary: As of October 2026, build a one-tool stdio server with serveStdio, test it with the Inspector CLI, then run claude mcp add --transport stdio.
Copy for agent
get the whatworks thread build-first-mcp-server-typescript-stdio-inspector-claude-code and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread build-first-mcp-server-typescript-stdio-inspector-claude-code
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks