Developer ToolsCluster Spoke2026-11-24

How to Build an MCP Server in TypeScript and Python

How to Build an MCP Server in TypeScript and Python

Executive TL;DR

Building an audited custom MCP server requires under 80 lines using @modelcontextprotocol/sdk with Zod schemas or Python FastMCP. Keep stdout exclusively reserved for JSON-RPC frames, validate inputs strictly, and test contracts via MCP Inspector before team rollout.

Production Case Study: Building an Internal MCP Adapter

Whenever public community registries omit proprietary internal endpoints or domain calculators, shipping a focused in-house MCP server gives engineers clean leverage in under an hour. Our walkthrough distills lessons from packaging domain integrations alongside Korean Law MCP and MCP for Unity.

SDK Stack Comparison

SDK Choice
SDK ChoiceValidation LibraryBest Fit Scenario
@modelcontextprotocol/sdk NodeZod inputSchemaNext.js monorepos, REST wrappers, Vercel deployments
Python FastMCPPydantic type hintsData pipelines, ML scripts, local Unity WebSocket hubs

Minimal TypeScript stdio Server Blueprint

Using TypeScript ensures end-to-end schema typing between JSON arguments validated by Zod and backend calls:

typescript
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";

const server = new McpServer({
  name: "internal-release-notes",
  version: "1.0.0",
});

server.registerTool(
  "get_deploy_status",
  {
    description: "Fetch current release build tag by environment",
    inputSchema: { env: z.enum(["staging", "production"]) },
  },
  async ({ env }) => ({
    content: [{ type: "text", text: "Deploy active for " + env }],
  })
);

const transport = new StdioServerTransport();
await server.connect(transport);

Three Pitfalls We Caught During Testing

  1. Polluting stdout with console.log: In stdio transport, standard output carries raw JSON-RPC frames exclusively. A single stray log statement breaks Claude or Cursor initialization instantly. Always emit diagnostics to console.error so logs land cleanly on stderr.
  2. Oversized Raw Payload Dumps: Returning raw 50KB REST JSON blobs floods context windows and triggers truncation. Trim responses strictly to identifiers, timestamps, and actionable status codes—mirroring strategies covered in our Token Bloat Reduction Guide.
  3. Missing Actionable Error Hints: Return clear recovery guidance inside isError responses so autonomous loops self-correct parameter typos immediately instead of guessing blindly.

Verify every new custom server interactively with npx @modelcontextprotocol/inspector before adding it to your Claude MCP Setup or registering it for review inside MCP Atlas.

Structured Technical FAQ

Why does stdout printing break stdio MCP servers?

MCP stdio transport exchanges newline-delimited JSON-RPC messages on standard output. Any non-JSON text printed via console.log or print corrupts the protocol stream, so always log to stderr.

How do I test a new MCP server before linking Claude or Cursor?

Launch npx @modelcontextprotocol/inspector against your compiled entrypoint to test tool discovery, argument validation, and response payloads visually inside a local browser.

Should I write a custom server in Node.js or Python?

Use TypeScript with Zod if your codebase runs on JavaScript infrastructure or needs easy npx distribution; choose Python FastMCP when wrapping ML libraries or local desktop Python bridges.

Referenced MCP Servers

Database MCP
Core Ecosystem

PostgreSQL Read-Only MCP

Inspect relational schemas and run safe EXPLAIN plans without mutation risk

stdioenv-connection-stringopen-source
Tool Surface5 tools
Reliability Score96 / 100
1120 tok · 14,200 starsInspect config
Search & Web
Long-Tail Niche

Korean Law MCP

Query verified South Korean statutes, court precedents, constitutional rulings, and municipal ordinances via Open API

stdioapi-keyopen-source
Tool Surface16 tools
Reliability Score93 / 100
2480 tok · 1,450 starsInspect config
Developer Tools
Rising Stack

MCP for Unity

Three-tier Unity Editor bridge to build scenes, inspect hierarchy objects, run tests, and edit C# scripts via AI

stdiostreamable-httpnoneopen-source
Tool Surface34 tools
Reliability Score92 / 100
3980 tok · 5,200 starsInspect config
Developer Tools
Rising Stack

Repomix Codebase Packager MCP

Token-counted repository bundler and grep-free structural context engine

stdiononeopen-source
Tool Surface6 tools
Reliability Score94 / 100
1180 tok · 16,400 starsInspect config

Related Hub & Spoke Guides