MCP (Model Context Protocol)
Explains the Model Context Protocol (MCP) architecture, its JSON-RPC flow, and how FastMCP simplifies server creation.
What this file does
Explains the Model Context Protocol (MCP) architecture, its JSON-RPC flow, and how FastMCP simplifies server creation.
When to use it
- Learning how MCP connects AI models to external tools
- Understanding the JSON-RPC message exchange between client and server
- Evaluating FastMCP as a wrapper for building MCP servers
- Referencing the architecture diagrams for a team presentation
Assumes this stack
MCP (Model Context Protocol)
What is MCP
MCP is a standardized protocol that enables AI models to securely connect to external data sources and tools through a client-server architecture.
It is an open standard created by Anthropic, but it's not specific to Claude at all. Developers can build MCP servers (tools) once, and those tools can then work with any AI that supports the protocol.
Below is a diagram showing how MCP fits in the AI system architecture (e.g. Claude):
┌─────────────────────────────────────────────────────┐
│ YOU (Human) │
└────────────────────┬────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────┐
│ Claude (AI Assistant) │
│ ┌───────────────────────────────────────────────┐ │
│ │ Claude Sonnet 4.5 Model (The Brain) │ │
│ │ • Thinks and reasons │ │
│ │ • Generates responses │ │
│ └───────────────────────────────────────────────┘ │
└────────────────────┬────────────────────────────────┘
│
│ Uses tools via...
▼
┌─────────────────────────────────────────────────────┐
│ MCP (Model Context Protocol) │
│ (The "Connector" / "App Store") │
└────┬────────────┬────────────┬───────────┬──────────┘
│ │ │ │
▼ ▼ ▼ ▼
┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐
│ Dropbox │ │ Local │ │Database │ │ Custom │
│ Server │ │ Files │ │ Server │ │ APIs │
│ │ │ Server │ │ │ │ │
└─────────┘ └─────────┘ └─────────┘ └─────────┘
(Tool) (Tool) (Tool) (Tool)
MCP Architecture
Visual
┌─────────────────┐
│ USER │
└────────┬────────┘
│
▼
┌────────────────────────────────────────────────┐
│ MCP HOST │
│ (Claude Desktop, IDEs, Custom Apps) │
│ │
│ ┌──────────────────────────────────────────┐ │
│ │ AI MODEL (Claude, GPT, etc) │ │
│ └──────────────────────────────────────────┘ │
│ │
│ ┌──────────────────────────────────────────┐ │
│ │ MCP CLIENT │ │
│ │ • Sends requests │ │
│ │ • Receives responses │ │
│ └──────────────────────────────────────────┘ │
└────────────────┬───────────────────────────────┘
│
│ MCP Protocol
│ (JSON-RPC over stdio/HTTP)
│
┌───────────┼───────────┬──────────────┐
│ │ │ │
▼ ▼ ▼ ▼
┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐
│ MCP │ │ MCP │ │ MCP │ │ MCP │
│ SERVER │ │ SERVER │ │ SERVER │ │ SERVER │
│ 1 │ │ 2 │ │ 3 │ │ N │
└────┬────┘ └────┬────┘ └────┬────┘ └────┬────┘
│ │ │ │
▼ ▼ ▼ ▼
┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐
│Dropbox │ │ Local │ │Database │ │ Custom │
│ API │ │ Files │ │ │ │ Tool │
└─────────┘ └─────────┘ └─────────┘ └─────────┘
Flow
User: "Add 5 and 3"
↓
Client → Model: "User wants to add 5 and 3"
↓
Model → Client: "I need to call the add tool"
↓
Client → Server:
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "add",
"arguments": {
"a": 5,
"b": 3
}
}
}
↓
Server → Client:
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"content": [
{
"type": "text",
"text": "8"
}
],
"structuredContent": 8,
"isError": false
}
}
↓
Client → User: "5 + 3 = 8"
Manual Implementation
code-examples/mcp/ - Educational example showing how MCP uses JSON-RPC protocol from scratch
FastMCP
FastMCP is a convenience wrapper that makes it easier to create MCP servers.
Code
class FastMCP(Generic[LifespanResultT]):
def __init__(self, ...):
# Creates a low-level MCPServer
self._mcp_server = MCPServer(...)
def _setup_handlers(self) -> None:
"""Set up core MCP protocol handlers."""
self._mcp_server.list_tools()(self.list_tools)
self._mcp_server.call_tool(validate_input=False)(self.call_tool) # ← Key!
Flow
1. Client sends: {"method": "tools/list"}
↓
2. MCPServer receives the MCP protocol message
↓
3. MCPServer looks up: "What handler is registered for tools/list?"
↓
4. MCPServer finds: "Oh, it's FastMCP.list_tools"
↓
5. MCPServer calls: FastMCP.list_tools()
↓
6. FastMCP.list_tools() returns the tools
↓
7. MCPServer formats the response and sends it back
Example Usage
code-examples/fastmcp/ - Real MCP server using FastMCP framework
References
- Cursor with Claude Model
- MCP Python SDK https://github.com/modelcontextprotocol/python-sdk
What's inside
2 architecture diagrams, 1 JSON-RPC flow example, 1 FastMCP code snippet, 1 FastMCP flow, 2 code-example references
Change this for your project
- Replace
code-examples/mcp/andcode-examples/fastmcp/with your own example directories - Replace
Cursor with Claude Modelreference with your AI host or tool
Where it goes
Save in docs/ or the repository root. Gives agents and new contributors a map of the codebase.
Worth borrowing
- Using a convenience wrapper (FastMCP) to hide low-level protocol handling
- Separating protocol handlers from business logic via a server class
Related Documents
Design Document: BharatSeva AI
Describes a 10-agent AWS system that helps India's informal workers access government schemes via voice-first, serverless architecture.
OpenClaw Enterprise Transformation Plan
Transforms a single-user AI agent into a dual-mode platform supporting both viral open-source and Fortune 500 enterprise deployments through phased security, IAM, audit, multi-tenancy, and Kubernetes features.
University of Guelph Rocketry Club - Complete Tech Stack
Documents the full tech stack of a university rocketry club website with AI chatbot, member management, and project showcases.
Qwen Image and Edit: Open-sourcing and Local GGUF Generations with Lightning
Documents the Qwen-Image and Qwen-Image-Edit models, covering architecture, training, benchmarks, ComfyUI setup, and prompting techniques for local GGUF deployment.