Provides arbitrary precision arithmetic operations and mathematical functions by integrating with the GNU bc (Basic Calculator) command-line tool, supporting calculations with configurable precision up to 100 decimal places.
BC Calculator MCP Server
A Model Context Protocol (MCP) server that provides numerical computation capabilities by integrating with the Unix bc (Basic Calculator) command-line tool. This server exposes arbitrary precision arithmetic operations, mathematical functions, and complex expressions through the MCP protocol.
Features
⨠Arbitrary Precision Arithmetic: Support for calculations with configurable decimal precision (0-100 digits)
š§® Advanced Math Functions: Access to bc's math library including sqrt, sin, cos, arctan, natural log, exponential
š Concurrent Processing: Process pool management for handling multiple calculations simultaneously
š”ļø Security First: Input validation and sanitization to prevent command injection
ā” Performance Optimized: Process pooling for fast response times
šÆ MCP Compliant: Full MCP protocol implementation with tool discovery and JSON-RPC communication
Installation
Prerequisites
Node.js (v18 or higher)
TypeScript (v5.3 or higher)
bc calculator (standard on most Unix systems)
Verify bc is installed:
If not installed:
Setup
Navigate to MCP servers directory:
Bootstrap the project (if using create-server):
Or manually create the project structure:
Install dependencies:
Build the server:
Configure MCP settings:
Add to ~/.config/Code/User/globalStorage/rooveterinaryinc.roo-cline/settings/mcp_settings.json:
Usage
Available Tools
1. calculate
Evaluate basic mathematical expressions with configurable precision.
Parameters:
expression(string, required): Mathematical expression to evaluateprecision(number, optional): Decimal places for the result (default: 20, range: 0-100)
Examples:
2. calculate_advanced
Execute advanced BC scripts with variables, functions, and control flow.
Parameters:
script(string, required): Multi-line BC scriptprecision(number, optional): Decimal places for results (default: 20)
Examples:
3. set_precision
Set the default precision for subsequent calculations.
Parameters:
precision(number, required): Number of decimal places (0-100)
Example:
Mathematical Functions (with -l flag)
When using the math library, these functions are available:
Function | Description | Example |
| Square root |
ā 1.41421... |
| Sine (radians) |
ā 1.0 |
| Cosine (radians) |
ā 1.0 |
| Arctangent (radians) |
ā 0.78539... |
| Natural logarithm |
ā 1.0 |
| Exponential (e^x) |
ā 2.71828... |
Supported Operators
Arithmetic:
+,-,*,/,^(power),%(modulo)Comparison:
<,>,<=,>=,==,!=Logical:
&&,||,!Assignment:
=Increment/Decrement:
++,--
BC Language Features
Variables:
a = 5; b = 10; a + bArrays:
a[0] = 1; a[1] = 2Conditionals:
if (x > 0) { ... }Loops:
while (i < 10) { ... },for (i=0; i<10; i++) { ... }Functions: Define custom functions with
define
Architecture
Process Pool
The server maintains a pool of 3 BC processes to handle concurrent requests:
Security Features
Input Validation
Character whitelist enforcement
Maximum expression length (10KB)
Dangerous pattern detection
Command Injection Prevention
No shell execution (spawn with
shell: false)Input sanitization before BC
Blocked patterns:
system(),exec(), backticks, file redirects
Resource Protection
30-second timeout per calculation
Process pool size limit (3 processes)
Automatic process recovery on failures
Error Handling
The server provides detailed error messages for common issues:
Validation Errors
BC Runtime Errors
Timeout Errors
Configuration
Default Settings
Process Pool Size: 3 concurrent BC processes
Default Precision: 20 decimal places
Calculation Timeout: 30 seconds
Max Expression Length: 10,000 characters
Environment Variables
None required - bc is a standard system utility.
Optional: Custom Pool Size
Edit src/index.ts to adjust pool configuration:
Development
Project Structure
Build Commands
Testing
Troubleshooting
BC Not Found
Error: spawn bc ENOENT
Solution: Install bc calculator
Permission Denied
Error: Cannot execute build/index.js
Solution:
Module Import Errors
Error: Cannot find module
Solution: Ensure "type": "module" is in package.json
Timeout on Complex Calculations
Symptom: Long-running calculations fail
Solution: Increase timeout in tool parameters or pool config
Process Pool Exhausted
Symptom: Delayed responses under heavy load
Solution: Increase poolSize in BCProcessPool configuration
Performance
Benchmarks
Simple arithmetic: <10ms
Math functions: <50ms
Complex scripts: <200ms
Concurrent requests: 3 parallel calculations
Optimization Tips
Reuse connections: The process pool automatically optimizes this
Batch operations: Use
calculate_advancedfor multiple related calculationsAdjust precision: Lower precision = faster calculations
Increase pool: For heavy concurrent use, increase pool size
Contributing
Contributions welcome! Please:
Maintain TypeScript strict mode compliance
Add tests for new features
Update documentation
Follow existing code style
Ensure security validations remain intact
License
MIT License - See LICENSE file for details
Acknowledgments
Built on the Model Context Protocol SDK
Uses the standard GNU bc calculator
Inspired by the need for arbitrary precision arithmetic in AI applications
Support
For issues, questions, or feature requests:
Check the troubleshooting section
Review the implementation guide (IMPLEMENTATION_GUIDE.md)
Examine the architecture documentation (ARCHITECTURE.md)
Version History
1.0.0 (Initial Release)
Basic calculation support
Advanced scripting support
Process pool management
Security validation
MCP protocol compliance
This server cannot be installed
local-only server
The server can only run on the client's local machine because it depends on local resources.
Provides arbitrary precision arithmetic operations and advanced mathematical computations through the Unix bc calculator, supporting complex expressions, mathematical functions, and multi-line scripts with configurable precision.