Fundamentals & Architecture
The Model Context Protocol (MCP) is an open standard for AI systems to securely access external tools and resources.
In this set of lessons, we’ll cover the basics of developing with MCP as an engineer: from the fundamental architecture to using and building MCP servers.
Let’s start by talking about what problem MCP solves, and how it works.
This Lesson Will Cover
🧩 Why MCP exists and where it fits in the modern AI tool-chain
🏗️ Core protocol objects — Tools, Prompts, Resources — and the supplemental concepts of Roots, Sampling, and Transports
🔄 JSON-RPC 2.0 message lifecycle for tool calls, resource reads, and sampling requests
🚚 Transport choices:
stdiofor local processes and editor plugins- Streamable HTTP for cloud or high-concurrency deployments
Why MCP?
The Model Context Protocol (MCP) addresses the problem of fragmented tool interfaces for connecting language models to external data and capabilities.[1]
In a world without MCP, different AI applications require their own bespoke methods of interaction, requiring more development time, increased complexity, and maintenance challenges.
MCP solves for these inefficiencies by providing a unified, language-agnostic protocol that standardizes how applications provide context to LLMs.
The result is a world where developers have a clearly defined and robust way of integrating their applications and data with any language model.[2]
Core Architecture
MCP is designed around a client-server model — but unlike traditional networked systems, these components often run as local processes on the same machine (e.g., your laptop or development environment).
Consider the following primary components:
- MCP Client: This is a component embedded inside an AI application — like a desktop app or terminal tool — responsible for sending and receiving structured requests to/from the server.
- MCP Server: This is a separate process that “hosts” tools, resources, and prompt templates, making them available to the AI via a formal interface.
- Communication Protocol: These two processes communicate using a lightweight message-passing standard (JSON-RPC 2.0), typically over local
stdioor HTTP.
The model or host application selects a tool and supplies its arguments. After initialization and tool discovery with tools/list, the MCP client sends a tools/call JSON-RPC request and returns the server’s result to the application. Protocol communication and interpreting user intent are separate responsibilities.
Component Breakdown
| Component | Description | Concrete Example |
|---|---|---|
| MCP Clients | Part of an AI application, this process manages communication with an MCP server. It sends protocol requests such as tools/list and tools/call and returns tool responses to the host application. | A VSCode plugin running an AI assistant sends a request via its embedded MCP client to fetch the output of a code linter tool. |
| MCP Servers | A local or remote process that exposes tools (functions), resources (read-only data), and prompts. These are described in a machine-readable way and can be invoked by the model. | A Python-based MCP server running in the background exposes access to a local file search tool and a SQL database for querying project metrics. |
| Communication Protocol | JSON-RPC 2.0 is used to format requests and responses between client and server, typically over stdio or HTTP. This allows tools written in any language to work together. |
The MCP client sends a JSON-RPC request over stdio to a Node.js tool that returns today’s weather using a local API key. |
MCP Client Examples
It’s become standard practice for AI tools to implement MCP clients. The OpenAI desktop application is expected to release this soon.
Here are some examples of MCP clients available at time of writing:
- Claude Desktop (App)
- Cursor (Editor)
- Windsurf (Editor)
- Cline (VS Code plugin)
- Continue (VS Code plugin)
- Claude Code (CLI tool)
- MCPHub (Neovim plugin)
MCP Server Examples
Many MCP clients provide MCP server marketplaces, where we can browse the most popular servers.
Here’s the top 10 from MCPHub at time of writing (June 2025):
1) Google Drive ✨ ⭐ 50952 ⬇️ 5046
Enables searching, listing, and reading files from Google Drive, with automatic export of Google Workspace files to common formats like Markdown, CSV, and PNG.
2) Google Maps ✨ ⭐ 50943 ⬇️ 3664
Provides comprehensive access to Google Maps services including geocoding, place search, directions, distance calculations, and elevation data through the Google Maps API.
3) SQLite ✨ ⭐ 50915 ⬇️ 8815
Provides database interaction and business intelligence capabilities through SQLite, enabling SQL queries, data analysis, and automated business insight generation.
4) Puppeteer ✨ ⭐ 50909 ⬇️ 20397
Provides browser automation capabilities using Puppeteer, enabling web page interaction, screenshots, and JavaScript execution in a real browser environment.
5) Time ✨ ⭐ 50904 ⬇️ 16591
Provides time and timezone conversion capabilities using IANA timezone names, with automatic system timezone detection and support for current time queries.
6) GitLab ✨ ⭐ 50886 ⬇️ 3997
Enables comprehensive GitLab project management including file operations, issue tracking, merge requests, and repository management through the GitLab API.
7) Sequential Thinking ✨ ⭐ 50870 ⬇️ 38304
A structured problem-solving tool that enables step-by-step analysis, thought revision, and branching logic for complex reasoning tasks.
8) PostgreSQL Reader ✨ ⭐ 50846 ⬇️ 7155
Provides read-only access to PostgreSQL databases, allowing LLMs to inspect database schemas and execute read-only queries within protected transactions.
9) Knowledge Graph Memory ✨ ⭐ 50808 ⬇️ 9726
A persistent memory system using a local knowledge graph that enables AI assistants to remember information about users across conversations through entities, relations, and observations.
10) GitHub ✨ ⭐ 50794 ⬇️ 71365
Comprehensive GitHub API integration enabling repository management, file operations, issue tracking, pull request handling, and advanced search functionality across code, issues, and users.
Protocol Concepts
Here’s an overview of the core primitives for MCP:
| Object | Purpose |
|---|---|
| Tool | Represents a callable function or operation with structured inputs/outputs (JSON Schema). |
| Prompt | A reusable template or instruction that guides the model’s behavior or response. |
| Resource | Provides the AI model with read-only data like files, documents, or database entries. |
And here’s an overview of a few more supplemental MCP concepts:
| Object | Purpose |
|---|---|
| Transports | The underlying channel that transmits JSON-RPC messages between client and server. |
| Sampling | Requesting a model-generated completion from the client. |
| Roots | Defining a scoped collection or namespace for tools, resources, and prompts. |
At time of writing, in 2025, most MCP clients do not support root and sampling features.[3] Tools account for the vast majority (probably over 90%[4]) of MCP usage.
Let’s explore a concrete example of how these objects work together in practice:
Weather MCP Server Example
Imagine that you’re working with a weather MCP server that helps an AI assistant get current weather data.
Here are examples of how it might expose functionality through the three core primitives of MCP:
-
Tools: A
get_current_weathertool and aget_weather_alertstool that the AI can call to fetch active weather and warnings for any city. -
Prompts: A template called
weather-briefingthat structures how to present weather info (like “Give temperature, conditions, and any safety advice”). -
Resources: The server exposes a text document
file://weather/data/sources.mddescribing the underlying data sources used, and a PDFfile://weather/safety.pdfwith illustrated safety information.
Additionally, here are examples of how it could make use of other MCP concepts:
-
Transports: Communication happens over stdio between your chat app (MCP client) and the weather server.
-
Sampling: An
analyze_weather_patternstool that fetches historical weather data and then runs a series of LLM analysis prompts on the data. This can be done from the server using the client LLM. -
Roots: The server accepts a versioned weather provider URI, e.g.
https://awesome-weather-api.com/v1. This can be provided by clients when they connect to the server.
Based on this setup we could imagine a number of user LLM interactions:
-
Tool Call: “What’s the weather like in Toronto today?” → The AI calls the
get_current_weathertool with{"location": "Toronto", "units": "metric"}and receives structured data about temperature, conditions, etc. -
Prompt Template Usage: Select
weather-briefingtemplate from drop-down menu → The AI directly inserts theweather-briefingprompt template into the user input dialogue. -
Direct Resource Access: Select
file://weather/data/sources.mdfrom drop-down menu and ask “Explain where your data comes from for Mexico City?” → The AI directly inserts the selected file context into the chat along with the question. -
Tool-Mediated Resource Access: “Show me weather safety guidelines for thunderstorms in my area” → The AI calls a
get_safety_infotool that internally fetches and processes content from thefile://weather/safety.pdfresource for Toronto. -
Sampling Call: “Analyze the weather patterns in Thunder Bay over the last month” → The AI calls the
analyze_weather_patternstool, which fetches historical data and then uses the client’s LLM capabilities (via sampling) to generate insights about trends and anomalies.
Roots work a bit differently — they provide configuration context when connecting to the server. For example, an MCP client might allow the user to set the API version as a configuration setting, and then inform the server about the root Weather Provider URI accordingly. This would be provided from the client to the server during the initial connection or whenever it changes (i.e. when the user changes their config settings).
Message Lifecycle - Anatomy of a Call
MCP clients and servers communicate over a transport layer using JSON-RPC formatted messages.
Let’s continue the weather example from above and walk through what happens when a user asks “What’s the weather like in Toronto today?” and the AI calls the weather server’s get_current_weather tool.
Step 1: Client Requests Weather Data
The MCP client (the chat app) sends a JSON-RPC request to the weather server over the stdio transport:
// MCP Client → MCP Weather Server
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "get_current_weather",
"arguments": {
"location": "Toronto",
"units": "metric"
}
}
}
What’s happening here:
- The
jsonrpc: "2.0"field indicates this follows the JSON-RPC 2.0 specification - The
id: 1field allows the client to match this request with the eventual response - The
method: "tools/call"tells the server this is a tool invocation - The
paramsobject contains the tool name and the arguments the AI wants to pass
Step 2: Server Processes and Responds
The weather server receives this message through its stdio transport, processes the request by calling the underlying weather API, and sends back a JSON-RPC response:
// MCP Weather Server → MCP Client
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"content": [
{
"type": "text",
"text": "Current weather in Toronto: 52°F, cloudy with light rain. Humidity: 78%. Wind: 8 mph NW."
}
]
}
}
What’s happening here:
- The
id: 1matches the original request, so the client knows this response belongs to that specific call - The
resultfield contains the successful response data - The weather information is structured as content that the AI can use in its response to the user
Step 3: Error Handling (Alternative Flow)
If something goes wrong - like an invalid location or API failure - the server would send an error response instead:
// MCP Weather Server → MCP Client (Error Case)
{
"jsonrpc": "2.0",
"id": 1,
"error": {
"code": -32602,
"message": "Invalid location parameter",
"data": {
"parameter": "location",
"value": "InvalidCity123",
"suggestion": "Please provide a valid city name"
}
}
}
Transport Layer Details
Here’s a detailed explanation of how this flow works for stdio:
- The client process spawns the weather server as a child process
- JSON-RPC messages are sent as serialized newline-delimited JSON over stdin/stdout
- The client writes the request message to the server’s stdin
- The server reads from its stdin, processes the message, and writes the response to stdout
- The client reads the response from the server’s stdout
Advanced Scenarios
Resource Access Example:
If the user asked “Show me your weather data sources”, the flow might look like:
// MCP Client → MCP Weather Server
{
"jsonrpc": "2.0",
"id": 2,
"method": "resources/read",
"params": {
"uri": "file://weather/data/sources.md"
}
}
// MCP Weather Server → MCP Client
{
"jsonrpc": "2.0",
"id": 2,
"result": {
"contents": [
{
"uri": "file://weather/data/sources.md",
"mimeType": "text/markdown",
"text": "# Weather Data Sources\n\nOur weather data comes from:\n- NOAA Weather Service API\n- Local weather station network\n..."
}
]
}
}
Sampling Request Example:
For the weather pattern analysis tool that uses sampling:
// MCP Client → MCP Weather Server
{
"jsonrpc": "2.0",
"id": 3,
"method": "tools/call",
"params": {
"name": "analyze_weather_patterns",
"arguments": {
"location": "Toronto",
"start": "2025-05-01",
"end": "2025-05-31"
}
}
}
// MCP Weather Server → MCP Client (Sampling Request)
{
"jsonrpc": "2.0",
"id": 3,
"method": "sampling/createMessage",
"params": {
"messages": [
{
"role": "user",
"content": {
"type": "text",
"text": "Analyze this weather data for patterns: [historical data here]"
}
}
],
"maxTokens": 1000
}
}
// MCP Client → MCP Weather Server (Sampling Response)
{
"jsonrpc": "2.0",
"id": 3,
"result": {
"role": "assistant",
"content": {
"type": "text",
"text": "Based on the data, I notice three key patterns: 1) Temperature fluctuations follow a clear seasonal trend..."
}
}
}
This message lifecycle demonstrates how MCP’s transport layer enables communication between clients and servers using the standardized JSON-RPC protocol, with examples of tool calls, resource access, and sampling operations.
Transports in the Wild
MCP is transport-agnostic: it can work over any transport that has the proper interface.
However, a few transports have become common in practice due to their reliability and/or standard implementation in MCP:
| Transport | When to Use |
|---|---|
| Standard Input/Output (stdio) | Local integrations, command-line tools. |
| Server-Sent Events (SSE) | If streamable HTTP is not possible for some reason. |
| Streamable HTTP | Cloud-hosted, high-concurrency APIs. |
FastMCP recommends using Standard Input/Output (stdio) when running local servers and Streamable HTTP transport for remote/persistent servers.[5]
Key Considerations for Each Transport
-
Standard Input/Output (stdio):
- Best for local tools, editor plugins, and environments with direct process communication.
- Very low overhead, with no need for network configuration.
- Not suitable for distributed or cloud-based applications.
-
Streamable HTTP:
- Supports both streaming and traditional HTTP-style responses.
- Designed for robust, scalable deployments (e.g., in serverless or containerized environments).
Conclusion
MCP is very young — less than a year old at time of writing. It’s hard to predict how it will evolve in the coming years, but I expect that the core concepts and architecture we discussed above will remain the same.
Key Takeaways
🔗 MCP is an open, language-agnostic standard for passing context into a model and invoking external tools in a consistent way.
🧩 The three primary objects are Tools, Prompts, and Resources; Roots, Sampling, and Transports round out the model-server contract.
🛠️ A healthy ecosystem of MCP clients (e.g., Claude Desktop, Cursor, Continue, fast-agent) and servers (e.g., Google Drive, SQLite, Puppeteer) shows broad real-world adoption.
📊 Tool calls make up well over 90 % of current MCP traffic; Sampling and Roots remain niche, with only a few clients offering full support.
🚚 Use
stdiolocally and Streamable HTTP remotely; SSE is now a legacy, one-way option.🌐 All communication uses JSON-RPC 2.0, giving predictable request/response semantics and language-independent interoperability.
Next: Using MCP Servers
Having seen the core concepts, let’s actually use MCP. In the next lesson we’ll get up and running with the Context7 MCP server for Claude Desktop.
PS. The footnotes below have some pretty amazing gems. For example, the MCP podcast episode[4:1] was a great resource to help me understand this stuff.
Footnotes
Read Introducing the Model Context Protocol from Anthropic to experience a little piece of AI history (Nov 25, 2024) ↩︎
Here’s where the “USB-C port for AI” analogy comes in. First of all — it’s an open protocol, so it can be adopted by every model, tool and data provider (similar to how USB-C has been universally adopted). Next, think about how MCP mirrors the use-cases of USB: it provides a common way to pass context into a model and action out via tools, similar to USB-C’s bidirectional data + power. ↩︎
A feature support matrix for MCP clients is published on the official model context protocol website. As of June 2025, fast-agent is the only MCP client listed that has complete feature support (including sampling and roots). ↩︎
The creators of MCP said “tool calling is obviously like probably like 95% plus of the integrations” on a podcast in April 2025. ↩︎ ↩︎
Here are the FastMCP docs which discuss various transport options. The official MCP transport docs do not make SSE sound like a very appealing option, suggesting usage when “Only server-to-client streaming is needed” or “Working with restricted networks”. ↩︎
Comments (0)
No comments yet.