mcp-server-calculator
A simple calculator server that provides basic math operations to a client using the Model Context Protocol (MCP).
How to build an MCP server - Calculator Example
⚠️ work in progress ⚠️
About
Model Context Protocol (MCP) is a protocol that enables LLMs to access custom tools and services. An MCP client can make requests to MCP servers to access tools that they provide. This example represents a simple calculator server that provides basic math operations to a client.
"MCP can provide a single, standardized way for AI models to interact with external systems. You write code once and all AI systems can use it." 1
"Servers are the fundamental building block that enriches LLMs with external data and context." 2
Usage
🚧 TODO
Running & Testing the Server locally
- MCP Inspector is a handy GUI tool that lets you test your custom MCP server via web interface at http://localhost:5173 without integrating it with LLM / AI agents.
mcp dev src/mcp_server_calculator/calculator.py
MCP config
- Add the following to your mcp config:
{
"mcpServers": {
"calculator": {
"command": "uv",
"args": [
"run --with mcp mcp run src/mcp_server_calculator/calculator.py"
]
}
}
}
Notes
- When using Windsurf IDE as MCP Client, you need to have a Pro Plan to be able to use MCP Servers.
Dev Setup
As we are using Nix in this project for having a reproducible and isolated development environment, there is no need to install Python or any other dependencies. You will get everything you need out of the box. Also there is no need to create a virtual environment in Python using venv
or poetry
, but you have to be willing to install Nix on your system.
That's it!
Tech Stack
- Python3
- Pytest
- MCP SDK
- MCP CLI
- Nix
Resources
- [1] MCP server: A step-by-step guide to building from scratch
- [2] What is Model Context Protocol (MCP)?
- Understanding MCP and how AI engineers can leverage it
- MCP SDK
- MCP CLI
- MCP Inspector
- The largest collection of MCP Servers
- A Beginner's Guide to using MCP
- Claude MCP has Changed AI Forever - Here's What You NEED to Know
- Find MCP servers
Credits
- Nix-Setup taken from ical2json