Calculator MCP Server

Calculator MCP Server

A local MCP server providing basic arithmetic tools (add, subtract, multiply, divide, power, square root, percentage) and a recent-calculation history resource, designed for integration with Claude Desktop.

Category
访问服务器

README

My First MCP Server — Setup Journey

A step-by-step log of building and connecting my first Model Context Protocol server to Claude Desktop, using the official Python SDK. This README documents exactly what was done, in order, including the issues hit along the way.

Built on: macOS Monterey 12.7.6, Intel i5, 8GB RAM (2015 MacBook Pro).


What is MCP

MCP lets an app like Claude Desktop call out to a local program (a "server") for tools and live data, instead of relying only on the model's built-in knowledge. This project builds a simple calculator server and connects it to Claude Desktop as a working example.

SDK used: modelcontextprotocol/python-sdk


Steps followed

1. Install uv (Python package/project manager)

uv wasn't installed, so:

curl -LsSf https://astral.sh/uv/install.sh | sh
source $HOME/.local/bin/env
uv --version

2. Create the project

mkdir mcp-test && cd mcp-test
uv init
uv add "mcp[cli]"

Issue hit: uv init defaulted requires-python to >=3.14, a version with no prebuilt wheel for the cryptography dependency — uv add sat compiling it from source for a very long time.

Fix: pin the project to a more compatible Python version:

sed -i '' 's/requires-python = ">=3.14"/requires-python = ">=3.10"/' pyproject.toml
rm -rf .venv
uv venv --python 3.12
uv add "mcp[cli]"

This installed cleanly using a prebuilt wheel.

3. Write the server

Created calculator_server.py using mcp.server.MCPServer, exposing calculator functions as tools (add, subtract, multiply, divide, power, square_root, percentage) and a small in-memory calculation log as a resource (history://recent), so tool calls and resource reads could both be demonstrated.

4. Test locally with the MCP Inspector

uv run mcp dev calculator_server.py

Issue hit: npx not found — the Inspector needs Node.js, which wasn't installed.

Fix: installed Node via nvm (chosen over Homebrew, since Homebrew's latest Node bottle isn't well supported on macOS Monterey and risked a slow/failing source build):

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
source ~/.zshrc
nvm install 20
nvm use 20

Reran uv run mcp dev calculator_server.py — it started the Inspector proxy and printed a local URL with an auth token. Opened that URL in the browser and confirmed:

  • Tools tab → called multiply(6, 7) → got 42
  • Resources tab → opened history://recent → saw the call logged

5. Connect the server to Claude Desktop

In Claude Desktop: Settings → Developer → Local MCP servers → Edit Config.

Issue hit: manually opening claude_desktop_config.json via terminal initially showed an unrelated app-preferences file, not the MCP config — resolved by using the in-app Edit Config button instead of guessing the file path, since it opens the correct file for the installed build.

Added:

{
  "mcpServers": {
    "calculator": {
      "command": "/Users/<you>/.local/bin/uv",
      "args": [
        "--directory",
        "/Users/<you>/Documents/mcp-test",
        "run",
        "calculator_server.py"
      ]
    }
  }
}

Used the full path to uv (from which uv) since Claude Desktop's process doesn't inherit the terminal shell's PATH.

6. Verify it's actually working

In Settings → Developer, the calculator server showed status running.

In a chat, confirmed the calculator toggle was on under the "+" → connectors menu, then asked Claude a question it could only answer using the tool's live state:

"What's in my calculator history?"

First attempt returned no history — because the earlier questions asked ("what's 84 divided by 12") were simple enough that Claude just computed them mentally instead of calling the tool. Asking more explicitly:

"Use the calculator tool for 84 divided by 12, and 15% of 200."

produced a response tagged "used calculator integration" in the UI — confirming the tool call was real, not just model math.


Result

A working local MCP server with 7 tools and 1 resource, connected to Claude Desktop, verified end-to-end via real tool invocation (not just Claude's own arithmetic).

Project structure

mcp-test/
├── calculator_server.py   # the MCP server
├── pyproject.toml           # project + dependency config (Python >=3.10)
├── uv.lock                   # locked dependency versions
└── README.md                 # this file

Reference

  • SDK: https://github.com/modelcontextprotocol/python-sdk
  • Docs: https://py.sdk.modelcontextprotocol.io/

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选