Skip to main content
The Calculator Python server demonstrates building MCP servers with Python using the FastMCP framework. It provides basic arithmetic operations through a unified calculator tool.

Features

  • FastMCP Framework: Simplified Python MCP development
  • Arithmetic Operations: Add, subtract, multiply, divide
  • Error Handling: Division by zero protection
  • Minimal Setup: Quick to install and configure

Installation

1

Prerequisites

Ensure you have Python 3.13+ installed:
2

Navigate to Directory

3

Install Dependencies

Install using uv (recommended) or pip:
4

Configure MCP Client

Add to your MCP client configuration:

Tools

calculate

Perform arithmetic operations on two numbers. Parameters:
  • a (float): First number
  • b (float): Second number
  • operation (string): Operation to perform - add, subtract, multiply, or divide
Example Usage:

Implementation

Server Setup

The server uses FastMCP for simplified MCP server creation:

Arithmetic Functions

Core calculator operations:

Calculator Tool

Unified tool that routes to specific operations:

Running the Server

Complete Server Code

Error Handling

The calculator includes built-in error handling:

Division by Zero

Invalid Operation

FastMCP Benefits

FastMCP simplifies MCP server development:

Decorator-Based

Use @mcp.tool() decorator to register tools automatically

Type Hints

Python type hints automatically define parameter schemas

Built-in Transport

Stdio transport configured with mcp.run(transport='stdio')

Error Handling

Automatic error serialization and reporting

Dependencies

pyproject.toml:
Key Package:
  • mcp[cli]>=1.6.0 - MCP SDK with CLI tools and FastMCP framework

Testing the Server

You can test the calculator using the MCP inspector:
Or test directly in your MCP client:

Extending the Calculator

Add more operations by defining new functions and updating the tool:

Troubleshooting

This server requires Python 3.13+. Check your version:
Install Python 3.13+ from python.org if needed.
Install uv for faster dependency management:
Or use pip instead:
Ensure mcp package is installed:
Reinstall if needed:

Project Structure

Next Steps

Basic TypeScript

Explore advanced MCP features with TypeScript

EDteam Go Server

Learn about API integration with Go MCP servers