Lesson 11 · Slide 1
Lesson 11 — Why TypeScript for Production MCP
We learned MCP in Python. We ship it in TypeScript. Here is why — and where Python still wins.
MCP Servers
Module 5
Lesson 11 · Slide 2
The Module-5 pivot
Where we are
Modules 1–4 built a 7-tool PKB in Python. It tests, it logs, it handles auth — but it ships as a single-tenant stdio process on your laptop.
This module
Module 5 productionizes the same shape in TypeScript: HTTP+SSE transport, Docker, multi-tenant isolation, hardening.
"Same protocol. Different deployment substrate."
Lesson 11 · Slide 3
The 2026 MCP ecosystem reality
- Most public/remote MCP servers in 2026 are written in TypeScript or Node-flavoured runtimes (Cloudflare Workers, Vercel Functions, Deno Deploy).
- The TS SDK ships first, gets transport features first, and has the largest example corpus.
- Python remains dominant for local and AI-research servers.
- Pick TS for "I want users to connect over the internet"; Python for "I am the only user, this runs on my laptop".
Lesson 11 · Slide 4
Perf and deploy ergonomics
TS on Node 20+ has stable async I/O, a sub-200 ms cold start in a container, and a 50–80 MB base image with node:20-alpine. Python equivalents are 200–500 MB unless you Distroless+slim, and cold-start under gunicorn/uvicorn is heavier. For burst HTTP traffic with many short-lived MCP sessions, that matters.
Headline: TS Docker image: ~80 MB, ~150 ms cold. Python equivalent: ~250 MB, ~800 ms. (Orders of magnitude, not benchmarks.)
Lesson 11 · Slide 5
The TS SDK feature lead
- HTTP+SSE transport in the TS SDK shipped 2 quarters earlier than the Python equivalent.
- The official auth helper exists in TS first.
- The resumable-session pattern was prototyped in TS.
- For production HTTP MCP in 2026, the TS SDK is the path of least resistance.
Lesson 11 · Slide 6
When to stay in Python
Stay in Python when:
- The server is personal (one user, your laptop).
- The tools wrap scientific Python (NumPy, PyTorch, transformers) and porting them would mean re-implementing math.
- The server is a prototype you want to throw away in a week.
- Your audit / compliance shop only signs off on Python.
Don't rewrite a working personal Python server just because this lesson exists.
Lesson 11 · Slide 7
What we'll carry over from Python
- Tool name → schema → handler shape.
- Structured-log decorator (now a
pino child logger pattern).
- Per-user isolation (now bearer-token middleware).
- Sampling pattern.
mcp dev Inspector workflow (works against any transport).
Lesson 11 · Slide 8
What we'll add in TS-land
- Zod for runtime schema validation (no Pydantic in TS).
tsx/tsc build pipeline.
- ESM-only module setup.
npm/pnpm workflow.
- Docker as the deploy unit.
- Caddy for TLS.
- Bearer-token auth middleware.
pino for structured JSON logs (one logger pattern, not per-module).
Lesson 11 · Slide 9
A pre-requisite check
Lesson 11 assumes:
- You can read TypeScript (
async, interface, import).
- You know what a
package.json is.
- You've run
npm install at least once.
- You have Node 20+ and Docker installed locally.
If any of those is "no" — pause the course, run through 30 minutes of the Node.js docs, then come back. The TS lessons do not re-teach Node.
Lesson 11 · Slide 10
Project layout we're heading toward
sample-server/typescript/
package.json
tsconfig.json
src/
server.ts # entry
tools.ts # PKB tool handlers
schemas.ts # Zod schemas
logger.ts # pino setup
Dockerfile # added in L13
docker-compose.yml # added in L13
Caddyfile # added in L13
RUNBOOK.md # added in L15
Lesson 11 · Slide 11
The lesson 11 lab
This is a no-code lesson. The "lab" is:
- Confirm
node --version ≥ 20 and docker --version works.
- Clone or pull the repo so the empty TS skeleton is in place.
- Read the existing
package.json / tsconfig.json and trace why each option is set.
- Write a 1-page decision memo: "would I migrate my Python PKB to TS?" with three concrete arguments either way.
Lesson 11 · Slide 12
Recap & what's next
- TS for remote / internet-facing MCP servers.
- Python for personal / scientific / prototype servers.
- Same protocol either way — the choice is deployment substrate, not capability.
Coming up: Lesson 12 — Port PKB's first tool to TypeScript with the official SDK, Zod schemas, and the tsx dev loop.