Model Context Protocol (MCP)
What is MCP?
Section titled “What is MCP?”Model Context Protocol is an open standard that lets AI models (like Claude) connect to external tools, databases, and APIs through a unified interface.
Think of it as a USB standard for AI — any MCP-compatible client can talk to any MCP server.
Architecture
Section titled “Architecture”Claude (MCP Client) ↕ MCP ProtocolMCP Server ↕Your Tools / APIs / DatabasesMCP Server Capabilities
Section titled “MCP Server Capabilities”| Type | Description | Example |
|---|---|---|
| Tools | Functions the AI can call | Run SQL query, send email |
| Resources | Data the AI can read | File contents, DB records |
| Prompts | Reusable prompt templates | Summarize document |
Building a Simple MCP Server (Python)
Section titled “Building a Simple MCP Server (Python)”from mcp.server import Serverfrom mcp.server.stdio import stdio_serverfrom mcp import types
app = Server("my-server")
@app.list_tools()async def list_tools(): return [ types.Tool( name="get_weather", description="Get current weather for a city", inputSchema={ "type": "object", "properties": { "city": {"type": "string"} }, "required": ["city"] } ) ]
@app.call_tool()async def call_tool(name: str, arguments: dict): if name == "get_weather": city = arguments["city"] # call your weather API here return [types.TextContent(type="text", text=f"Sunny in {city}, 28°C")]
async def main(): async with stdio_server() as (read, write): await app.run(read, write, app.create_initialization_options())Configuring MCP in Claude Code
Section titled “Configuring MCP in Claude Code”Add to ~/.claude/settings.json:
{ "mcpServers": { "my-server": { "command": "python", "args": ["/path/to/server.py"] } }}Common MCP Servers
Section titled “Common MCP Servers”- filesystem — read/write local files
- postgres — query PostgreSQL databases
- github — interact with GitHub repos
- fetch — fetch web pages
- sqlite — query SQLite databases