// What's Next · Done · The Associate Track
Introduction to Model Context Protocol (MCP)
Completed Nov 08, 2026 · 3 hrs
MCP is an open standard that connects AI models to external tools and data through a host, client, and server architecture. This cheatsheet covers its primitives, server building, client communication, LLM integration, and production practices.
Architecture
- MCP: Open standard for secure, modular, bi-directional connections between AI models and external data sources or tools.
- Host: Application the user interacts with directly; it starts the connection and lets the LLM choose external connections.
- Client: Creates a session with an MCP server and executes requests using the JSON-RPC 2.0 message format.
- Server: Provides AI-friendly access to external data or functionality, translating API and database calls into the MCP format.
- Dynamic tool discovery: Lets the LLM see which tools a server offers in real time while completing a request.
Primitives
- Tools: Actions the LLM performs to complete a request, such as querying a database or booking a flight.
- Resources: Read-only data or context, such as documents, files, database records, or API responses.
- Prompts: Predefined workflow templates or instruction sets that guide the model and save users from writing long prompts.
- URI: Uniform resource identifier that points a resource at local files, APIs, or remote servers.
Building Servers
- FastMCP: Class from the official MCP Python SDK used to instantiate a server in one line.
- @mcp.tool(): Decorator that registers a Python function as a tool discoverable by MCP clients.
- @mcp.resource("uri"): Decorator that registers a resource function to read data, such as a local file.
- @mcp.prompt(title=""): Decorator that registers a prompt, with the title as metadata and the function name as the identifier.
- Docstrings and type hints: Describe each tool so the LLM can intelligently choose and use it; considered an absolute necessity.
Client Communication
- JSON-RPC 2.0: Standardized message format for every request, response, and function call between client and server.
- stdio: Transport where the client launches the server as a subprocess and exchanges messages over stdin and stdout.
- Streamable HTTP: Transport for remote servers, delivering JSON-RPC over HTTP and receiving it via Server-Sent Events.
- list_tools / list_resources / list_prompts: Session methods that discover the primitives a server exposes.
- call_tool / read_resource / get_prompt: Session methods that invoke a tool, read a resource, or retrieve a prompt.
- async with / await: Pattern that manages connections, pauses for server responses, and allows concurrent operations.
LLM Integration
- Tool-calling workflow: Five-step process from sending definitions and a query to returning a final informed response.
- stop_reason: Response attribute checked for tool_use to detect that the model wants to call a tool.
- read_resource: Client helper that fetches read-only context by URI for injection into the request.
- get_prompt: Client helper that retrieves a prompt template and injects the user's input into its arguments.
- Anthropic Messages API: Provider API used to wire MCP tools to Claude with tool-calling in mind.
Production
- Database integration: Connect to databases for query power, scale, concurrency, and production-ready backups and replication.
- Connection lifecycle: Create a connection once at startup or first use, reuse it in handlers, and close it on shutdown.
- Parameterized queries: Use placeholders instead of concatenating user or LLM input into SQL to prevent prompt injection.
- Timeout and error handling: Pass a timeout to requests and check raise_for_status() so tool calls fail clearly instead of hanging.
- API authentication: Keep API keys server-side in environment variables and attach them as Bearer tokens; never expose them to the client.
- Third-party MCP servers: Prebuilt servers for speed and maintained integration, weighed against trust, security, and surface area.
// Module notes
MCP Architecture
MCP exists because LLMs cannot reach live data, and bespoke code for every tool and API quickly turns complex. The fix is an open standard for secure, modular, bi-directional connections, often described as the USB-C port for AI applications. It adds dynamic tool discovery, so the LLM sees which tools a server offers in real time while completing a request.
- Host: the application the user interacts with directly; this is where the server connection begins.
- Client: opens a session with a server and executes requests using JSON-RPC 2.0.
- Server: exposes external data or functionality in the consistent MCP format.
Watch for how the split gives models controlled access to external context.
MCP Primitives
Servers expose functionality as primitives. Resources differ from tools in that the LLM does not necessarily call them.
- Tools: actions the LLM performs to complete a request, such as querying a database or booking a flight.
- Resources: read-only data or context, such as documents, files, database records, or API responses.
- Prompts: predefined workflow templates or instruction sets that guide the model for specific tasks.
- URI: the identifier used to point resources at local files, APIs, or remote servers.
Knowing which primitive fits a job decides whether the model acts or just reads.
Servers, Clients, and Transports
Any Python function can become a tool. Register functions with decorators on a FastMCP server, then connect a client that sends JSON-RPC 2.0 requests.
- Decorators: @mcp.tool(), @mcp.resource("uri"), and @mcp.prompt(title="") register primitives.
- Docstrings and type hints: let the LLM choose and use each tool correctly.
- stdio: the client launches the server as a subprocess and talks over stdin/stdout.
- Streamable HTTP: delivers JSON-RPC to remote servers over HTTP via Server-Sent Events.
- Client methods: list_tools, list_resources, list_prompts; call_tool, read_resource, get_prompt.
The docstring quality determines whether the LLM picks the right tool.
LLM Integration
Tools are wired to an LLM through a five-step tool-calling workflow; resources and prompts are fetched by the client and injected into the request.
- Tool calling: send tool definitions and the query, check stop_reason for tool_use, call the tool, then send the result back as a follow-up message.
- Context: read_resource fetches read-only context and get_prompt injects user input into a template, both passed to the model.
- Provider note: integration is LLM-dependent; this uses Claude through Anthropic's Messages API.
The same process looks different on every provider, so read your model's docs rather than memorizing code.
Production and Databases
Production servers harden API integrations and add database access with safe habits.
- API safety: set a timeout, call raise_for_status(), and keep keys server-side in environment variables as Bearer tokens.
- Databases: connect once at startup, reuse the connection, use parameterized queries, and close it on shutdown.
- Data access: resources fit read-only, infrequently changing reference data; tools fit dynamic, user-input-driven or write operations.
- Third-party servers: weigh trust, security, and surface area before plugging one in.
Shortcut any of these and the LLM gains a way to misuse the power you just handed it.
In plain terms
MCP is the USB-C port for AI applications. One standard port lets a model plug into databases, files, and APIs instead of a bespoke, insecure adapter for every tool. A host starts the connection, a client runs the session in JSON-RPC 2.0, and a server translates the messy outside world into that one consistent format.
Worth sitting with
- If MCP is a single standard port, what stops a server from exposing a dangerous tool, and who decides what the LLM is allowed to see?
- Why does dynamic tool discovery matter more than a fixed list of tools, and what could go wrong when the tool set changes mid-request?
- If docstrings and type hints decide whether the right tool gets called, where does prompt engineering end and tool design begin?
// Where this fits
The concepts above are the ones this module turns on, and the notes below explain each in turn. The course page carries the whole track, and the certificate page carries the plan it belongs to.