calc_mcp
calc_mcp
stdio 経由で加算・減算・乗算・除算の四則演算を提供する電卓 MCP サービスです。
公式 MCP Python SDK の FastMCP API を使用し、依存関係を 1.x に限定して、メジャーバージョンアップによるインターフェース変更を回避します。
利用可能なツール
すべてのツールは必須の数値パラメータ a、b を 2 つ受け取り、整数、小数、負数に対応しています。
ツール | 演算 | 呼び出しパラメータ例 | 結果 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
呼び出しが成功すると structuredContent は {"result": 数值} となり、互換性のあるテキストコンテンツも提供されます。ツールはファイルの読み書きやネットワークアクセスを行いません。
エラーは MCP ツール結果の isError: true として返され、サービスを中断しません:
除数が
0または-0.0:Cannot divide by zero.引数が NaN または無限大:
Operands must be finite numbers.結果が無限大にオーバーフロー:
Result exceeds the supported finite number range.引数が不足している、または解析できない数値が渡された場合:SDK がパラメータ検証エラーを返します。
演算は Python の倍精度浮動小数点数を使用するため、通常の浮動小数点の丸め誤差が発生します。例えば 0.1 + 0.2 は 0.30000000000000004 を返す場合があります。10 進数の正確な計算が必要な用途には適していません。本バージョンは式の評価に対応していません。
Related MCP server: My Calculator MCP Server
ディレクトリ構造
calc_mcp/
├── pyproject.toml # 项目、依赖和命令行入口
├── uv.lock # 依赖版本锁定
├── README.md
├── .gitignore
├── src/calc_mcp/
│ ├── __init__.py
│ ├── __main__.py # python -m calc_mcp 入口
│ ├── server.py # MCP 实例和 stdio 启动
│ └── tools.py # 四则运算、边界检查和工具注册
└── tests/
└── test_server.py # 算术单元测试和 stdio 集成测试インストールと起動
Python 3.10+ と uv が必要です。このプロジェクトのディレクトリで実行します:
uv sync
uv run calc-mcpモジュールのエントリポイントから起動することもできます:
uv run python -m calc_mcpサービスは標準入出力を介して MCP クライアントと通信し、Web ページは提供しません。直接起動した後、クライアントからのメッセージを待つのは正常な動作です。stdout にデバッグ情報を出力しないでください。ログは stderr に書き込む必要があります。
MCP クライアント設定例
以下は mcpServers JSON 設定形式を使用するクライアント向けです。実際のクライアントに合わせて調整してください:
{
"mcpServers": {
"calc-mcp": {
"command": "uv",
"args": [
"--directory",
"/Users/lifang/product/0826/calc_mcp",
"run",
"calc-mcp"
]
}
}
}クライアントが uv を見つけられない場合は、command を uv 実行ファイルの絶対パスに変更してください。プロジェクトを移動した場合は、ディレクトリのパスを更新する必要があります。
検証
uv run python -m unittest discover -s tests -vテストは四則演算、負数、小数、ゼロ、不正な引数、非有限数、オーバーフローをカバーし、実際の stdio サブプロセスを起動して、MCP 初期化、ツール発見、ツール呼び出し、およびエラー後の正常な呼び出しを確認します。
今後の拡張箇所
src/calc_mcp/tools.py にツール定義を追加し、関数を register_tools() の登録リストに加えます。server.py の create_server() がツールを一括登録します。
Available Tools
4 toolsaddARead-onlyIdempotent
Add two finite numbers: a + b.
Inputs: a (required), b (required). Returns: result
divideARead-onlyIdempotent
Divide a by b: a / b. Operands must be finite and b must not be zero.
Inputs: a (required), b (required). Returns: result
multiplyARead-onlyIdempotent
Multiply two finite numbers: a * b.
Inputs: a (required), b (required). Returns: result
subtractARead-onlyIdempotent
Subtract b from a: a - b. Both operands must be finite numbers.
Inputs: a (required), b (required). Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 4 tools
Each tool maps to a single, distinct arithmetic operation: addition, subtraction, multiplication, or division. There is no overlap or ambiguity between tool purposes.
All tool names follow the same simple verb-only pattern: add, subtract, multiply, divide. The naming is perfectly consistent and instantly predictable.
Four tools is the ideal size for a basic arithmetic calculator server. Each tool covers a fundamental operation without unnecessary bloat.
The tool set fully covers the core arithmetic operations needed for a calculator: addition, subtraction, multiplication, and division, with appropriate edge-case handling for division by zero. It is a complete minimal surface for its stated purpose.
Maintenance
Related MCP Connectors
Evaluates Reverse Polish Notation (postfix) expressions: arithmetic, trig, logs, bitwise ops.
High-precision finance & business calculations for AI agents — exact decimals, never floats.
Exact arithmetic, algebra, calculus, physics, chemistry and finance with a checkable formula.
Create friendly greetings and add two numbers instantly. Speed up simple tasks and streamline ligh…
Related MCP Servers
- AlicenseDqualityDmaintenanceProvides basic mathematical operations (addition, subtraction, multiplication, division) through a calculate tool. Supports both stdio and HTTP/SSE transport modes.1ISC
- FlicenseNot gradedqualityDmaintenanceEnables basic calculator operations such as add, subtract, multiply, and divide through an MCP interface.-
- AlicenseNot gradedqualityDmaintenanceExposes add, subtract, multiply, and divide tools for performing arithmetic operations over stdio via the Model Context Protocol.ISC
- FlicenseAqualityCmaintenanceEnables an LLM client to perform basic arithmetic on two numbers — addition, subtraction, multiplication, and division — plus reverse a supplied text string, through five simple tools exposed over stdio. Inputs and structured text results follow JSON schemas, with invalid operations such as division by zero surfaced as tool errors.5-