Udemy
Turn what you know into an opportunity and reach millions around the world.
Learn More
Your cart is empty.
Keep shopping
MCP Production: Secure, Scalable MCP Servers in Python
New
3 students

MCP Production: Secure, Scalable MCP Servers in Python

Model Context Protocol servers that survive retries, replicas, OAuth and gateways. Built on the 2026 spec, in 14 labs.
Created byRuns Clean
Last updated 10/2026
English
English

What you'll learn

  • Build an MCP server in Python, and the same contract in TypeScript, that handles discovery, capabilities and errors the way the spec says
  • Run stateless MCP servers on revision 2026-07-28 across two replicas behind a gateway, and prove both return the same answer
  • Make retries safe: replace session state with handles that carry an owner and an expiry, and catch an operation that runs twice
  • Pause a tool call for a person's approval with Multi Round-Trip Requests, and make refusal and replay fail safely
  • Cache list and read results without letting one caller see another caller's data
  • Secure an MCP server with OAuth and PKCE, checking issuer, audience and scopes, including the requests it has to reject
  • Deploy behind a load balancer with health checks, logs and per-tool metrics, and run long jobs as durable tasks that survive restarts
  • Migrate a 2025-11-25 server to revision 2026-07-28 with compatibility tests and a rollback you've actually rehearsed
  • Apply MCP security best practices against prompt injection in tool output and tool definitions, and prove each control with a test
  • Point a black-box conformance suite at your own MCP server and know what a pass does and doesn't tell you

Course content

14 sections • 58 lectures • 6h 58m total length
  • Welcome, and how the labs in this course run2:47

    Here's the failure this course is built around, what you'll have built by the end against revision 2026-07-28, and how every lab runs on your machine with one Docker Compose command.

  • Before lab 1: set up Docker and Compose1:59

    Ten minutes now saves you an hour of guessing later. Install Docker, check Compose, and run one test container before the first lab.

  • Why a working tool call can fail on another replica7:44

    The same call works on replica A and fails on replica B. Work out what the request itself carries, what lives in application state, and which evidence tells the two apart.

  • Read an MCP request from headers to tool arguments8:22

    Read one self-contained request from the headers down to the tool arguments, separate routing metadata from input, and find the places where the two can contradict each other.

  • Diagnose a rejected call without guessing at the server8:23

    Transport error, protocol error, or a tool that ran and failed? Learn to tell them apart from the request and response alone, and where a client trace stops being proof.

  • Build the TypeScript server and run its contract tests8:46

    Start the lab and build tool discovery and invocation in TypeScript, then throw valid and malformed messages at it and read what comes back.

  • Build the Python server against the same contract8:22

    Build the same contract in Python, run the shared fixtures against both servers and compare their answers line by line.

  • Test discovery and version handling across replicas8:16

    Add discovery and capability checks, try a supported and an unsupported version, and send calls through alternating replicas to prove no request leans on the one before it.

  • Check yourself: The Request Contract

Requirements

  • Python you're comfortable with: running tests and reading a traceback. TypeScript helps in module 1, but you can follow the Python side only
  • Reading HTTP requests, JSON and command-line output
  • A computer that can run Docker Compose with a few containers at once
  • Internet access the first time each lab runs, to pull images and pinned dependencies

Description

This course contains the use of artificial intelligence.

A tool call times out at two in the morning. The server had already written the order before the connection dropped. Your client retries, the load balancer sends the retry to another replica, and now there are two orders. Nothing in the response tells you which one is real, and every test you have still passes, because they all ran against one process.

That's the distance between an MCP server that works on your laptop and one that holds up in production. Most Model Context Protocol material ends at the first tool call that works. This course starts there and puts your server through what production does to it: two replicas behind a gateway, OAuth tokens that were issued for some other service, a person who has to approve something halfway through a call, and a release you might have to roll back at short notice.

What you'll build

  • One request contract in Python, and the same contract in TypeScript, sent through a proxy to alternating replicas until you can prove both give the same answer.

  • Explicit handles with an owner and an expiry in place of session state, and a business operation that you can tell has already run when the retry shows up.

  • A human approval inside a tool call with Multi Round-Trip Requests, where saying no, walking away and replaying an old answer all fail safely.

  • Caching that never shows one caller another caller's data, measured on a workload you can rerun yourself.

  • MCP authentication done properly: a local OAuth flow with PKCE, and issuer, audience and scope checked at the server, including every request you're supposed to turn away.

  • Durable tasks that survive a restart, then the whole service behind a load balancer with health checks, logs, per-tool metrics and a rollback you've actually rehearsed.

Written against the current spec

Everything targets revision 2026-07-28, the stateless one: no initialization handshake, no protocol sessions, and input requests that come back inside the result. If you run a server on 2025-11-25, module 9 is about moving it, with compatibility tests and the deprecated features that are still in the spec for now. You don't need to learn the old model first.

Fourteen labs, and they have to pass

Every lesson was written against a lab that had already passed on a real machine. Docker Compose is the only thing you install. Images are pinned by digest, nothing asks for a cloud account or an API key, and each lab ships checks that break the code on purpose, so you watch the tests catch the exact defect they were written for.

Five extra modules

They go past the core contract into MCP security and what real deployments need. Agent security treats tool output as data and pins the tool definitions you approved, which is where prompt injection gets in. Resources and prompts are served without ever confirming what a caller can't see. The production-gaps module covers one trace across the gateway, tokens from a real identity provider and a rate limit that holds across replicas. A decisions module maps each need to a pattern and what it costs you. The last one puts it all into a reference server with a black-box conformance suite you can point at your own server.

Who it's for

Backend and platform engineers who already write Python and can read an HTTP request and a stack trace. If you've shipped an MCP tool and wondered what happens to it behind a load balancer, this was written for you. It isn't an introduction to LLMs, and it doesn't teach MCP from zero.

Who this course is for:

  • Backend engineers building MCP servers that expose real tools and data
  • Platform engineers who own the gateway, the auth and the uptime around those servers
  • Engineers chasing a bug that only shows up on the second replica or after a retry
  • Developers with an MCP integration on revision 2025-11-25 who need a tested way to move to 2026-07-28