Model Context Protocol by Anthropic for connecting AI models to data


A couple of months ago, Anthropic introduced and open-sourced the Model Context Protocol (MCP). MCP is the new standard for connecting AI models to external data sources and APIs more easily and consistently. With the advances in AI, models are becoming increasingly powerful in reasoning and quality. However, as text-completion machines, these models still lack access to real-time data. AI providers have worked around this using Retrieval Augmented Generation (RAG) and tool calling. Every data source requires custom implementation, and every provider has a way of integrating tools with AI models. MCP addresses these silos by providing a universal, open standard for connecting AI systems with data sources.

As Anthropic explains in its documentation, MCP is like a USB-C port for AI applications. Just as USB-C provides a standardized way to connect devices to various peripherals and accessories, MCP provides a standardized way to connect AI models to different data sources and tools.

There are a few components in the MCP architecture.

An MCP host is an AI application that needs access to external tools and data. These hosts get access to the tools, prompts, and resources an MCP server exposes through an MCP client inside the host application. Anthropic provides a set of sample servers written in Python and TypeScript. Implementing MCP servers and clients is easy if you are familiar with any of these languages. A few community members have implemented MCP SDKs in other languages as well. For example, mcp-golang is a Go implementation of the MCP.

This article will look at building a simple MCP server in Python. This example demonstrates how you can get started with developing MCP servers. We shall look at useful MCP server implementations in Python and other languages in future articles.

Getting started

As we will only implement an MCP server today, we must use an existing MCP host with an MCP client. We shall use Claude Desktop for this purpose. Anthropic added support for MCP in Claude Desktop. As of today, MCP servers can provide three types of capabilities: resources, prompts, and tools. This article will look at implementing tool capability in an MCP server.

Assuming you already have Python and the uv package manager installed on your system, you can run the following commands to create the scaffold for a hello-world MCP server.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# Create a new directory for our project
uv init hello-world
cd hello-world

# Create virtual environment and activate it
uv venv
.venv\Scripts\activate

# Install dependencies
uv add mcp[cli]

# Create our server file
new-item hello-world.py

We will implement the necessary tools in the hello-world.py.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from typing import Any
from mcp.server.fastmcp import FastMCP

mcp = FastMCP("hello")

@mcp.tool()
async def say_hello(name: str) -> str:
    """Say hello to the user.

    Args:
        name (str): The name of the user.
    """

    return f"Hello, {name}!"

@mcp.tool()
async def say_hello_to_everyone() -> str:
    """Say hello to everyone."""

    return "Hello, everyone!"

if __name__ == "__main__":
    mcp.run(transport='stdio')

This hello-world MCP server implements two tools – say_hello and say_hello_to_everyone. The @mcp.tool() decorator indicates that the functions are MCP tools that a host can use. The doc strings inside the function definitions are important for identifying the right tools.

We need to add the MCP server definition to the Claude Desktop configuration to make the MCP host (Claude Desktop) aware of the tools exposed by the MCP server. On a Windows system, this configuration file is located at C:\Users\<username>\AppData\Roaming\Claude\claude_desktop_config.json.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
{
    "mcpServers": { 
        "hello-world": {
            "command": "C:\\Users\\ravik\\.local\\bin\\uv.exe",
            "args": [
                "--directory",
                "C:\\GitHub\\mcp-servers\\hello-world",
                "run",
                "hello.py"
            ]
        },        
        "memory": {
            "command": "npx",
            "args": [
                "-y",
                "@modelcontextprotocol/server-memory"
            ]
        }
    }
}

Once you add the tool definition, restart the Claude Desktop application. You should then be able to see the tools available to Claude.

Now, you are ready to prompt and see Claude you these tools. Once you prompt, if Claude finds a suitable tool, you will be prompted to allow access to the tool.

This is it. In the next set of articles in this series on MCP, we will look at developing some useful MCP servers and clients.

Share on: