Understanding Model Context Protocol (MCP) Servers: A Deep Dive

Sarvottam BhagatSarvottam Bhagat
10 min read

In the fast-changing world of Artificial Intelligence, it's crucial for AI models to easily connect with external tools, resources, and environments. This is where the Model Context Protocol (MCP) is important. MCP serves as a universal connector, standardizing how AI systems access and use external capabilities, similar to how USB-C transformed connectivity for electronic devices.

This blog post will demystify MCP servers, explore their core components, and demonstrate their practical application through a curated development stack. We'll delve into why MCP was created, how it addresses common integration challenges, and how it empowers AI models to achieve more.

What is MCP?

  • The Model Context Protocol (MCP) is a standardized interface and framework.

  • It allows AI models to interact smoothly with external tools, resources, and environments.

  • MCP acts like a universal translator for AI, enabling communication with diverse capabilities through one interface.

  • Without MCP, AI would need to learn each external system individually, which is inefficient.

  • Large Language Models (LLMs) have strong knowledge and reasoning but are limited to their initial training data.

  • To access real-time information or perform real-world actions, LLMs need to connect with external tools and resources.

  • Before MCP, integrating these external functions was complex and required custom solutions, causing significant development challenges.

Why was MCP Created? The M x N Problem

Before the advent of MCP, integrating AI models with external tools and data sources was a significant challenge. This was often referred to as the "M x N integration problem." If you had 'M' different AI applications and 'N' different tools or data sources, you would typically need to create M × N custom integrations. Each AI model would require unique code to connect to each external service, leading to a complex and unmanageable web of interconnections.

This approach was not scalable. Developers were constantly reinventing the wheel, and tool providers had to support multiple incompatible APIs to reach different AI platforms. This fragmented landscape hindered the rapid development and deployment of AI applications that could leverage external functionalities.

MCP addresses this by introducing a standard interface. Instead of M × N direct integrations, MCP simplifies this to M + N implementations. Each of the M AI applications implements the MCP client side once, and each of the N tools implements an MCP server once. This means everyone speaks the same "language," drastically simplifying connections and enabling seamless communication between AI models and external capabilities.

AI Agent vs. MCP

To further illustrate the problem MCP solves, consider the distinction between a standalone AI Agent and an MCP-enabled system. An AI Agent, while capable of autonomous action and task delegation, often relies on direct API calls and internal logic to interact with its environment. This can lead to the M x N problem described earlier.

In contrast, an MCP system introduces a standardized protocol between the AI Agent (or Host/Client) and various MCP Servers. This abstraction layer allows for a more modular and scalable architecture, where new tools and resources can be integrated without requiring extensive modifications to the AI Agent itself. The following diagram highlights this difference:

AI Agent Versus MCP

MCP Architecture Overview

At its heart, MCP follows a client-server architecture, similar to how the web operates. However, the terminology is tailored to the AI context, with three main roles:

Host

The Host is the user-facing AI application. This is the environment where the AI model lives and interacts with the user. Examples include chat applications like OpenAI's ChatGPT or Anthropic's Claude desktop app, AI-enhanced Integrated Development Environments (IDEs) like Cursor, or any custom application embedding an AI assistant. The Host initiates connections to available MCP servers when needed, captures user input, maintains conversation history, and displays the model's replies.

Client

The MCP Client is a component within the Host that manages the low-level communication with an MCP Server. It acts as an adapter or messenger. While the Host decides what to do, the Client knows how to speak the MCP language to carry out those instructions with the server.

Server

The MCP Server is an external program or service that provides capabilities (tools, data, etc.) to the application. An MCP Server wraps specific functionalities, exposing a set of actions or resources in a standardized way that any MCP Client can invoke. Servers can run locally on the same machine as the Host or remotely in the cloud, as MCP is designed to support both scenarios seamlessly. The server advertises its capabilities in a standard format, executes requests from the client, and returns results.

Core Capabilities of an MCP Server: Tools, Resources, and Prompts

Within the MCP framework, capabilities are the features or functions that an MCP server makes available. These are categorized into three core types:

Tools

Tools are executable actions or functions that the AI (via the host/client) can invoke. These typically involve operations that can have side effects or require computation beyond the AI's own capabilities, often involving external API calls. The AI model usually triggers tools when it determines that specific functionality is needed.

For example, an MCP server might expose a get_weather tool. When the AI needs weather information for a specific location, it can call this tool, and the server will execute the underlying function (e.g., making an API call to a weather service) and return structured data (like temperature and conditions) to the AI. Since tools can perform actions like file I/O or network calls, MCP implementations often require user permission for tool calls to ensure human control over powerful actions.

# Example of a simple weather tool in an MCP server
@mcp.tool()
def get_weather(location: str):
    """Fetches the current weather for a given location.

    Args:
        location (str): The city or region to get weather for.

    Returns:
        dict: A dictionary containing weather information (e.g., temperature, conditions).
    """
    # In a real scenario, this would call an external weather API
    if location == "San Francisco":
        return {"temperature": "15°C", "conditions": "Cloudy"}
    else:
        return {"temperature": "N/A", "conditions": "Unknown"}

# When the AI calls tools/call with name "get_weather" and {"location": "San Francisco"}
# the server executes get_weather("San Francisco") and returns the result.

Resources

Resources provide read-only data to the AI model. These are akin to databases or knowledge bases that the AI can query for information without modifying them. Unlike tools, resources typically do not involve heavy computation or side effects, as they are primarily for information lookup. Resources are often accessed under the host application's control, meaning the application decides when to fetch specific context for the model.

For instance, if a user asks a question that requires information from a company handbook, the Host might call a resource that retrieves relevant sections of the handbook and feeds them to the model. Resources can include local file contents, snippets from knowledge bases, read-only database query results, or any static data like configuration information. While read-only, privacy and permissions are still crucial considerations to ensure the AI only accesses authorized data.

# Example of a simple file reading resource in an MCP server
@mcp.resource("file://{path}")
def read_file(path: str):
    """Reads the content of a local file.

    Args:
        path (str): The absolute path to the file.

    Returns:
        str: The content of the file.
    """
    try:
        with open(path, "r") as f:
            return f.read()
    except FileNotFoundError:
        return "File not found."

# The AI (or Host) could ask the server for resources.get with a URI like
# file://home/user/notes.txt, and the server would call read_file("/home/user/notes.txt")
# and return the text.

Prompts

Prompts in the MCP context are predefined prompt templates or conversation flows that can be injected to guide the AI's behavior. They provide a canned set of instructions or an example dialogue to steer the model for specific tasks. This capability is useful for recurring patterns, such as setting up a system role (e.g., "You are a code reviewer") or defining multi-turn workflows.

By exposing prompts via MCP, any client can retrieve and use these sophisticated prompts on demand. Prompts are typically user-controlled or developer-controlled, meaning the user might select a template from a UI, which the host then fetches from the server. This allows for updates and improvements to prompts without requiring changes to the client application, and different servers can offer specialized prompts.

# Example of a code review prompt template in an MCP server
@mcp.prompt()
def code_review_prompt(code: str):
    """Generates a prompt for a code review scenario.

    Args:
        code (str): The code to be reviewed.

    Returns:
        list: A list of message objects (e.g., in OpenAI format) for the AI.
    """
    return [
        {"role": "system", "content": "You are a meticulous code reviewer. Identify potential bugs, suggest improvements for readability and efficiency, and ensure best practices are followed."},
        {"role": "user", "content": f"Please review the following code:\n\n```python\n{code}\n```\n\nProvide your feedback, focusing on correctness, style, and performance."}
    ]

# When the host invokes this prompt, it gets these messages and can insert the actual code
# to be reviewed into the user content, then provides these messages to the model.

These three core capabilities — Tools, Resources, and Prompts — are visually summarized below:

Core Capabilities of an MCP Server

The Workflow of Model Context Protocol (MCP)

The workflow of MCP involves a seamless interaction between the user, the MCP Host, the MCP Client, and the MCP Server, which in turn accesses various data sources and performs API invocations. This structured approach ensures that AI models can efficiently and reliably leverage external capabilities.

Here's a breakdown of the typical MCP workflow:

1.User Request: The process begins with a user submitting a query or request to the MCP Host (e.g., a chat application or IDE).

2.Intent Analysis: The MCP Host analyzes the user's intent to determine what external capabilities might be needed.

3.Tool Selection/Resource Retrieval: Based on the intent, the MCP Client, working within the Host, communicates with the MCP Server to discover and select the appropriate tools, retrieve necessary resources, or fetch relevant prompts.

4.API Invocation: The MCP Server, acting as a wrapper, then invokes the required external APIs or accesses data sources (web services, databases, local files) to fulfill the request.

5.Initial Response & Notification: The server processes the request and returns the results to the MCP Client, which then relays them to the Host. The Host can then provide an initial response to the user or trigger notifications.

This entire process is orchestrated to provide a context-aware and accurate response to the user. The following diagram illustrates this workflow:

The Workflow of Model Context Protocol (MCP)

My Curated 7-MCP Stack for Serious Development

After exploring the theoretical underpinnings of MCP, let's dive into a practical application: a curated 7-MCP stack designed for robust and efficient development. This stack demonstrates how different MCPs can synergize to cover the full development lifecycle, from database operations to deployment, automation, and documentation.

This isn't a random collection; it's a carefully selected set of MCPs that handle approximately 90% of common development scenarios, ensuring no overlap in functionality, proven stability in production, and active maintenance.

My Curated 7-MCP Stack

Here's a breakdown of each component and its specific purpose:

Database & Backend:

•Supabase MCP: Provides real-time database operations, offering a powerful backend as a service that integrates seamlessly with your applications.

•Upstash MCP: Offers Redis caching and KV storage, crucial for high-performance applications requiring fast data retrieval and session management.

Deployment & Infrastructure:

•DigitalOcean MCP: Facilitates server management and deployment, providing scalable infrastructure for hosting your applications.

•Shopify Dev MCP: Essential for e-commerce integration and testing, allowing developers to build and test applications within the Shopify ecosystem.

Automation & Data:

•Puppeteer MCP: Enables browser automation and testing, invaluable for tasks like end-to-end testing, web scraping, and generating PDFs.

•Bright Data MCP: Specializes in web scraping and data collection, providing access to vast amounts of public web data for various analytical needs.

Documentation:

•Context7 MCP: Designed for extended context management with a 6000+ token minimum, ensuring that AI-enhanced workflows have ample context for complex tasks.

The Synergy:

The true power of this stack lies in its synergy. For instance:

•Supabase + DigitalOcean: Form a robust combination for building and deploying full-stack applications, leveraging Supabase's real-time capabilities with DigitalOcean's scalable infrastructure.

•Puppeteer + Bright Data: Create a formidable duo for web automation and data extraction, allowing for efficient and large-scale data collection.

•Context7 + Upstash: Enhance AI-driven workflows by providing extended context management and fast caching, leading to more intelligent and responsive AI applications.

This curated stack exemplifies how MCPs can be strategically combined to create a powerful, efficient, and well-rounded development environment, addressing diverse needs across the software development lifecycle.

Learn how to build a basic MCP server in Next.js ✋

0
Subscribe to my newsletter

Read articles from Sarvottam Bhagat directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Sarvottam Bhagat
Sarvottam Bhagat