Understanding the Model Context Protocol (MCP): A Developer's Quickstart
Until recently, connecting large language models (LLMs) to local tools and private databases required building custom integrations for every specific IDE, web app, or workflow. The **Model Context Protocol (MCP)**, open-sourced by Anthropic, resolves this issue. Much like how the Language Server Protocol (LSP) standardized syntax checking across editors, MCP standardizes how AI agents securely access data, run scripts, and interact with software tools.
What is the Model Context Protocol?
MCP is an open standard client-server protocol. It establishes a secure channel for AI models (running inside a local client or host) to discover, inspect, and execute capabilities provided by a local or remote server.
The Three Pillars of MCP Architecture
- Host / Application: The development environment or platform where the AI logic lives (e.g., Claude Desktop, Cursor, Windsurf, or a custom LLM orchestration backend).
- Client: The protocol implementation inside the host that negotiates communication and enforces user permissions.
- Server: A lightweight program that exposes specific data sources (databases, folders) or computational tools (compilers, calculators, shell runners) to the client.
How MCP Works in Practice
MCP communicates over JSON-RPC. When an AI client connects to an MCP server, it asks the server what capabilities it supports. The server replies with three types of resources:
- Prompts: Pre-built prompt templates that help guide the user's interaction with the model (e.g., "Review this SQL schema").
- Resources: Read-only data feeds. These can be local file contents, live database schemas, logs, or API responses.
- Tools: Executable functions that the model can run (with user approval), such as executing code, performing a web search, or writing a file.
Building a Simple Python MCP Server
Writing an MCP server is straightforward. Anthropic provides SDKs in Python and TypeScript. Below is a simple Python MCP server that provides a mathematical computation tool.
1. Setup Dependencies
Create a directory and install the python-mcp SDK:
pip install mcp
2. Write the Server Logic (server.py)
Create a file named server.py and add the following code:
from mcp.server.fastmcp import FastMCP
# Initialize FastMCP server
mcp = FastMCP("CalculatorService")
@mcp.tool()
def calculate_fibonacci(n: int) -> str:
"""Calculate the nth Fibonacci number."""
if n < 0:
return "Error: n must be a positive integer."
elif n == 0:
return "0"
elif n == 1:
return "1"
a, b = 0, 1
for _ in range(2, n + 1):
a, b = b, a + b
return f"The {n}th Fibonacci number is {b}."
if __name__ == "__main__":
mcp.run()
Integrating Your Server with Claude Desktop
To hook up this new service to Claude Desktop, you must add it to your local MCP configuration file. This config file is located at:
- Windows:
%APPDATA%\Claude\claude_desktop_config.json - macOS:
~/Library/Application Support/Claude/claude_desktop_config.json
Open this file and add your server to the mcpServers block:
{
"mcpServers": {
"calculator": {
"command": "python",
"args": ["C:/path/to/your/server.py"]
}
}
}
Restart Claude Desktop. You will see a new hammer icon, indicating the model has access to your custom Calculator tool. When you ask Claude to calculate a high Fibonacci number, it will route the request to your local Python server, run the calculation, and return the correct result.
Security Best Practices
Because MCP tools can run terminal commands and read files on your local machine, security is critical:
- Enforce User Approvals: Clients should always prompt the user before running write-based or destructive tools (e.g., executing a terminal command or writing a file).
- Restrict Directory Access: If building a filesystem server, validate that input paths are constrained within a safe workspace directory to prevent path traversal attacks.
- Use Environment Variables: Never hard-code API keys inside your server code. Pass them via the client configuration using the `env` parameter.
The Verdict
MCP represents a massive shift in how AI models interact with the physical world. Instead of writing custom plugins for every IDE, developers can write a single MCP server in Node.js or Python and immediately expose their tools to Claude Code, Cursor, Windsurf, and any future client that adopts the standard.