Math Tools
Mathematical calculations and unit conversions for AI agents.
Provider: Built-in
Authentication: None required
Category: Utilities
Credit Cost: 0 credits (free)
Overview
Math tools provide essential mathematical operations without requiring external APIs or authentication. Perfect for quick calculations, unit conversions, and generating random numbers within your AI workflows.
Available Tools
Calculate
Evaluate mathematical expressions safely.
Tool ID: math_Calculate
Credit Cost: 0 credits (free)
Parameters:
expression(string, required): Mathematical expression to evaluate- Supports:
+,-,*,/,**(power),%(modulo) - Supports: parentheses for grouping
- Supports: decimals and scientific notation
- Examples:
"2 + 2","10 * 5 + 3","(100 - 20) / 4"
- Supports:
Response:
{
"result": 42,
"expression": "40 + 2"
}
Example Usage:
# Python
response = client.call_tool(
name="math_Calculate",
arguments={
"expression": "((100 - 15) * 2) + 50"
}
)
# Returns: {"result": 220}
// TypeScript
const response = await client.callTool({
name: "math_Calculate",
arguments: {
expression: "2 ** 10" // 2 to the power of 10
}
});
// Returns: {"result": 1024}
Use Cases:
- Calculate costs and totals
- Perform percentage calculations
- Evaluate formulas from text
- Quick arithmetic in agent workflows
Limitations:
- No support for trigonometric functions
- No support for logarithms or advanced math
- Expression length limit: 1000 characters
Convert Units
Convert between different measurement units.
Tool ID: math_Convert_Units
Credit Cost: 0 credits (free)
Parameters:
value(number, required): The numeric value to convertfrom_unit(string, required): Source unitto_unit(string, required): Target unit (must be same category as from_unit)
Supported Units:
Temperature:
c,celsius- Celsiusf,fahrenheit- Fahrenheitk,kelvin- Kelvin
Length:
m,meter,meters,metre,metres- Meterscm,centimeter,centimeters- Centimeterskm,kilometer,kilometers- Kilometersft,feet,foot- Feetin,inch,inches- Inchesmi,mile,miles- Milesyd,yard,yards- Yards
Weight:
kg,kilogram,kilograms,kilo- Kilogramsg,gram,grams- Gramslb,lbs,pound,pounds- Poundsoz,ounce,ounces- Ounces
Response:
{
"value": 104,
"from_unit": "celsius",
"to_unit": "fahrenheit",
"result": 219.2
}
Example Usage:
# Convert temperature
response = client.call_tool(
name="math_Convert_Units",
arguments={
"value": 25,
"from_unit": "celsius",
"to_unit": "fahrenheit"
}
)
# Returns: {"result": 77}
// Convert distance
const response = await client.callTool({
name: "math_Convert_Units",
arguments: {
value: 100,
from_unit: "km",
to_unit: "mi"
}
});
// Returns: {"result": 62.137}
# Convert weight
curl -X POST https://api.joinreeva.com/mcp/server_123 \
-H "Authorization: Bearer mcpk_your_key" \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"name": "math_Convert_Units",
"arguments": {
"value": 150,
"from_unit": "lb",
"to_unit": "kg"
}
},
"id": 1
}'
Use Cases:
- Convert user input to standard units
- Localize measurements for different regions
- Scientific calculations requiring unit consistency
- Recipe conversions
Error Handling:
- Units must be in the same category (can't convert temperature to length)
- Negative temperatures are allowed
- Very large or small values may lose precision
Random Number
Generate random numbers for testing and simulations.
Tool ID: math_Random_Number
Credit Cost: 0 credits (free)
Parameters:
min(integer, optional): Minimum value (inclusive)- Default: 0
max(integer, optional): Maximum value (inclusive)- Default: 100
Response:
{
"random_number": 42,
"min": 1,
"max": 100
}
Example Usage:
# Generate random number between 1 and 100
response = client.call_tool(
name="math_Random_Number",
arguments={
"min": 1,
"max": 100
}
)
# Returns: {"random_number": 67}
// Generate random dice roll
const response = await client.callTool({
name: "math_Random_Number",
arguments: {
min: 1,
max: 6
}
});
// Returns: {"random_number": 4}
Use Cases:
- Generate test data
- Simulate dice rolls or lottery numbers
- Random sampling in workflows
- A/B testing assignments
Common Patterns
Calculate and Convert
# Calculate speed in km/h, convert to mph
speed_kmh = client.call_tool(
name="math_Calculate",
arguments={"expression": "100 / 2"} # 50 km/h
)
speed_mph = client.call_tool(
name="math_Convert_Units",
arguments={
"value": speed_kmh["result"],
"from_unit": "km",
"to_unit": "mi"
}
)
Temperature Conversion Workflow
# Get weather in Celsius, convert for US users
weather_celsius = 22
weather_fahrenheit = client.call_tool(
name="math_Convert_Units",
arguments={
"value": weather_celsius,
"from_unit": "celsius",
"to_unit": "fahrenheit"
}
)
# User sees: "72°F"
Financial Calculations
# Calculate discount
original_price = 100
discount_percent = 15
discount_amount = client.call_tool(
name="math_Calculate",
arguments={"expression": f"{original_price} * {discount_percent} / 100"}
)
final_price = client.call_tool(
name="math_Calculate",
arguments={"expression": f"{original_price} - {discount_amount['result']}"}
)
# Result: $85.00
Best Practices
Expression Safety
- Always validate user input before passing to calculate
- Set reasonable limits on expression complexity
- Be aware of division by zero errors
Unit Conversion
- Standardize units within your application
- Display units clearly to users
- Keep track of precision requirements
Random Numbers
- Use appropriate ranges for your use case
- Don't use for cryptographic purposes
- Consider seeding for reproducibility if needed
Troubleshooting
"Invalid expression" Error
Cause: Expression contains unsupported operations or syntax errors
Solutions:
- Check for typos in mathematical operators
- Ensure parentheses are balanced
- Remove any letters or symbols (except operators)
- Verify decimal points are used correctly
"Units not in same category" Error
Cause: Trying to convert between incompatible unit types
Solutions:
- Check from_unit and to_unit are in same category
- Review supported units list above
- Verify spelling of unit names
Precision Issues
Cause: Floating point arithmetic limitations
Solutions:
- Round results to appropriate decimal places
- Use integer operations when possible
- Be aware of very large or very small numbers
Related Tools
- Text Tools - String manipulation and text processing
- Time Tools - Date and time operations
- Weather Tools - Temperature data (can combine with conversions)
Examples
Example 1: Recipe Scaling
# Scale recipe from 4 servings to 6
original_servings = 4
new_servings = 6
scaling_factor = client.call_tool(
name="math_Calculate",
arguments={"expression": f"{new_servings} / {original_servings}"}
)
# Scale each ingredient
flour_oz = 8
flour_scaled = client.call_tool(
name="math_Calculate",
arguments={"expression": f"{flour_oz} * {scaling_factor['result']}"}
)
# Result: 12 oz flour
Example 2: International Shipping
# Package weight in pounds, need kilograms for international shipping
weight_lbs = 25
weight_kg = client.call_tool(
name="math_Convert_Units",
arguments={
"value": weight_lbs,
"from_unit": "lb",
"to_unit": "kg"
}
)
# Result: 11.34 kg
Example 3: Random Test Selection
# Select random test case from 1-50
test_case = client.call_tool(
name="math_Random_Number",
arguments={
"min": 1,
"max": 50
}
)
# Run test case #23
See Also
- Creating Custom Tools - Pre-configure unit conversions
- Tool Testing - Test calculations in playground
- All Tools - Browse complete tool catalog