DEV Community

丁久
丁久

Posted on • Originally published at dingjiu1989-hue.github.io

MCP (Model Context Protocol) Complete Guide: The Standard Connecting AI to Your Tools

This article was originally published on AI Study Room. For the full version with working code examples and related articles, visit the original post.

MCP (Model Context Protocol) Complete Guide: The Standard Connecting AI to Your Tools

Every AI application needs to talk to external systems — databases, APIs, file systems, search engines. Before 2025, every integration was custom: write a LangChain tool, build a custom function call, hack together a plugin. It was like the pre-USB era where every device had its own cable.

MCP (Model Context Protocol) changes that. It's an open protocol that standardizes how AI models connect to external tools and data sources — one protocol, any LLM, any tool.

What Is MCP?

MCP is an open standard (originally developed by Anthropic) that defines how AI applications discover and call external tools. Think of it as USB-C for AI integrations — a universal connector that any MCP-compatible client can use to talk to any MCP-compatible server.

┌─────────────────┐     ┌────────────────┐     ┌─────────────────┐
│  MCP Client     │◄───►│  MCP Protocol  │◄───►│  MCP Server     │
│  (Claude, VS    │     │  (JSON-RPC     │     │  (DB connector, │
│   Code, Cursor) │     │   over stdio   │     │   file system,  │
│                 │     │   or SSE)      │     │   search, API)  │
└─────────────────┘     └────────────────┘     └─────────────────┘
Enter fullscreen mode Exit fullscreen mode

The key insight: MCP decouples tool implementation from the AI client. A single MCP server written once works with Claude Desktop, VS Code extensions, Cursor, and any other MCP-compatible client. No more "write this tool for LangChain, rewrite it for OpenAI, rewrite it for Claude."

Architecture

MCP has four core concepts:

1. Host (Client Application)

The AI-powered application the user interacts with: Claude Desktop, VS Code, Cursor, a custom chat app.

2. Client (MCP Client)

A lightweight transport layer inside the host that manages connections to MCP servers. It speaks the MCP protocol over the wire.

3. Server (MCP Server)

A lightweight service that exposes resources and tools through MCP. Each server is focused on one domain: filesystem access, database queries, API integrations.

4. Protocol

The standard JSON-RPC message format that clients and servers use to communicate. Two transport modes:

  • stdio: Server runs as a subprocess, communication over stdin/stdout (simple, secure)
  • SSE (Server-Sent Events): Network-based, for remote servers

Communication Flow

User: "Find all bugs assigned to me"
    │
    ▼
Host (Claude Desktop)
    │  MCP Client asks servers for available tools
    ▼
MCP Server (GitHub) ───► Returns: list_issues, get_repo, search_code
    │
    ▼
LLM decides: call list_issues with assignee:me
    │
    ▼
MCP Server executes GitHub API call
    │
    ▼
Returns issue data to LLM
    │
    ▼
Host shows: "Found 3 bugs assigned to you:..."
Enter fullscreen mode Exit fullscreen mode

MCP vs Alternatives

Feature MCP OpenAI Function Calling LangChain Tools Custom API
Standardized ✅ Open standard ❌ OpenAI-only ❌ LangChain-only ❌ Custom
Cross-client ✅ Any MCP client ❌ OpenAI API only ❌ LangChain only ❌ One app only
Tool discovery ✅ Auto-discover tools ✅ Schema-based ✅ Defined in code ❌ Hard-coded
Dynamic resources ✅ Yes (file system, DB) ❌ No ❌ No ❌ No
Security model ✅ Host controls permissions ⚠️ Per-call ⚠️ Per-call ⚠️ Per-call
Async/long-running ✅ Notifications, progress ❌ Request-response only ❌ Request-response only ⚠️ Depends
Ecosystem Growing fast Mature but narrow Good None
Setup complexity Low Low Medium High

Why MCP Wins

Before MCP: Every AI tool integration was bespoke

  • VS Code extension for GitHub ← custom code
  • Claude Desktop for database queries ← one-off Python script
  • Cursor for file operations ← built-in, not extensible
  • Custom chatbot for search ← another custom tool

With MCP: Write once, use everywhere

  • One GitHub MCP server works in Claude Desktop, VS Code, Cursor
  • One PostgreSQL MCP server works in any host
  • One filesystem MCP server works everywhere

How to Build an MCP Server

The MCP SDK (available for Python, TypeScript, Java, and Go) makes building a server trivial. Here's a complete example in Python:

Python MCP Server


python
# server.py
from mcp.server import Server
from mcp.types import Tool, TextContent
import httpx
import json

app = Server("weather-server")

@app.list_tools()
async def list_tools() -> list[Tool]:
    return [
        Tool(
            name="get_weather",
            description="Get current weather for a city",
            input_schema={
                "type": "object",
                "properties": {
                    "city": {"type": "string", "description": "City name"}
                },
                "required": ["city"],
            },
        )
    ]

@app.call_tool()
async def call_tool(name: str, arguments: dict) -> list[TextContent]:
    if name =

---

**Read the full article on [AI Study Room](https://dingjiu1989-hue.github.io/en/ai/mcp-complete-guide.html)** for complete code examples, comparison tables, and related resources.

*Found this useful? Check out more [developer guides and tool comparisons](https://dingjiu1989-hue.github.io/en/) on AI Study Room.*
Enter fullscreen mode Exit fullscreen mode

Top comments (0)