Skip to content
~/dipjyoti
Go back

Model Context Protocol The "USB-C" for AI

Anthropic’s Model Context Protocol: The “USB-C” for AI

In the rapidly evolving landscape of artificial intelligence, a significant bottleneck has emerged: the seamless integration of large language models (LLMs) with the vast universe of external data and tools. Each new integration has traditionally required bespoke, time-consuming engineering, creating a complex web of custom solutions. Enter Anthropic’s Model Context Protocol (MCP), a groundbreaking open standard poised to revolutionize how we build and interact with AI. Often hailed as the “USB-C for AI,” MCP offers a standardized, plug-and-play approach to connecting LLMs with the world around them.

This technical blog post delves deep into the intricacies of the Model Context Protocol. We will explore its core architecture, dissect its fundamental building blocks, and provide practical examples to illustrate its power. We will also compare it with existing context management techniques like Retrieval-Augmented Generation (RAG) and speculate on its profound implications for the future of AI development.

Why We Need a Standard?

Before MCP, connecting an LLM to a new data source or tool was a one-off, custom endeavor. An organization with ‘$N$’ LLM applications and ‘$M$’ external systems (databases, APIs, file systems, etc.) faced the daunting task of building and maintaining N \times M unique integrations. This “N x M problem” stifled innovation, increased development costs, and created a fragmented and unscalable AI ecosystem.

MCP elegantly solves this by introducing a universal protocol. Instead of building a custom bridge for each connection, developers can now create a single MCP-compliant “server” for each external system and a single MCP “client” for each LLM application. This transforms the N \times M problem into a much more manageable $N + M$ scenario, fostering a more interoperable and efficient AI landscape.

Under the Hood: The Core Architecture of MCP

At its heart, the Model Context Protocol operates on a client-host-server architecture, communicating via JSON-RPC 2.0 messages. This design promotes a clear separation of concerns, enhances security, and allows for a modular and scalable approach to AI application development.

MCP High-Level Architecture

graph TD
    User[👤 User] --> Host[🖥️ Host Application<br/>Claude Desktop, VS Code, etc.]
    Host <--> Client[🔌 MCP Client<br/>JSON-RPC 2.0]
    Client <--> Server[⚙️ MCP Server<br/>Tools, Resources, Prompts]
    Server --> DB[(🗄️ Database)]
    Server --> API[🌐 REST API]
    Server --> Files[📁 File System]
    Server --> Tools[🔧 External Tools]

    subgraph "Host Environment"
        Host
        Client
    end

    subgraph "External Systems"
        DB
        API
        Files
        Tools
    end

The MCP Workflow in Action

To truly understand how MCP works, let’s walk through a typical workflow, from a user’s query to the final, context-enriched response.

MCP Interaction Workflow

sequenceDiagram
    participant User
    participant Host as "Host (e.g., Claude)"
    participant LLM
    participant MCP Client as "MCP Client"
    participant MCP Server as "MCP Server"

    User->>Host: Enters prompt: "What's the weather like in Melbourne?"
    Host->>LLM: Sends prompt for analysis
    LLM-->>Host: Determines it needs a 'weather' tool
    Host->>MCP Client: Queries for available tools
    MCP Client->>MCP Server: Request available tools
    MCP Server-->>MCP Client: Returns schema for 'get_weather' tool
    MCP Client-->>Host: Provides tool schema
    Host->>LLM: Provides tool schema and user prompt
    LLM-->>Host: Generates request to call 'get_weather' with location="Melbourne"
    Host->>MCP Client: Send tool execution request
    MCP Client->>MCP Server: Execute get_weather(location="Melbourne")
    MCP Server->>MCP Server: Calls external weather API
    MCP Server-->>MCP Client: Returns result: {"temperature": "14°C", "condition": "Cloudy"}
    MCP Client-->>Host: Forwards tool result
    Host->>LLM: Provides tool result as context
    LLM-->>Host: Generates final response: "The weather in Melbourne is currently 14°C and cloudy."
    Host-->>User: Displays the final response

The Building Blocks of MCP: Primitives Explained

The power and flexibility of MCP stem from its core “primitives,” which define the types of capabilities that a server can offer.

Getting Your Hands Dirty: A Practical Implementation Guide

The best way to understand MCP is to see it in action. Let’s walk through a simplified example of how to create an MCP server using the official Python SDK. In this example, we’ll create a server with the simple “weather” tool from our workflow diagram.

First, ensure you have the Python SDK installed:

pip install model-context-protocol

Now, let’s write the server code:

weather_server.py

import asyncio
from model_context_protocol import (
    ContextProtocolServer,
    Tool,
    ToolCall,
    ToolResult,
    ToolSchema,
    Primitive,
)

# Define the schema for our tool. This tells the LLM what the tool is,
# what it does, and what parameters it accepts.
WEATHER_TOOL_SCHEMA = ToolSchema(
    name="get_current_weather",
    description="Get the current weather in a given location.",
    input_schema={
        "type": "object",
        "properties": {
            "location": {
                "type": "string",
                "description": "The city and state, e.g., San Francisco, CA",
            }
        },
        "required": ["location"],
    },
)

# This is the actual implementation of our tool.
# In a real application, this would call a weather API.
def get_weather_implementation(location: str) -> dict:
    """A mock implementation of the weather tool."""
    print(f"Fetching weather for {location}...")
    if "melbourne" in location.lower():
        return {"temperature": "14°C", "forecast": "Cloudy with a chance of rain"}
    else:
        return {"temperature": "22°C", "forecast": "Sunny"}

class WeatherTool(Tool):
    def get_schema(self) -> ToolSchema:
        return WEATHER_TOOL_SCHEMA

    async def execute(self, tool_call: ToolCall) -> ToolResult:
        location = tool_call.inputs.get("location")
        if not location:
            # Handle error case where location is not provided
            return ToolResult(
                tool_call_id=tool_call.tool_call_id,
                output={"error": "Location must be provided."},
                is_error=True
            )

        weather_data = get_weather_implementation(location)
        return ToolResult(tool_call_id=tool_call.tool_call_id, output=weather_data)


# Main function to set up and run the server
async def main():
    print("Starting weather MCP server...")
    server = ContextProtocolServer(
        # The list of primitives this server provides.
        primitives=[Primitive(id="weather_tool_1", implementation=WeatherTool())]
    )
    await server.run_forever()

if __name__ == "__main__":
    asyncio.run(main())

When you run this script (python weather_server.py), it starts a local MCP server. A host application like Claude Desktop can then discover this server, and the LLM can leverage the get_current_weather tool as described in the workflow diagram.

MCP vs. RAG: A Tale of Two Contexts

It’s common to wonder how MCP relates to Retrieval-Augmented Generation (RAG). While both aim to provide LLMs with external context, they operate differently and solve distinct parts of the problem.

FeatureRetrieval-Augmented Generation (RAG)Model Context Protocol (MCP)
Core IdeaRetrieve relevant documents from a vector database before calling the LLM.A real-time, interactive protocol for LLMs to use tools and access data during generation.
Workflow1. User Query -> 2. Retrieve -> 3. Augment Prompt -> 4. LLM Call1. User Query -> 2. LLM Call -> 3. LLM decides to use tool -> 4. MCP Call -> 5. LLM generates response.
InteractionStatic, one-way data push to the LLM.Dynamic, two-way interaction. The LLM can decide which tools to use and when.
Use CaseAnswering questions based on a large corpus of documents (e.g., a knowledge base).Enabling AI agents to perform actions, query live APIs, and interact with local files.
SynergyA RAG pipeline can be exposed as an MCP Tool or Resource for an agent to use.MCP can provide the framework for an LLM to decide to use a RAG system.

In short, RAG is a technique for data retrieval; MCP is a protocol for interaction. They are not mutually exclusive and can be powerfully combined.

The Future is Composable: Implications of MCP

The standardization proposed by MCP has far-reaching implications:

  1. A Composable AI Ecosystem: Developers will be able to build complex AI applications by assembling off-the-shelf MCP servers, much like building web applications with microservices.
  2. An “App Store” for AI Tools: We can envision a marketplace where developers can publish and monetize MCP servers that provide access to proprietary data or specialized tools.
  3. Enhanced Security and User Control: By standardizing the interaction layer, MCP provides clear points for implementing security policies, sandboxing, and fine-grained user consent for tool usage.
  4. Democratized AI Development: MCP lowers the barrier to entry for building sophisticated, context-aware AI applications, empowering a broader range of developers to innovate.

Conclusion

The Model Context Protocol is more than just a new API; it’s a foundational piece of infrastructure for the next generation of AI. By solving the N x M integration problem and providing a standardized way for LLMs to interact with the outside world, MCP paves the way for more capable, secure, and composable AI systems. Just as USB-C unified the world of physical connectors, MCP is poised to unify the world of AI integrations, unleashing a new wave of innovation in the process.


References


Share this post:

Previous Post
The Unseen Engine of Modern AI Agents: A Deep Dive into JSON-RPC
Next Post
Essential Mathematics for Better Programming