amankale376/calculator-mcp-server
3.1
If you are the rightful owner of calculator-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
A simple Model Context Protocol (MCP) server that provides calculator functionality with basic arithmetic, advanced mathematical operations, and expression evaluation.
Calculator MCP Server
A simple Model Context Protocol (MCP) server that provides calculator functionality with basic arithmetic, advanced mathematical operations, and expression evaluation.
Features
Basic Arithmetic Operations
- add: Addition of two numbers
- subtract: Subtraction of two numbers
- multiply: Multiplication of two numbers
- divide: Division of two numbers (with zero-division protection)
Advanced Mathematical Operations
- power: Exponentiation (base^exponent)
- square_root: Square root calculation
- factorial: Factorial calculation (0-170)
Trigonometric Functions
- sin: Sine function (angle in radians)
- cos: Cosine function (angle in radians)
- tan: Tangent function (angle in radians)
Logarithmic Functions
- log: Natural logarithm (ln)
- log10: Base-10 logarithm
Expression Evaluation
- evaluate: Evaluate complex mathematical expressions with support for:
- Basic operators: +, -, *, /, ^
- Functions: sqrt, sin, cos, tan, log, abs
- Parentheses for grouping
Installation
- Build the server:
npm run build
- The server is configured in the MCP settings to run automatically.
Usage Examples
Once the server is running and connected, you can use the calculator tools:
add(5, 3)
→ "5 + 3 = 8"multiply(4, 7)
→ "4 × 7 = 28"power(2, 8)
→ "2^8 = 256"square_root(16)
→ "√16 = 4"factorial(5)
→ "5! = 120"sin(1.5708)
→ "sin(1.5708) = 1" (π/2 radians)evaluate("2 + 3 * 4")
→ "2 + 3 * 4 = 14"evaluate("sqrt(16) + sin(0)")
→ "sqrt(16) + sin(0) = 4"
Error Handling
The server includes proper error handling for:
- Division by zero
- Invalid expressions
- Negative numbers for square root
- Factorial overflow protection (limited to 170!)
- Invalid mathematical operations
Technical Details
- Built with TypeScript and the MCP SDK
- Uses Zod for input validation
- Communicates via stdio transport
- Provides detailed error messages for invalid operations