Skip to main content
Machine Learning & AI

MCP Tutorial with Examples.

MCP tutorial: build Model Context Protocol servers and clients in Python, with tools, resources, prompts, the wire protocol, HTTP and security.

Architecture at a glance

Click any box to open the lesson that teaches it

MCP architecture at a glance

host + LLM → MCP client ↔ JSON-RPC ↔ MCP server → tools, resources, prompts

MCP architecture at a glance A host app's LLM runs a tool-use or agent loop through an MCP client, which exchanges JSON-RPC messages with an MCP server over stdio or Streamable HTTP. The server exposes tools, resources and prompts, and can ask the client for sampling, roots or elicitation, with logging, progress and cancellation on the same connection. Results return structured and schema-checked. A bottom row covers OAuth authorization, security, observability and production scaling. Host app tool-use MCP Client discoverstools Transport JSON-RPCstdio · HTTP MCP Server capabilities Result schema-checked Agent loop many steps repeats per tool call What the server exposes Tools schemas Resources URI templates Prompts complete Security path · trust capabilities Client features Server asks the client sampling · roots · elicitation Logging · progress + cancellation, same call round trip Ship and secure OAuth basics OAuth + CIMD LLM security HTTP + Inspector Observability (OTel) Production & scaling
How it fits together (8 steps)
  1. The host app's LLM decides to call a tool, running the tool-use loop — or, across many steps, an agent loop.
  2. It talks through an MCP client, which discovers what a server offers before any call is made.
  3. Requests and responses travel as JSON-RPC over stdio or Streamable HTTP; the same server also runs over HTTP, testable with the Inspector.
  4. The MCP server exposes tools, resources and prompts with argument completion.
  5. Mid-call, the server can ask the client for things: sampling the client's model, reading roots, or eliciting a missing argument from the user, while logging, progress and cancellation ride the same connection.
  6. The result comes back structured and schema-checked, via outputSchema and structuredContent, and the loop decides whether to call another tool or stop.
  7. Shipping it needs auth and security: OAuth fundamentals wired into OAuth 2.1 and CIMD, server-side security, and LLM security beyond guardrails.
  8. In production: OpenTelemetry traces follow a call across client and server, and scaling, caching and operational controls keep it running.

Beginner

Start here — no prior experience needed

4 lessons

Intermediate

For developers with core concepts down

4 lessons

Advanced

Production-grade patterns for experienced engineers

5 lessons

Also part of MCP (Model Context Protocol)

Taught in other topics. Each link opens the lesson in its home topic.

5 lessons