Skip to main content
21nauts
MCPBeginnerHands-on

Model Context Protocol (MCP) 101: A Hands-On Beginner's Guide

Learn MCP fundamentals with practical examples. Discover how to create weather data servers, integrate with Claude Desktop, and understand the client-server architecture that makes AI applications more capable.

January 10, 2025
12 min read
Pavan Belagatti

Model Context Protocol (MCP) 101: A Hands-On Beginner's Guide

The Model Context Protocol (MCP) is creating a buzz in the AI community, and for good reason. This open-source framework, initiated by Anthropic, provides a standardized way for AI models to connect with external data sources and tools. By simplifying the integration process, MCP is set to revolutionize how developers create AI applications.

What is Model Context Protocol (MCP)?

MCP stands for Model Context Protocol, and it's essentially a universal connector for AI applications. Think of it as the USB-C of the AI world, allowing different AI tools and models to interact seamlessly with various data sources.

With MCP, developers can focus on building innovative applications instead of spending time on complex integrations.

Why Do We Need MCP?

Large Language Models (LLMs) like Claude, ChatGPT, and others have transformed our interactions with technology. However, they still have limitations, particularly when it comes to accessing real-world data and connecting with tools.

Challenges MCP Addresses:

Knowledge Limitations

LLMs rely on training data that can quickly become outdated. This makes it difficult for them to provide accurate, real-time information.

Domain Knowledge Gaps

LLMs lack deep understanding of specialized domains, making it hard for them to generate contextually relevant responses.

Non-Standardized Integration

Current methods for connecting LLMs to external data sources often require custom solutions, leading to high costs and inefficiencies.

MCP provides a unified solution to these issues, allowing LLMs to easily access external data and tools, thereby enhancing their capabilities.

How MCP Works

MCP was originally built to improve Claude's ability to interact with external systems. Anthropic decided to open-source MCP in early 2024 to encourage industry-wide adoption.

Beyond RAG

While Retrieval Augmented Generation (RAG) provides LLMs with custom data required to generate contextually relevant responses, MCP goes beyond that. MCP provides direct access to tools and other custom data through a unified API.

MCP facilitates communication between AI models and external data/tools, enabling AI systems to interact with diverse sources in a consistent manner.

MCP Architecture Components

MCP operates on a client-server architecture, comprising several key components:

MCP Hosts

Applications that need contextual AI capabilities, such as chatbots or IDEs.

MCP Clients

These maintain a one-on-one connection with MCP servers and handle protocol specifics.

MCP Servers

Lightweight programs that expose specific capabilities through the MCP interface, connecting to local or remote data sources.

Local Data Sources

Files and databases that MCP servers can securely access.

Remote Services

External services available over the Internet that MCP servers can connect to.

Restaurant Analogy

Here's an analogy to understand MCP:

Imagine MCP as a restaurant where we have:

  • The Host = The restaurant building (the environment where the agent runs)
  • The Server = The kitchen (where tools live)
  • The Client = The waiter (who sends tool requests)
  • The Agent = The customer (who decides what tool to use)
  • The Tools = The recipes (the code that gets executed)

Benefits of Implementing MCP

Standardization

MCP provides a common interface for integrating various tools and data sources, reducing development time and complexity.

Enhanced Performance

Direct access to data sources allows for faster, more accurate responses from AI models.

Flexibility

Developers can easily switch between different LLMs without having to rewrite code for each integration.

Security

MCP incorporates robust authentication and access control mechanisms, ensuring secure data exchanges.

Getting Started with MCP: Weather Server Example

Let's walk through a practical example where we create an MCP server that can fetch weather data.

Prerequisites

Ensure you have Claude Desktop installed on your system. You can download it based on your operating system — macOS or Windows.

Building the Weather MCP Server

Here's how to set up a simple weather server:

1. Server Setup

First, create your MCP server structure:

from mcp import McpServer
import asyncio
import httpx

class WeatherServer:
    def __init__(self):
        self.server = McpServer("weather-server")
        self.setup_tools()

    def setup_tools(self):
        @self.server.tool("get_weather")
        async def get_weather(location: str) -> str:
            """Get current weather for a location"""
            # Implementation here
            pass

        @self.server.tool("get_forecast")
        async def get_forecast(location: str, days: int = 5) -> str:
            """Get weather forecast for a location"""
            # Implementation here
            pass
Python

2. Tool Implementation

Implement the weather tools:

async def get_weather(location: str) -> str:
    """Get current weather for a location"""
    api_key = "your-weather-api-key"
    url = f"https://api.openweathermap.org/data/2.5/weather"
    params = {
        "q": location,
        "appid": api_key,
        "units": "metric"
    }

    async with httpx.AsyncClient() as client:
        response = await client.get(url, params=params)
        data = response.json()

        return f"Weather in {location}: {data['weather'][0]['description']}, "
               f"Temperature: {data['main']['temp']}°C"

async def get_forecast(location: str, days: int = 5) -> str:
    """Get weather forecast for a location"""
    api_key = "your-weather-api-key"
    url = f"https://api.openweathermap.org/data/2.5/forecast"
    params = {
        "q": location,
        "appid": api_key,
        "units": "metric",
        "cnt": days * 8  # 8 forecasts per day (3-hour intervals)
    }

    async with httpx.AsyncClient() as client:
        response = await client.get(url, params=params)
        data = response.json()

        forecast_text = f"5-day forecast for {location}:\n"
        for item in data['list'][:days]:
            forecast_text += f"- {item['dt_txt']}: {item['weather'][0]['description']}, "
                           f"{item['main']['temp']}°C\n"

        return forecast_text
Python

3. Server Configuration

Configure your server for Claude Desktop:

{
  "mcpServers": {
    "weather": {
      "command": "python",
      "args": ["path/to/your/weather_server.py"],
      "env": {
        "WEATHER_API_KEY": "your-api-key"
      }
    }
  }
}
JSON

Claude Desktop Integration

Once your server is running, Claude Desktop can use it to:

  1. Get current weather: "What's the weather like in San Francisco?"
  2. Get forecasts: "Give me a 5-day forecast for Tokyo"
  3. Compare locations: "Compare the weather in New York and London"

Database Operations with MCP

MCP also excels at database automation. For example, with SingleStore's MCP server, you can:

Installation

# Install via Smithery
npx -y @smithery/cli install @singlestore-labs/mcp-server-singlestore --client claude

# Or via pip
pip install singlestore-mcp-server
Bash

Configuration

{
  "mcpServers": {
    "singlestore": {
      "command": "singlestore-mcp-client",
      "args": [],
      "env": {
        "SINGLESTORE_CONNECTION_STRING": "your-connection-string"
      }
    }
  }
}
JSON

Natural Language Database Queries

With this setup, you can perform database operations using natural language:

  • "Show me the top 10 customers by revenue"
  • "Create a new table for user preferences"
  • "Update all inactive users from last month"

Popular MCP Tools and Ecosystem

The MCP ecosystem is rapidly growing with support from major AI tools:

Supported Applications

  • Claude Desktop - Native MCP support
  • Claude Code - Development-focused integration
  • Cursor - IDE with MCP capabilities
  • Windsurf (Codeium) - Cloud-based development
  • Cline - VS Code extension for AI assistance

Available Servers

  • SingleStore - Database operations
  • GitHub - Repository management
  • Notion - Documentation and notes
  • Filesystem - Local file operations
  • Web Search - Internet data access

Best Practices for MCP Development

Security Considerations

  1. Authentication: Always implement proper API key management
  2. Access Control: Limit server capabilities to necessary functions
  3. Data Validation: Validate all input data before processing
  4. Error Handling: Implement comprehensive error handling

Performance Optimization

  1. Caching: Cache frequently accessed data
  2. Async Operations: Use asynchronous operations for I/O
  3. Connection Pooling: Reuse database connections
  4. Rate Limiting: Respect API rate limits

Development Tips

  1. Start Simple: Begin with basic functionality
  2. Test Thoroughly: Test with various input scenarios
  3. Document Well: Provide clear tool descriptions
  4. Monitor Usage: Track server performance and usage

The Future of MCP

MCP is poised to become the standard for AI integration, addressing the challenges of knowledge limitations, domain knowledge gaps, and non-standardized integrations. By adopting MCP, developers can create more efficient, scalable, and secure AI applications.

The future looks bright for AI, and with MCP laying the groundwork for standardized connections, we are taking significant steps toward a more connected and capable ecosystem.

Next Steps

Ready to start building with MCP?

  1. Install Claude Desktop and familiarize yourself with the interface
  2. Choose your first use case - start with something simple like file access or API calls
  3. Build your first server using the Python or TypeScript SDK
  4. Test and iterate with real use cases
  5. Join the community and share your MCP implementations

MCP represents a fundamental shift in how AI applications access external systems. By providing a standardized protocol, it enables developers to build more capable, connected, and powerful AI applications with less complexity.


Ready to build your first MCP server? Check out our comprehensive development guides and examples to get started.