AI Engineer In 10 Weeks | Model Context Protocol (MCP)
Overview: Model Context Protocol (MCP) is an open standard created by Anthropic in 2024 to standardize how Large Language Models (LLMs) connect to external tools, APIs, and data sources. By replacing custom, hardcoded API wrappers with a universal communication layer, MCP enables dynamic tool discovery, prevents code bloat, and eliminates breaking changes when underlying tool schemas evolve.
1. Real-World Analogy: The Multi-Language Household Dilemma
To understand why MCP was invented, consider the friction involved when integrating components that communicate using different rules and languages.
The Scenario
Imagine hiring household help:
- Driver: The driving agency provides a driver who handles all vehicles (from a Nano to a Ferrari). However, the driver speaks only French. To direct her, you are forced to learn French.
- Cook: The culinary agency sends a cook who prepares both vegetarian and non-vegetarian dishes. But he speaks only Japanese. To order meals, you must learn Japanese.
- Cleaner: The housekeeping agency sends a cleaner who speaks only German. To give instructions, you must learn German.
The Breakdown
After learning French, Japanese, and German, the cook agency calls to inform you that the Japanese cook is being replaced by a new cook who speaks only Chinese. You are expected to learn Chinese to keep receiving meals.
The Solution
Instead of forcing the employer to continuously learn custom languages for every worker, a universal standard is established: English. Every incoming worker is required to translate their specialized skill instructions into English. The employer communicates exclusively in English, achieving immediate interoperability across all services.
Analogy Mapping:
- Employer = LLM Client (Claude, ChatGPT, Gemini, Grok)
- Household Workers = External Tools / APIs (Tavily Search, Gmail, Slack, GitHub)
- Custom Languages = Tool-specific API syntaxes, headers, and parameters
- Universal Language (English) = Model Context Protocol (MCP)
2. Tool Integration Before MCP (The Naive Approach)
In basic AI Agent architectures, connecting an LLM to external functionality (such as web search or calculators) requires writing custom integration functions directly within the application codebase.
When building an AI agent, developers manually wrap third-party APIs using specific syntax and argument requirements:
# Naive approach: Manual integration wrapper for Tavily Search API
import requests
def tavily_search(query: str, max_results: int = 5) -> dict:
"""
Directly bound tool integration.
Requires developer to know Tavily's exact API endpoints, headers, and params.
"""
url = "https://api.tavily.com/search"
headers = {"Authorization": "Bearer YOUR_API_KEY"}
payload = {
"query": query,
"max_results": max_results,
"search_depth": "advanced"
}
response = requests.post(url, json=payload, headers=headers)
return response.json()
While manageable for a local project with 1–2 tools, this approach scales poorly when applied to production AI platforms.
3. Core Flaws of Hardcoded Tool Integrations
Flaw 1: Code Bloat & Maintenance Bottlenecks
There are millions of tools available across the internet—YouTube analytics, Slack messaging, Gmail senders, database connectors, and custom search engines.
- If platform developers (e.g., Anthropic building Claude) wrote custom Python functions for every integrated service, the core codebase would swell by millions of lines of integration glue code.
- Model developers would spend all their engineering resources maintaining tool wrappers rather than improving model capabilities.
Flaw 2: API Drift and Cascading Production Failures
External tool APIs are owned by third-party companies, not the LLM creators.
- If Tavily alters its API endpoint parameters (e.g., reducing required arguments from 3 to 2), any hardcoded wrapper expecting the old parameter signature fails instantly in production.
- To recover, the LLM developer must push a software patch or release a hotfix version (e.g., upgrading from version 5.5 to 5.6) just to adjust to a third-party parameter update.
4. What is Model Context Protocol (MCP)?
Created by Anthropic in 2024, Model Context Protocol (MCP) is an open communication standard that defines how LLM clients and tool providers exchange data.
Definition: MCP is a universal interface contract that allows LLMs to query external servers about available tools, read their exact schemas dynamically, and request execution—without the LLM client maintaining hardcoded knowledge of the tool's underlying API code.
Key Conceptual Transition
- Before MCP: The LLM Client must know how every tool is implemented.
- With MCP: The LLM Client simply asks an MCP Server what tools it provides and how to invoke them according to standard JSON schemas.
5. Mental Model: The Universal Restaurant Ordering Protocol
To see how standard protocols solve interface complexity, examine the global restaurant industry.
Real-Life Analogy: The Universal Restaurant Protocol
Across the world, there are thousands of restaurants (KFC, Domino's, local diners). Every restaurant has a different menu, unique recipes, and different kitchen implementations.
Despite these internal differences, you do not need to take a training course to order food when entering a new restaurant. Every restaurant abides by a universal Ordering Protocol:
Customer enters Restaurant
|
| 1. Request Menu
v
Waitstaff provides Menu (Lists available dishes & prices)
|
| 2. Select Dish & Provide Specific Arguments (e.g., "1 Burger, No Onions")
v
Kitchen prepares order internally
|
| 3. Serve Dish & Process Payment
v
Customer receives completed meal
No restaurant requires customers to perform custom prerequisites—such as washing dishes or dancing—before placing an order. The interaction contract is identical across all establishments.
MCP applies this exact interaction protocol to LLMs and software tools.
6. Architecture & Dynamic Tool Discovery Flow
Under MCP, tools are isolated inside independent process endpoints called MCP Servers. Tools manage their own execution logic, while the LLM client acts as the consumer interacting through standardized messages.
Browser / User
|
| User Prompt: "Search Tavily for latest AI news"
v
LLM Client (e.g., Claude Desktop, Custom Agent Application)
|
| 1. Query Tools: list_tools()
v
MCP Server (e.g., Tavily MCP Server Endpoint)
|
| 2. Returns JSON Schema:
| - Tool Name: "tavily_search"
| - Arguments: {"query": "string", "search_depth": "string"}
v
LLM Client evaluates prompt against schema
|
| 3. Invokes Tool: execute_tool("tavily_search", {"query": "AI news"})
v
MCP Server executes tool internally
|
| 4. Returns JSON Response Data
v
LLM Client formats answer for User
7. Direct Code Comparison: Hardcoded vs. MCP Pattern
Legacy / Hardcoded Pattern
In a traditional setup, the client application explicitly builds and maintains tool-specific network requests:
# Legacy / Rigid Tool Call
class HardcodedAgent:
def execute_tavily(self, query: str) -> dict:
# Heavily coupled to Tavily's direct API endpoint structure
return requests.post(
"https://api.tavily.com/search",
json={"query": query, "api_key": "secret"}
).json()
Standardized MCP Pattern
In an MCP setup, the client interacts dynamically with any host using the standard protocol SDK. The tool provider implements the server logic:
# Standardized MCP Server Pattern (Conceptual Implementation)
from mcp.server import Server
app = Server("tavily-mcp-server")
@app.list_tools()
async def handle_list_tools():
"""
Exposes tool discovery schema dynamically to any connecting LLM Client.
"""
return [
{
"name": "tavily_web_search",
"description": "Performs web search using Tavily Search API",
"inputSchema": {
"type": "object",
"properties": {
"query": {"type": "string", "description": "Search query keywords"},
"search_depth": {"type": "string", "enum": ["basic", "advanced"]}
},
"required": ["query"]
}
}
]
@app.call_tool()
async def handle_call_tool(name: str, arguments: dict):
"""
Executes tool locally within the server when requested by the LLM Client.
"""
if name == "tavily_web_search":
# Internal API execution isolated inside the provider's server
result = execute_tavily_internal(
query=arguments["query"],
depth=arguments.get("search_depth", "basic")
)
return [{"type": "text", "text": str(result)}]
8. Architectural Comparison Matrix
9. Real-World Maintenance & Production Workflows
Scenario: Updating Tool Schemas in Production
If a service provider (e.g., Tavily) deprecates an old field and introduces a new mandatory parameter:
- Service Provider Update: Tavily updates its own MCP Server code to reflect the new JSON schema requirements.
- Dynamic Client Sync: When the LLM Client sends its standard
list_tools()request on the next interaction, the MCP Server returns the updated parameter schema. - Automatic Adaptation: The LLM reads the updated JSON schema, formats its arguments accordingly, and executes the call.
- Outcome: The platform maintains zero downtime. The client application requires no code edits, hotfixes, or redeployments.
10. Summary and Key Takeaways
- Universal Standard: MCP is an open communication protocol released by Anthropic in 2024 to standardise interactions between LLM clients and external software tools.
- Solves Scalability: Eliminates the need to write millions of custom function wrappers for every tool available on the internet.
- Prevents API Drift Failures: Tools manage their internal API signatures inside MCP Servers. When a tool changes, only its MCP Server is updated; LLM client code remains unchanged.
- Dynamic Tool Discovery: LLMs query MCP Servers dynamically (
list_tools()) at runtime to discover capabilities, parameter schemas, and argument types. - The Universal Language Analogy: MCP acts like establishing English as a universal language for household workers—tool builders translate specialized functionality into standardized MCP responses.
- The Restaurant Protocol Analogy: Like ordering from a menu at any restaurant, MCP standardizes tool interaction into three steps: request options, send execution arguments, and receive output.
- Ecosystem Adoption: MCP provides a shared contract for both tool developers and LLM providers, ensuring seamless interoperability across the AI agent ecosystem.