Model Context Protocol (MCP): The New Industry Standard for AI Agents
Every major leap in computing requires a universal protocol to unlock network effects. The web scaled because HTTP standardized hypermedia transfer. Relational databases scaled because SQL standardized queries. Yet, until recently, connecting large language models to enterprise data sources (GitHub, PostgreSQL, Slack, Google Drive) was an engineering mess: every AI tool built proprietary, brittle integrations.
Anthropic solved this systemic fragmentation by open-sourcing the Model Context Protocol (MCP). MCP provides an open, standardized JSON-RPC 2.0 communication layer between AI client applications (hosts) and external data integrations (servers). In this architectural deep dive, we explore how MCP functions, dissect its three foundational primitives, build a custom Python FastMCP server, and evaluate its impact on enterprise agent architectures.
The N x M Integration Problem in AI Engineering
Before MCP, connecting AI applications to developer tools suffered from an exponential scaling bottleneck:
- If there are N AI applications (Claude Desktop, Cursor, Continue, Cline, custom internal agent frameworks),
- And M enterprise tools (PostgreSQL, Jira, GitHub, Linear, Snowflake),
- Developers were forced to write and maintain N × M distinct integrations.
If Cursor updated its tool-calling format, every server had to adapt. If Anthropic updated its API schema, integrations broke. MCP converts this matrix into an N + M ecosystem: a tool author writes a single MCP server once, and it immediately functions across Claude Desktop, Cursor, Claude Code, and any MCP-compliant client.
For a hands-on tutorial configuring database servers, check our guide on connecting PostgreSQL to Claude via MCP.
MCP Architecture: Client, Host, and Server Topologies
The Model Context Protocol establishes clear architectural boundaries:
- MCP Host: The orchestrating application that the user interacts with (e.g., Claude Desktop, Cursor IDE). The host manages security boundaries, handles user approvals, and coordinates conversation history.
- MCP Client: A protocol connector inside the host application that maintains a 1-to-1 connection with a specific MCP server.
- MCP Server: A lightweight program that exposes specific capabilities (database introspection, file searching, API calls) through standardized protocol messages.
Supported Transport Layers: Stdio vs SSE
MCP supports two distinct transport protocols depending on deployment architecture:
- Standard I/O (stdio): The server runs as a local child process spawned by the client. Communication occurs via standard input and standard output streams. This is exceptionally fast (sub-millisecond latency) and avoids opening open network ports on user workstations.
- Server-Sent Events (SSE) over HTTP: The server runs as a remote web service. The client opens an HTTP connection to receive streaming server-to-client events and dispatches client-to-server requests via HTTP POST. This allows hosting centralized MCP servers within cloud VPCs.
The Three Core MCP Primitives
MCP abstracts all external interactions into three distinct capabilities:
- Resources (Passive Data): Read-only data streams that provide background context to the model without executing state changes. Examples include database schemas, application logs, or source code files.
- Tools (Executable Functions): Actions the model can invoke to perform computation or mutate external systems. Examples include running a SQL query, creating a Jira issue, or sending a Slack message. Tools require explicit schema definitions (JSON Schema) and can enforce human approval gates.
- Prompts (Structured Templates): Pre-engineered conversational workflows exposed by the server. Users can invoke them like slash commands (e.g.,
/review-pror/debug-incident).
Protocol Framing: JSON-RPC 2.0 Message Lifecycle
Under the hood, all MCP communication relies on standard JSON-RPC 2.0 frames sent line-by-line across stdio or HTTP SSE. When an MCP host initializes a server, it follows a three-stage handshake:
// 1. Client sends initialize request
{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2024-11-05",
"capabilities": {"roots": {"listChanged": true}},
"clientInfo": {"name": "ClaudeDesktop", "version": "1.0.0"}
}
}
// 2. Server replies with supported capabilities
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"protocolVersion": "2024-11-05",
"capabilities": {
"tools": {"listChanged": true},
"resources": {"subscribe": true}
},
"serverInfo": {"name": "PostgresMCPServer", "version": "0.5.2"}
}
}
// 3. Client confirms initialization
{
"jsonrpc": "2.0",
"method": "notifications/initialized"
}
Hands-On: Building a Custom Python FastMCP Server
Anthropic's official Python SDK includes FastMCP, a high-level framework modeled after FastAPI that allows building MCP servers with minimal boilerplate:
from mcp.server.fastmcp import FastMCP
import psutil
# 1. Initialize MCP server
mcp = FastMCP("DevOps System Inspector")
# 2. Expose a passive Resource (system telemetry)
@mcp.resource("system://metrics")
def get_system_metrics() -> str:
# Returns current CPU and RAM utilization
cpu = psutil.cpu_percent(interval=1)
ram = psutil.virtual_memory().percent
return f"CPU: {cpu}% | RAM: {ram}%"
# 3. Expose an active Tool (process termination)
@mcp.tool()
def kill_process(pid: int) -> str:
# Terminates an unresponsive local process by PID
try:
proc = psutil.Process(pid)
proc_name = proc.name()
proc.terminate()
return f"Process {proc_name} (PID: {pid}) terminated successfully."
except Exception as e:
return f"Error terminating process: {str(e)}"
if __name__ == "__main__":
mcp.run(transport="stdio")
To inspect this server using interactive diagnostic tools before deploying to Claude, see our troubleshooting instructions in the Claude Code CLI setup guide.
Containerizing MCP Servers for Production Isolation
In enterprise engineering teams, running MCP servers directly on developer workstations without isolation can create security vulnerabilities. If a server dependency is compromised, an attacker could access the user's home directory. The recommended deployment model is containerizing stdio servers inside unprivileged Docker containers:
{
"mcpServers": {
"isolated-sqlite": {
"command": "docker",
"args": [
"run", "--rm", "-i",
"--network", "none",
"--read-only",
"--user", "1000:1000",
"-v", "/opt/data/readonly.db:/data/db.sqlite:ro",
"mcp/sqlite:latest",
"/data/db.sqlite"
]
}
}
}
By enforcing --network none and --read-only, the container cannot reach the internet to exfiltrate data, nor can it mutate host files, providing defense-in-depth against malicious payloads.
Comparison: MCP vs Custom Tool Calling vs REST APIs
Here is how MCP compares against legacy integration approaches:
| Feature Dimension | Model Context Protocol (MCP) | Custom OpenAI Function Calling | Direct REST / OpenAPI |
|---|---|---|---|
| Portability | Universal (Claude, Cursor, Cline, etc.) | Vendor-locked to specific LLM API | Requires custom HTTP client code |
| Transport Types | Local stdio IPC & Remote SSE HTTP | HTTP JSON payloads only | HTTP/HTTPS REST |
| State Management | Standardized Resources + Tools | Manual prompt injection of context | Manual serialization |
| Human-in-the-Loop | Native approval modals in client UI | Requires custom frontend dialogs | Application-specific ACLs |
| Open Standard | Yes (Open source under MIT) | No (Proprietary spec) | Yes (OpenAPI Initiative) |
Security Considerations and Sandboxing
While MCP unlocks unprecedented agent autonomy, running arbitrary MCP servers introduces security challenges. Because servers can execute local shell commands or query private databases, operators must observe three security practices:
- Explicit Consent Gates: Claude Desktop requires user confirmation before executing any tool that performs mutations or connects to external networks. Never disable confirmation prompts on production databases.
- Read-Only Scoping: Whenever possible, pass read-only connection strings to database servers (e.g., PostgreSQL users with only
SELECTgrants). - Guard Against Indirect Injection: Malicious data returned by an MCP server can hijack the host LLM; read our security breakdown on Agent Data Injection defense.
To learn more about our open-source benchmarks and engineering standards, visit our About AI4SaaS page.
Frequently Asked Questions (FAQ)
Is the Model Context Protocol exclusive to Anthropic Claude?
No. While Anthropic created and open-sourced the protocol, MCP is completely model-agnostic. Open-source developers have implemented MCP clients for Cursor, Zed, Cline, Continue.dev, and local Ollama runtimes. Any LLM that supports tool calling can interface with MCP servers.
Can MCP servers run on a remote server across the internet?
Yes. By utilizing the Server-Sent Events (SSE) transport over HTTPS, MCP servers can run on AWS, Cloudflare Workers, or Google Cloud Run. Clients connect to the remote URL with bearer token authentication headers.
How does MCP handle large files or responses that exceed context windows?
MCP supports resource subscriptions and pagination. Instead of dumping an entire 100MB database table or log file into the prompt, the server exposes discrete chunks or statistical summaries, allowing the LLM to inspect only relevant subsets.
What languages can I use to write an MCP server?
Official SDKs exist for TypeScript/Node.js and Python. Additionally, the community has produced native implementations in Go, Rust, Kotlin, and C#.
Join the conversation