MCP.so
Sign In
Servers

How to build an MCP server - Calculator Example

@simonberner

Example project showing how to build a simple MCP Server (and having it on Smithery!)

Overview

What is How to build an MCP server - Calculator Example?

This is a simple example MCP server that provides basic math operations (addition, subtraction, multiplication, division) to an MCP client. It demonstrates how to build an MCP server from scratch using Python and the MCP SDK, intended for developers learning the Model Context Protocol.

How to use How to build an MCP server - Calculator Example?

Install automatically via Smithery (npx -y @smithery/cli install @simonberner/mcp-server-calculator --client claude), or set up the development environment using Nix/direnv or manually with uv. Run locally with mcp dev src/mcp_server_calculator/calculator.py and test using MCP Inspector. Integrate with an MCP host by adding the server configuration to the host's mcp config file (e.g., for Claude Desktop).

Key features of How to build an MCP server - Calculator Example

  • Provides basic math operations: add, subtract, multiply, divide.
  • Built with Python 3 and the MCP SDK.
  • Supports installation via Smithery, Nix, or uv.
  • Testable via MCP Inspector web interface.
  • Includes unit tests with pytest.

Use cases of How to build an MCP server - Calculator Example

  • Learning how to build an MCP server from scratch.
  • Prototyping a simple math tool for AI agents.
  • Testing MCP client-server interactions locally.

FAQ from How to build an MCP server - Calculator Example

What is MCP?

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 they provide.

How do I install this server?

You can install it via Smithery, use the Nix development environment with direnv, or set it up manually with uv. For hosts like Claude Desktop, add the server configuration to your mcp config.

What dependencies are required?

Python 3, the MCP SDK, the MCP CLI, and pytest. Optionally Nix (or Lix) for a reproducible environment.

How do I test the server locally without an LLM?

Run mcp dev src/mcp_server_calculator/calculator.py and open MCP Inspector at http://localhost:5173 to test the server via a GUI.

Where does server data live?

The server is stateless; all math operations are computed in memory and no data is persisted.

What transport does it use?

The server runs as a Python script over stdio, configured locally in the MCP host’s configuration file. It is not a remote server.

More from Developer Tools