MCP Calculator Server
A comprehensive Model Context Protocol (MCP) server implementation using Python SDK featuring calculator tools, resources, and prompt templates. This server demonstrates how to build an MCP server with multiple capabilities including mathematical operations, resource access, and reusable prompt templates.
Features
8 Calculator Tools: Addition, subtraction, multiplication, division, power, square root, modulo, and expression evaluation
Resources: Access to external documentation files
Prompts: Reusable prompt templates (e.g., meeting summary template)
Dual Transport Support: Works with both stdio (for Claude Desktop) and Streamable HTTP transports
Async Support: Built with async/await for better performance
Prerequisites
Python 3.10 or higher - Required for the MCP SDK
uv package manager (recommended) or pip - For package management
Quick Start
1. Clone the Repository
2. Install Dependencies
Using uv (Recommended):
Using pip:
3. Run the Server
For stdio transport (default, used by Claude Desktop):
For Streamable HTTP transport:
Installation
Step 1: Verify Python Installation
Step 2: Install uv Package Manager
Windows (PowerShell):
macOS/Linux:
Or using pip:
Step 3: Create Virtual Environment
Step 4: Activate Virtual Environment
Windows (PowerShell):
Windows (Command Prompt):
macOS/Linux:
Step 5: Install MCP SDK
Step 6: Verify Installation
Configuration
Claude Desktop Configuration
To use this server with Claude Desktop, add the following to your Claude Desktop config file:
Windows: %APPDATA%\Claude\claude_desktop_config.json
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Linux: ~/.config/Claude/claude_desktop_config.json
Important: Replace the paths with your actual project paths.
Environment Variables
The server supports the following environment variables:
TRANSPORT: Transport type (stdioorstreamable-http). Default:stdioHOST: Host address for Streamable HTTP transport. Default:0.0.0.0PORT: Port number for Streamable HTTP transport. Default:8000TYPESDK_PATH: Path to TypeScript SDK documentation file (optional). Default:typesdk.mdin project directory
Server Features
Tools
The server provides 8 calculator tools:
1. add - Addition
Adds two numbers together.
Parameters:
a(float),b(float)Example:
add(5, 3)→8
2. subtract - Subtraction
Subtracts the second number from the first.
Parameters:
a(float),b(float)Example:
subtract(10, 4)→6
3. multiply - Multiplication
Multiplies two numbers.
Parameters:
a(float),b(float)Example:
multiply(7, 6)→42
4. divide - Division
Divides the first number by the second.
Parameters:
a(float),b(float)Example:
divide(20, 4)→5Error handling: Prevents division by zero
5. power - Exponentiation
Raises a base number to an exponent.
Parameters:
base(float),exponent(float)Example:
power(2, 8)→256
6. square_root - Square Root
Calculates the square root of a number.
Parameters:
number(float, must be non-negative)Example:
square_root(16)→4.0Error handling: Prevents square root of negative numbers
7. modulo - Modulo Operation
Calculates the remainder when dividing two numbers.
Parameters:
a(float),b(float)Example:
modulo(17, 5)→2Error handling: Prevents modulo by zero
8. calculate - Expression Evaluator
Evaluates complex mathematical expressions.
Parameters:
expression(string)Supports:
+,-,*,/,**, parentheses, and math functionsExample:
calculate("(3 + 4) * 2")→"Result: 14"Functions available:
sqrt,sin,cos,tan,log,log10,exp,abs,round,min,max,sum,powConstants:
pi,e
Resources
typesdk://documentation
Provides access to TypeScript SDK documentation.
URI:
typesdk://documentationType: Read-only resource
Configuration: Set
TYPESDK_PATHenvironment variable or placetypesdk.mdin the project directory
Prompts
meeting_summary
Generates a formatted meeting summary prompt using a template.
Parameters:
meeting_date(string, optional): The date of the meetingmeeting_title(string, optional): The title or subject of the meetingtranscript(string, optional): The meeting transcript or notes
Template Source: Based on mikeskarl/mcp-prompt-templates
Usage: The prompt template includes sections for:
Overview (purpose, participants, topics)
Key Decisions
Action Items
Follow-up Required
Project Structure
Transport Options
stdio Transport (Default)
Used by Claude Desktop and other local MCP clients. The server communicates via standard input/output.
Streamable HTTP Transport
For HTTP-based clients using Streamable HTTP. The server runs as an HTTP server.
Testing
Using MCP Inspector
Install MCP Inspector:
Run the server:
In another terminal, run the inspector:
Connect to your server and test the tools, resources, and prompts.
Example Tool Usage
Development
Adding New Tools
Open
server.pyAdd a new tool function with the
@mcp.tool()decorator:
Save the file and restart the server
The tool will be automatically registered and available to MCP clients.
Adding New Resources
Add a resource handler with the
@mcp.resource()decorator:
Adding New Prompts
Create a prompt template file (e.g.,
my_prompt_template.md)Add a prompt handler with the
@mcp.prompt()decorator:
Troubleshooting
Python Version Issues
Problem: Python version is too old or not found.
Solution:
Virtual Environment Not Activating
Windows PowerShell - Execution Policy Error:
Windows Command Prompt:
macOS/Linux:
Import Errors
Problem: Import errors when running the server.
Solution:
Ensure virtual environment is activated
Verify package is installed:
uv pip list | grep mcpReinstall if needed:
uv pip install --force-reinstall "mcp[cli]"
Server Not Starting
Problem: Server exits immediately or shows errors.
Solution:
Check Python version:
python --version(should be 3.10+)Verify server.py syntax:
python -m py_compile server.pyTest imports:
python -c "from mcp.server.fastmcp import FastMCP; print('OK')"Run with error output:
python server.py 2>&1
Streamable HTTP Connection Refused (ECONNREFUSED)
Problem: Getting ECONNREFUSED error when trying to connect via Streamable HTTP.
Solution:
Verify the server is running with Streamable HTTP transport:
TRANSPORT=streamable-http HOST=0.0.0.0 PORT=8000 python server.pyYou should see:
Starting Streamable HTTP server on 0.0.0.0:8000Check if the server is actually listening:
# Windows netstat -an | findstr 8000 # macOS/Linux lsof -i :8000 # or netstat -an | grep 8000Verify the client is connecting to the correct URL:
The server should be accessible at:
http://localhost:8000orhttp://0.0.0.0:8000Make sure the client is using the same host and port
Check firewall settings:
Ensure port 8000 (or your configured port) is not blocked by firewall
On Windows, you may need to allow Python through the firewall
Try a different port:
TRANSPORT=streamable-http PORT=8080 python server.pyFor Claude Desktop, use stdio transport instead:
Claude Desktop uses stdio transport by default
Don't set
TRANSPORT=streamable-httpwhen using with Claude DesktopJust run:
python server.py(stdio is the default)
Resource Not Found
Problem: typesdk://documentation resource not found.
Solution:
Place
typesdk.mdin the project directory, orSet
TYPESDK_PATHenvironment variable to the full path of your documentation file
Prompt Template Not Found
Problem: Meeting summary prompt fails with "Template file not found".
Solution:
Ensure meeting_summary_template.md exists in the project directory. The file is automatically downloaded when you clone the repository, or you can download it from mikeskarl/mcp-prompt-templates.
Version Verification Checklist
Python 3.10+ installed:
python --versionuv installed:
uv --versionVirtual environment created:
ls .venvordir .venvVirtual environment activated:
(.venv)in promptMCP package installed:
uv pip list | grep mcpMCP imports work:
python -c "from mcp.server.fastmcp import FastMCP; print('OK')"Server runs:
python server.py
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is provided as-is for educational purposes.
Resources
Support
If you encounter issues not covered in this README:
Check the Troubleshooting section
Review the MCP Python SDK documentation
Check uv documentation for package management issues
Verify all versions meet requirements (Python 3.10+, latest uv)
Last Updated: 2024
Python Version Required: 3.10+
MCP SDK Version: Latest (installed via uv pip install "mcp[cli]")