Concept #77Mediumextended-ai-concepts

What is MCP (Model Context Protocol)?

#gen-ai#mcp

Answer

What is MCP (Model Context Protocol)?

MCP (Model Context Protocol) is an open standard developed by Anthropic that defines how AI models connect to external tools, data sources, and services. It's the "USB standard for AI" — a universal interface for LLMs to interact with the world.

Core Problem MCP Solves

text
Before MCP:
  Claude → Custom code → Tool A
  Claude → Custom code → Tool B
  GPT-4  → Custom code → Tool A  (different custom code!)

With MCP:
  Any AI client → MCP Protocol → [Tool A, Tool B, Tool N...]

Architecture

text
ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”    MCP (JSON-RPC)    ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
│  MCP Client │ ←──────────────────→ │   MCP Server    │
│  (Claude,   │                      │  (Tool provider) │
│   Cursor,   │                      │  - File system  │
│   IDE...)   │                      │  - Database     │
ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜                      │  - APIs         │
                                     ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜

What MCP Servers Expose

CapabilityDescriptionExample
ToolsFunctions AI can call
text
search_web
,
text
run_sql
,
text
write_file
ResourcesData AI can readFiles, database records, API responses
PromptsReusable prompt templates
text
code-review-checklist

Simple MCP Server

python
from mcp.server import Server
from mcp.server.stdio import stdio_server
import mcp.types as types

app = Server("weather-server")

@app.list_tools()
async def list_tools():
    return [types.Tool(
        name="get_weather",
        description="Get 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":
        return [types.TextContent(type="text",
            text=f"Weather in {arguments['city']}: 22°C, sunny")]

async def main():
    async with stdio_server() as (read, write):
        await app.run(read, write, app.create_initialization_options())

Configure Claude to Use MCP Servers

json
{
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-filesystem", "/Users/me/projects"]
    },
    "github": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-github"],
      "env": {"GITHUB_TOKEN": "ghp_..."}
    }
  }
}

Popular MCP Servers

ServerCapability
FilesystemRead/write local files
GitHubRepos, PRs, issues
PostgresSQL queries
Brave SearchWeb search
Context7Live library docs
PlaywrightBrowser automation
SlackSend/read messages

Key Benefits

  • Security — AI only accesses what MCP servers explicitly expose
  • Standardization — one protocol works across Claude, Cursor, and other clients
  • Composability — combine multiple MCP servers for rich tool access
  • Open source — anyone can publish MCP servers