MCP in Production: Building & Securing Model Context Protocol Servers
course lessons.
1 Section · 5 LessonsCore Architecture & Production Implementation
- 1.1What MCP Actually Is (Architecture Diagram & Stdio vs. Streamable HTTP)
Every conference talk this year mentions the Model Context Protocol, or MCP, but most tutorials stop at a local Stdio script that only runs on your laptop. Let's break down what MCP actually is on the wire and wire up Streamable HTTP in TypeScript.
MCPCloudflareTypeScript+3▶ Video + LessonStart Lesson → - 1.2Building Your First TypeScript MCP Server on Cloudflare Workers
Shipping an MCP server inside a heavy Docker container means paying for idle RAM and suffering six hundred millisecond cold starts. Here is how we deploy a zero-cold-start TypeScript MCP server on Cloudflare Workers with Hono.
MCPCloudflareTypeScript+3▶ Video + LessonStart Lesson → - 1.3Securing Remote MCP Servers with OAuth 2.1 & Better-Auth
Pasting long-lived admin API keys into local JSON files works for a weekend demo, but it is a security disaster in production. Let's secure our remote MCP server with OAuth 2.1, PKCE, and Better-Auth.
MCPCloudflareTypeScript+3▶ Video + LessonStart Lesson → - 1.4Client-Side WebMCP & RFC 9727 Agent Discovery
Why are AI agents still burning twenty thousand tokens scraping raw HTML DOM trees when your web app already has a structured API? Let's fix that with Client-Side WebMCP and RFC 9727 Agent Discovery.
MCPCloudflareTypeScript+3▶ Video + LessonStart Lesson → - 1.5Connecting MCP to Verified Knowledge Bases (Sanity Context vs. Naive RAG)
Slicing your documentation into five-hundred-token vector chunks and praying cosine similarity finds the right paragraph is why production RAG hallucinates. Here is how Sanity Context Knowledge Bases and MCP fix it.
MCPCloudflareTypeScript+3▶ Video + LessonStart Lesson →
course overview.
1. Production Architecture Problem & Why We Built This Course
Move beyond toy local Stdio scripts. Learn how to architect, secure, and deploy remote Model Context Protocol (MCP) servers on Cloudflare Workers with OAuth 2.1, Better-Auth, WebMCP (RFC 9727), and Sanity Context Knowledge Bases. In production engineering teams, the gap between a quick weekend demo and a resilient, multi-tenant system comes down to three architectural boundaries: cold-start latency, compile-time contract validation, and predictable operational cost. Throughout MCP in Production: Building & Securing Model Context Protocol Servers, we strip away marketing buzzwords and build the exact TypeScript, edge compute, and structured data patterns that power CodingCat.dev in production.
Every lesson in this course pairs a dark-mode Architecture Diagram (contrasting the legacy anti-pattern on the left against the recommended 2026 production pattern on the right) with copy-pasteable TypeScript modules, automated verification checks, and an explicit Trade-Off Matrix. Whether you are reading the official Model Context Protocol (MCP) Official Specification (2025-03-26 / 2026 Streamable HTTP) or pairing this course with our deep dive on Blog Post: Architecting the Agent-Ready Web with WebMCP, Streamable HTTP MCP, and RFC 9727, you can apply every pattern directly to your own repository today.
🐾 AJ's Course Architecture Rule: Never adopt a tool just because it trended on social media. Measure its cold start in milliseconds, verify its TypeScript schema boundary at compile time, and check what happens to your cloud bill when traffic spikes 100x.
2. Lesson-by-Lesson Architectural Walkthrough (5 Lessons)
Work through the lessons in sequence to build the complete system from first principles, or jump directly to the specific architectural boundary you are solving right now:
- Lesson 1: What MCP Actually Is (Architecture Diagram & Stdio vs. Streamable HTTP): Replaces the
STDIO TRAP (AI Host App, stdin / stdout, Child Proc)anti-pattern withJSON-RPC 2.0 -> POST /api/mcp + Edge Workerinsidesrc/mcp/transport.ts. Every conference talk this year mentions the Model Context Protocol, or MCP, but most tutorials stop at a local Stdio script that only runs on your laptop. Let's break down what MCP actually is on the wire and wire up Streamable HTTP in TypeScript. - Lesson 2: Building Your First TypeScript MCP Server on Cloudflare Workers: Replaces the
CONTAINER LAG (Docker Image, Cold Boot, Idle Server)anti-pattern withHono + MCP -> tools/list + tools/callinsidesrc/mcp/worker.ts. Shipping an MCP server inside a heavy Docker container means paying for idle RAM and suffering six hundred millisecond cold starts. Here is how we deploy a zero-cold-start TypeScript MCP server on Cloudflare Workers with Hono. - Lesson 3: Securing Remote MCP Servers with OAuth 2.1 & Better-Auth: Replaces the
STATIC KEYS (Shared API Key, No Scopes, No Expiry)anti-pattern withBetter-Auth -> Bearer Token + Tenant Isolationinsidesrc/mcp/auth-guard.ts. Pasting long-lived admin API keys into local JSON files works for a weekend demo, but it is a security disaster in production. Let's secure our remote MCP server with OAuth 2.1, PKCE, and Better-Auth. - Lesson 4: Client-Side WebMCP & RFC 9727 Agent Discovery: Replaces the
DOM SCRAPING (Headless Bot, Brittle CSS, Blind Clicks)anti-pattern with/.well-known -> navigator.modelContext + Link Headerinsidesrc/pages/.well-known/api-catalog.ts. Why are AI agents still burning twenty thousand tokens scraping raw HTML DOM trees when your web app already has a structured API? Let's fix that with Client-Side WebMCP and RFC 9727 Agent Discovery. - Lesson 5: Connecting MCP to Verified Knowledge Bases (Sanity Context vs. Naive RAG): Replaces the
NAIVE RAG (500-Token Chunks, Stale Vectors, Top-K Guess)anti-pattern withSanity Context -> initial_context + knowledge_searchinsidesrc/mcp/sanity-context.ts. Slicing your documentation into five-hundred-token vector chunks and praying cosine similarity finds the right paragraph is why production RAG hallucinates. Here is how Sanity Context Knowledge Bases and MCP fix it.
3. Alex's 2026 Ecosystem & Architectural Tier List
Before writing a single line of configuration, you need to know how the available platforms and patterns stack up in real production environments. Here is how I rank the ecosystem from S-Tier (our default production choice on CodingCat.dev) down to D-Tier anti-patterns to avoid:
Alex's 2026 MCP Transport & Hosting Architectural Tier List
Ranking 5 production architectures for Model Context Protocol servers across cold-start latency, auth isolation, discovery, and cost.
Streamable HTTP on Cloudflare Workers + Better-Auth OAuth 2.1 ↗
Edge V8 Isolate + D1 SQLiteSub-5ms cold starts across 300+ edge PoPs, native JSON-RPC 2.0 over HTTP POST/SSE, and zero-cost idle scaling with scoped OAuth 2.1 Bearer tokens stored in Cloudflare D1.
Client-Side WebMCP (navigator.modelContext) + RFC 9727 ↗
In-Browser Agent Tool SurfaceExposes structured browser tools directly to in-page AI assistants while reusing the user's active cookie session and eliminating 20,000-token DOM scraping.
Sanity Context Knowledge Base MCP ↗
Ahead-of-Time Verified GraphCompiles structured Portable Text and document references into an ahead-of-time knowledge graph served via initial_context and knowledge_search tools.
Local Stdio Transport (npx / uvx Child Process) ↗
Single-User Desktop PipeIdeal for local git, terminal, and filesystem helpers inside Cursor or Claude Desktop, but cannot be deployed directly for multi-tenant SaaS users.
Unauthenticated Docker SSE Wrapper with Shared Root API Key
Legacy Container Anti-PatternSuffers from 600ms+ container cold starts, $50+/mo idle memory charges, and catastrophic confused-deputy security vulnerabilities when one static key is shared.
4. Production Starter Configuration & Local Setup
To follow along with the code examples in MCP in Production: Building & Securing Model Context Protocol Servers, start with this baseline wrangler.jsonc configuration. It enables strict TypeScript verification, observability tracing, and local development bindings that match production 1-to-1:
{
"$schema": "node_modules/wrangler/config-schema.json",
"name": "codingcat-mcp-production",
"main": "src/mcp/worker.ts",
"compatibility_date": "2026-03-01",
"compatibility_flags": ["nodejs_compat"],
"observability": { "enabled": true, "head_sampling_rate": 1 },
"d1_databases": [
{
"binding": "DB",
"database_name": "codingcat-mcp-auth",
"database_id": "00000000-0000-0000-0000-000000000001"
}
],
"vars": {
"MCP_SERVER_NAME": "codingcat-catalog-mcp",
"MCP_SERVER_VERSION": "2.1.0",
"SANITY_PROJECT_ID": "hfh83o0w",
"SANITY_DATASET": "production"
}
}5. Course-Wide Production Trade-Off Matrix
Every architectural decision involves trade-offs. Use this reference table during design reviews with your team to justify why we choose edge-native TypeScript, explicit schema validation, and deterministic workflows over legacy alternatives:
| Architectural Dimension | 2026 CodingCat.dev Course Pattern | Legacy Industry Default | Production Impact at Scale |
|---|---|---|---|
| Compute & Cold Starts | V8 Isolates / Native Browser Compositor (< 5ms) | Heavy Container VMs / Main-Thread JS Bloat (500ms+) | Eliminates tail-latency spikes on every request and interaction. |
| Contract & Type Safety | End-to-End TypeScript + Zod / GROQ TypeGen | Untyped JSON payloads & manual interface drift | Catches breaking schema changes in CI before deployment. |
| State & Database Topology | Cloudflare D1 Batch / Durable SQLite / Sanity Content Lake | Exhausted TCP pools & unindexed N+1 loops | Predictable sub-10ms reads with zero connection pool errors. |
| Security & Multi-Tenancy | OAuth 2.1 PKCE + Better-Auth Scoped Sessions | Shared static API keys & unescaped DOM strings | Zero-trust tenant isolation and $0 per-MAU SaaS tax. |
| AI & Agent Readiness | Streamable HTTP MCP + WebMCP + RFC 9727 + Daily Spend Caps | 20k-token headless DOM scraping & uncapped retry loops | Cuts token spend by 95%+ while preventing runaway bills. |
6. Official Specifications, Docs & Related CodingCat.dev Deep Dives
Bookmark these official specifications and related CodingCat.dev Courses, Blog Posts, and Podcast Episodes as you work through the lessons:
- Blog Post: Architecting the Agent-Ready Web with WebMCP, Streamable HTTP MCP, and RFC 9727: Deep architectural walkthrough of dual-surface MCP servers and RFC 9727 /.well-known/api-catalog discovery.
- Blog Post: WebMCP Explained: Exposing Browser-Native AI Tools with navigator.modelContext: How to register imperative and declarative client-side tools inside the user's active browser tab.
- Blog Post: Sanity Knowledge Bases & Agent Context MCP: Replacing brittle 500-token runtime vector RAG with ahead-of-time compiled Sanity Context graphs.
- Podcast Episode: How OAuth, MCP, and the OpenAI Apps SDK Power Interactive AI Experiences: Conversation on securing multi-tenant MCP servers with OAuth 2.1, PKCE, and scoped tokens.
- Podcast Episode: Identity in AI Agents with Tobin South: Delegated agent authorization, confused-deputy mitigation, and cryptographic tool auditing.
- Companion Course: The Zero-Cold-Start Edge Stack (Astro 7, Cloudflare Workers, D1 & Better-Auth): Master the underlying V8 isolate runtime, Cloudflare D1 SQLite database, and Better-Auth session layer.
- Model Context Protocol (MCP) Official Specification (2025-03-26 / 2026 Streamable HTTP): Canonical JSON-RPC 2.0 wire framing, capability negotiation, and Streamable HTTP transport rules.
- IETF RFC 9727: api-catalog Well-Known URI for Automated API Discovery: Standardized application/linkset+json format at /.well-known/api-catalog for HTTP Link header discovery.
- OAuth 2.1 Authorization Framework Specification & PKCE Requirements: Mandatory PKCE, exact redirect URI matching, and Bearer token hygiene for remote tool servers.
- Cloudflare Agents & Model Context Protocol Developer Documentation: Deploying stateless and stateful Streamable HTTP MCP servers on Cloudflare Workers.
- Better-Auth Official Documentation: OAuth 2.1 Provider & D1 Adapter: Self-hosted TypeScript authentication with OIDC/OAuth 2.1 token issuance on Cloudflare D1.
Ready to write code? Jump straight into Lesson 1: What MCP Actually Is (Architecture Diagram & Stdio vs. Streamable HTTP) →
how this course connects together.
Follow AJ through the sequence topology from input contract to production output.
