MCP: Model Context Protocol
MCP is an open standard (launched by Anthropic in Nov 2024) that gives AI apps a common way to connect to external tools and data. It is called "USB-C for AI": build an MCP server once and it works in Claude, Claude Code, IDEs and other AI clients.
13.1 Architecture
- Step 1
1.MCP Host: Claude Desktop, Claude Code, IDE
- Step 2
2.MCP Client: inside the host, one connection per server
- Step 3
3.MCP Server: GitHub, DB, Slack, filesystem...
- Step 4
4.Data source / API: the real system where the data lives
Messages travel in JSON-RPC 2.0 format
13.2 MCP primitives
| Primitive | Who controls it | What it is | Example |
|---|---|---|---|
| Tools | Model | Functions the model calls | create_issue, run_query |
| Resources | Application | Read-only data/context (by URI) | File content, DB schema |
| Prompts | User | Reusable prompt templates (like slash commands) | /review-pr |
| Sampling (client feature) | Server makes the request | Server asks the client's LLM for a completion | Server needs an AI summary |
| Roots (client feature) | Client | Which folders/URIs the server may work in | Project directory |
| Elicitation (client feature) | Server | Asking the user for extra input midway | "Which branch?" |
13.3 Transports
| Transport | When | Detail |
|---|---|---|
| stdio | Local server | The host runs it as a child process; they talk over stdin/stdout |
| Streamable HTTP | Remote server | HTTP POST + optional SSE streaming; auth via OAuth |
| SSE (old) | Legacy | Deprecated; use Streamable HTTP |
13.4 Your own MCP server (Python)
Python
# pip install "mcp[cli]"from mcp.server.fastmcp import FastMCP mcp = FastMCP("employee-db") @mcp.tool()def get_salary(emp_id: int) -> str: """Get the salary by employee ID.""" return db_lookup(emp_id) @mcp.resource("schema://employees")def schema() -> str: """Schema of the employees table.""" return "Id INT, Name NVARCHAR(100), Salary DECIMAL(18,2)" if __name__ == "__main__": mcp.run() # default transport: stdio13.5 Connecting MCP
Terminal
# Local (stdio) server in Claude Codeclaude mcp add employee-db -- python server.py # Remote HTTP serverclaude mcp add --transport http github https://api.githubcopilot.com/mcp/ claude mcp list # connected servers# Project scope: commit the .mcp.json file to the repo and the whole team gets itPython
# Remote MCP server straight from the Messages API (MCP connector, beta)r = client.beta.messages.create( model="claude-opus-5-5", max_tokens=4000, betas=["mcp-client-2025-11-20"], mcp_servers=[{"type": "url", "url": "https://example.com/mcp", "name": "crm"}], tools=[{"type": "mcp_toolset", "mcp_server_name": "crm"}], # both halves are required messages=[{"role": "user", "content": "Show the top 5 open deals"}],)