Lion Cipher Lab

MCP server, Part 4: dynamic client registration and PKCE — let unknown clients register themselves and get tokens with no shared secret (all local, proven with curl)

Why it matters

Part 3 proved your MCP server can validate a real token, but it quietly assumed you had already hand-registered the one client that would call it and were minting its tokens yourself. That does not survive contact with the real MCP world. The MCP authorization model expects an open ecosystem: an AI host or agent you have never met should be able to DISCOVER your server, obtain its own credentials, and get a token WITHOUT you registering each client by hand — that is Dynamic Client Registration (RFC 7591). And those clients are usually public: a desktop app, a CLI agent, a single-page tool…

What you'll learn

Steps in this lab

  1. What Part 3 left open — the pre-registered, self-minted client
  2. The two new mechanisms: Dynamic Client Registration and PKCE (and how discovery finds them)
  3. When DCR + PKCE is worth it — and when Part 3's static client is the right call
  4. Set up: reuse the Part 3 folder and start the (unchanged) resource server
  5. Build the local authorization server stand-in: as.py
  6. Discover the endpoints with curl: protected-resource metadata, then AS metadata
  7. Register dynamically (RFC 7591): get a client_id with no hand-registration
  8. PKCE (RFC 7636): make a verifier + challenge, get a code, exchange it for a token
  9. Watch the interception defense fire: replay a stolen code without the verifier
  10. Failure modes and doing it better: gate DCR, keep redirect-URI + state, use a real AS

Open the full interactive lab →