Calculator MCP Server
Calculator MCP Server
4つのツール(add、subtract、multiply、divide)を公開する最小限のMCPサーバーで、2つのバージョンがあります:
calculator_server.py— PythonmcpSDK(FastMCP)で構築。@mcp.tool()が型ヒントとdocstringからJSONスキーマを自動生成し、 JSON-RPCプロトコルも処理してくれます。calculator_server_raw.py— 同じサーバーを標準ライブラリのみ(json+sys)で ゼロから実装したもの。mcpへの依存はありません。JSON-RPC 2.0のメッセージ処理を 手動で実装し、FastMCPが内部で何をしているかを示しています。具体的には、 stdinから改行区切りのJSONリクエストを読み取り、method(initialize、tools/list、tools/call、ping)に応じて分岐し、stdoutにJSON-RPCレスポンスを 書き込みます。フレーミングの詳細(LSPスタイルのヘッダーなし、1行に1つのJSONオブジェクト)に ついては、ファイル冒頭のdocstringを参照してください。
セットアップ
python -m venv .venv
.venv\Scripts\pip install -r requirements.txtRelated MCP server: my-mcp-server
直接実行する(stdio)
MCPサーバーは通常のCLIではなく、stdio(またはHTTP)を介して通信します。「実行して 出力を見る」のではなく、クライアントが接続する方式です。試す方法は2つあります:
1. MCP Inspector(ビジュアル、対話式) — Node.js/npxが必要:
.venv\Scripts\mcp dev calculator_server.pyブラウザのUIが開き、add、multiply などを手動で呼び出せます。
ページが読み込まれても「Connect to an MCP server to start inspecting」と表示され、 Toolsタブがない場合は、サイドバーがコマンドを自動的に認識できていません (古いセッション設定がキャッシュされている場合に発生することがあります)。サイドバーに 手動で入力して Connect をクリックしてください:
Transport Type:
STDIOCommand:
C:\Users\simon\mcpserversample\.venv\Scripts\python.exeArguments:
C:\Users\simon\mcpserversample\calculator_server.py
接続すると、上部ナビゲーションに Tools タブが表示され、 "List Tools" をクリックして各ツールを実行できます。
2. test_client.py — このリポジトリに含まれるスクリプト型クライアントで、
接続、ツール一覧の取得、各ツールの呼び出しを行います。デフォルトでは
calculator_server.py を使用しますが、パスを指定すればもう一方のバージョンも
テストできます:
.venv\Scripts\python test_client.py
.venv\Scripts\python test_client.py calculator_server_raw.pyClaude Desktopへの組み込み
claude_desktop_config.json に追加します:
{
"mcpServers": {
"calculator": {
"command": "C:\\Users\\simon\\mcpserversample\\.venv\\Scripts\\python.exe",
"args": ["C:\\Users\\simon\\mcpserversample\\calculator_server.py"]
}
}
}仕組み
calculator_server.pyはFastMCPサーバーを作成し、各Python関数を@mcp.tool()デコレータでツールとして登録します。関数の型ヒントとdocstringが ツールのJSONスキーマと説明になり、呼び出し側のクライアント(Claude、Inspector、 またはtest_client.py)がそれを参照します。mcp.run()はMCPのstdioトランスポートを使用してサーバーを起動し、 stdin/stdoutで待ち受けます。これは、クライアントがローカルのMCPサーバーを サブプロセスとして起動して通信する標準的な方法です。クライアントは接続後、
list_tools()を呼び出して利用可能なツールを確認し、 その後call_tool(name, args)でツールを呼び出して結果を受け取ります。
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceA demonstration MCP server that provides calculator functionality through both stdio and FastAPI implementations. Enables users to perform mathematical calculations via MCP tools using the FastMCP framework.
- AlicenseNot gradedqualityDmaintenanceA basic MCP server that implements a calculate tool for arithmetic operations (add, subtract, multiply, divide). It handles requests via stdio.841MIT
- FlicenseNot gradedqualityCmaintenanceProvides basic calculator operations (add, subtract, multiply, divide) as MCP tools for use with Claude Desktop and other MCP clients.
- FlicenseAqualityCmaintenanceProvides four fundamental arithmetic operations (add, subtract, multiply, divide) as MCP tools with zero-division protection.4
Related MCP Connectors
Math.js MCP — wraps the mathjs.org API (free, no auth)
Number utilities MCP.
This MCP server enables users to perform scientific computations regarding linear algebra and vect…
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/leesdream/mcpserversample'
If you have feedback or need assistance with the MCP directory API, please join our Discord server