Frameworks & Tools / Integration Protocols

MCP

Intermediate [3/5]
Model Context Protocol Context protocol LLM integration standard

Definition

MCP (Model Context Protocol) is an open protocol developed by Anthropic that standardizes how LLM applications connect to external data sources and tools. It provides a universal way for AI assistants to access context from various systems without custom integrations for each.

MCP enables a "plug-and-play" approach where any MCP-compliant server can provide context to any MCP-compliant AI application, similar to how USB standardized device connections.

Key Concepts

  • Servers: Provide tools, resources, or prompts to clients
  • Clients: AI applications that consume MCP capabilities
  • Resources: Data that servers expose (files, DB records, etc.)
  • Tools: Functions the AI can invoke through servers

Examples

Architecture
MCP Protocol Structure
MCP ARCHITECTURE: ┌─────────────────────────────────────────────────┐ │ AI APPLICATION (Client) │ │ ┌───────────────────────────────────────────┐ │ │ │ Claude, ChatGPT, etc. │ │ │ └───────────────────────────────────────────┘ │ │ │ │ │ MCP Protocol │ │ │ │ │ ┌─────────────────┼─────────────────┐ │ │ ▼ ▼ ▼ │ │ ┌───────────┐ ┌───────────┐ ┌───────────┐ │ │ │ GitHub │ │ Database │ │ File │ │ │ │ Server │ │ Server │ │ Server │ │ │ └───────────┘ └───────────┘ └───────────┘ │ └─────────────────────────────────────────────────┘ MCP CAPABILITIES: 1. TOOLS - Functions the AI can call: - github.create_issue() - database.query() - filesystem.read_file() 2. RESOURCES - Data the AI can access: - file:///project/README.md - db://users/profile/123 - github://repo/issues 3. PROMPTS - Reusable prompt templates: - "Analyze this code for security issues" - "Summarize these database records" --- BEFORE MCP (Custom integrations): ┌──────────┐ Custom API ┌──────────┐ │ App │─────────────────────│ GitHub │ └──────────┘ └──────────┘ │ │ Custom API ┌──────────┐ └───────────────────────────│ Slack │ │ └──────────┘ │ Custom API ┌──────────┐ └───────────────────────────│ Notion │ └──────────┘ Problem: N apps × M integrations = N×M work! AFTER MCP (Standardized): ┌──────────┐ ┌──────────┐ │ App A │───┐ │MCP Server│─GitHub └──────────┘ │ └──────────┘ │ Standard ┌──────────┐ ┌──────────┐ ├── MCP ─────────│MCP Server│─Slack │ App B │───┤ Protocol └──────────┘ └──────────┘ │ ┌──────────┐ │ │MCP Server│─Notion ┌──────────┐ │ └──────────┘ │ App C │───┘ └──────────┘ Benefit: Any app can use any server!
Implementation
Building an MCP Server
MCP SERVER EXAMPLE (Python): from mcp.server import Server from mcp.types import Tool, Resource # Create MCP server server = Server("my-data-server") # Define a tool @server.tool() async def search_documents(query: str) -> str: """Search internal documents for information.""" results = await vector_db.search(query) return format_results(results) # Define a resource @server.resource("docs://{doc_id}") async def get_document(doc_id: str) -> str: """Retrieve a specific document by ID.""" doc = await db.get_document(doc_id) return doc.content # Run the server if __name__ == "__main__": server.run() --- CLIENT USAGE: When user asks: "What's in our Q3 report?" 1. AI recognizes need for internal data 2. AI calls MCP tool: search_documents("Q3 report") 3. MCP server searches vector DB 4. Results returned to AI 5. AI synthesizes response --- MCP CONFIGURATION (Claude Desktop): { "mcpServers": { "filesystem": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-filesystem", "/Users/me/projects"] }, "github": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-github"], "env": { "GITHUB_TOKEN": "ghp_xxxx" } }, "postgres": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-postgres", "postgresql://localhost/mydb"] } } } --- COMMON MCP SERVERS: ┌─────────────────┬──────────────────────────────┐ │ Server │ Capabilities │ ├─────────────────┼──────────────────────────────┤ │ Filesystem │ Read/write local files │ │ GitHub │ Issues, PRs, repos │ │ Postgres/SQLite │ Database queries │ │ Slack │ Messages, channels │ │ Google Drive │ Docs, sheets, files │ │ Memory │ Persistent AI memory │ │ Puppeteer │ Web browsing/scraping │ └─────────────────┴──────────────────────────────┘

Interactive Exercise

Design an MCP Server

You're building an MCP server for a project management tool (like Jira). What tools and resources would you expose? Think about what an AI assistant would need to help users manage their projects.

Pro Tips
  • Design tools around user intents, not raw API operations
  • Resources should be URI-addressable for easy reference
  • Include good descriptions - AI uses them to decide when to call tools
  • Consider security: what should the AI be allowed to do?

Related Terms