Skip to main content

An MCP server providing fast arithmetic operations.

Project description

Create a Custom Server

Get started building your own server to use in Claude for Desktop and other clients.

In this tutorial, we'll build a simple MCP calculator server and connect it to a host, Claude for Desktop.

What is MCP?

MCP stands for Model Context Protocol — it’s a protocol that allows developers to extend AI assistants (like Claude) with custom tools and servers.

  • Think of it like giving your AI assistant extra powers.
  • These servers expose tools or functionalities that the assistant can use during a conversation.
  • For example: you can build weather servers, calculators, finance assistants, or anything you imagine.

What We'll Be Building

We'll build a server that exposes four tools: add, subtract, multiply, and divide. Then we'll connect the server to an MCP host (in this case, Claude for Desktop):

Note: Servers can connect to any client. We've chosen Claude for Desktop here for demonstration purposes.

Why Claude for Desktop and not Claude.ai? Because servers are locally run, MCP currently only supports desktop hosts.

Core MCP Concepts

MCP servers can provide three main types of capabilities:

  1. Resources: File-like data that can be read by clients (like API responses or file contents).
  2. Tools: Functions that can be called by the LLM (with user approval).
  3. Prompts: Pre-written templates that help users accomplish specific tasks.

This tutorial will primarily focus on tools.

Let's get started with building our calculator server! You can find the complete code for what we'll be building here.


Prerequisite Knowledge

This quickstart assumes you have familiarity with:

  • Python
  • LLMs like Claude

System Requirements

  • Python 3.10 or higher installed.
  • You must use the Python MCP SDK 1.2.0 or higher.

Set Up Your Environment

First, let's install uv and set up our Python project and environment:

MacOS/Linux

curl -LsSf https://astral.sh/uv/install.sh | sh

Windows

powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

Make sure to restart your terminal afterwards to ensure that the uv command gets picked up.

Now, let's create and set up our project:

MacOS/Linux

# Create a new directory for our project
uv init calculator
cd calculator

# Create virtual environment and activate it
uv venv
source .venv/bin/activate

# Install dependencies
uv add "mcp[cli]"

# Create our server file
touch calculator.py

Windows

# Create a new directory for our project
uv init calculator
cd calculator

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

# Install dependencies
uv add "mcp[cli]"

# Create our server file
new-item calculator.py

Now let's dive into building your server.


Building Your Server

Importing Packages and Setting Up the Instance

Add these to the top of your calculator.py:

from mcp.server.fastmcp import FastMCP

# Initialize FastMCP server
mcp = FastMCP("calculator")

Implementing Tool Execution

The tool execution handler is responsible for actually executing the logic of each tool. Let's add it:

@mcp.tool()
def add(a: float, b: float) -> float:
    """Add two numbers."""
    return a + b

@mcp.tool()
def subtract(a: float, b: float) -> float:
    """Subtract two numbers."""
    return a - b

@mcp.tool()
def multiply(a: float, b: float) -> float:
    """Multiply two numbers."""
    return a * b

@mcp.tool()
def divide(a: float, b: float) -> float:
    """Divide two numbers."""
    if b == 0:
        raise ValueError("Division by zero is not allowed.")
    return a / b

Running the Server

Finally, let's initialize and run the server:

if __name__ == "__main__":
    # Initialize and run the server
    mcp.run(transport='stdio')

Your server is complete! Run uv run calculator.py to confirm that everything's working.


Testing Your Server with Claude for Desktop

Note: Claude for Desktop is not yet available on Linux.

We'll need to configure Claude for Desktop for whichever MCP servers you want to use. To do this, open your Claude for Desktop App configuration at ~/Library/Application Support/Claude/claude_desktop_config.json in a text editor. Make sure to create the file if it doesn't exist.

MacOS/Linux

code ~/Library/Application\ Support/Claude/claude_desktop_config.json

Windows

code $env:AppData\Claude\claude_desktop_config.json

You'll then add your servers in the mcpServers key. The MCP UI elements will only show up in Claude for Desktop if at least one server is properly configured.

In this case, we'll add our single calculator server like so:

MacOS/Linux

{
    "mcpServers": {
        "calculator": {
            "command": "uv",
            "args": [
                "--directory",
                "/ABSOLUTE/PATH/TO/PARENT/FOLDER/calculator",
                "run",
                "calculator.py"
            ]
        }
    }
}

Windows

{
    "mcpServers": {
        "calculator": {
            "command": "uv",
            "args": [
                "--directory",
                "C:\\ABSOLUTE\\PATH\\TO\\PARENT\\FOLDER\\calculator",
                "run",
                "calculator.py"
            ]
        }
    }
}

Warning: You may need to put the full path to the uv executable in the command field. You can get this by running which uv on MacOS/Linux or where uv on Windows.

Make sure you pass in the absolute path to your server.

This tells Claude for Desktop:

  1. There's an MCP server named "calculator".
  2. To launch it by running uv --directory /ABSOLUTE/PATH/TO/PARENT/FOLDER/calculator run calculator.py.

Save the file, and restart Claude for Desktop.


Since this calculator supports basic arithmetic operations, it can be used for addition, subtraction, multiplication, and division.

For more info: MCP Official Docs

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mseep_arithmo_mcp_server-0.1.0.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mseep_arithmo_mcp_server-0.1.0-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file mseep_arithmo_mcp_server-0.1.0.tar.gz.

File metadata

  • Download URL: mseep_arithmo_mcp_server-0.1.0.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.12

File hashes

Hashes for mseep_arithmo_mcp_server-0.1.0.tar.gz
Algorithm Hash digest
SHA256 26dbbd2adb364cc7d98d40559c01cfa53d7cf79c60e9fb3d7a8a465348ad809b
MD5 f69a1a4ec0da40ffb94c11a88dcb6ab0
BLAKE2b-256 bce60b652b7c44fda42f7ddc641aca2a58fcff8843bf04e600f4c2f16fea6d81

See more details on using hashes here.

File details

Details for the file mseep_arithmo_mcp_server-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for mseep_arithmo_mcp_server-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c9c55f9df22cd625eb1af41af52a0036f514eb5c4bd463e0d2ac1cfdeec84ce1
MD5 5b25e6f67cfe96cd4e6c0c5fc1001d47
BLAKE2b-256 e72cafd72a91b3dffcbabe5c24d3a25c28ed995862b23ca3318c289b2f0d8478

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page