Skip to content

Commit 9fe7877

Browse files
author
Avinash Sangle
committed
feat: Add comprehensive calculator-server to mcp-servers/go
Added a feature-rich MCP-compliant calculator server with comprehensive mathematical capabilities: ## Features - **Basic Operations**: Addition, subtraction, multiplication, division, power, square root - **Advanced Mathematics**: Trigonometric functions, logarithms, factorials, GCD/LCM - **Expression Parsing**: Complex mathematical expression evaluation with proper operator precedence - **Statistical Functions**: Mean, median, mode, standard deviation, variance, correlation - **Financial Calculations**: Present/future value, loan payments, investment returns - **Unit Conversions**: Length, weight, temperature, volume, area conversions ## Technical Implementation - **MCP Protocol Compliance**: Full Model Context Protocol implementation with JSON-RPC 2.0 - **Multi-Transport Support**: stdio, HTTP JSON-RPC, and Streamable HTTP with SSE - **Robust Architecture**: Clean separation with internal packages for calculator logic, handlers, and configuration - **Comprehensive Testing**: Unit tests, integration tests, and Python test scripts - **Configuration Management**: JSON and YAML configuration support with sample files - **Production Ready**: Makefile for building, comprehensive documentation, and error handling ## MCP Tools Provided - calculate: Basic arithmetic operations - calculate_advanced: Advanced mathematical functions - evaluate_expression: Complex expression parsing and evaluation - calculate_statistics: Statistical analysis of datasets - calculate_finance: Financial calculations and analysis - convert_units: Unit conversion between different measurement systems The server follows the established patterns in mcp-servers/go and integrates seamlessly with the MCP Gateway ecosystem. Signed-off-by: Avinash Sangle <[email protected]>
1 parent c9b5956 commit 9fe7877

33 files changed

+9980
-0
lines changed
Lines changed: 296 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,296 @@
1+
# AI Agent Test Prompts for Calculator Server Tools
2+
3+
This document provides ready-to-use prompts for testing the calculator server tools with AI agents. Each prompt is designed to thoroughly test a specific calculator tool.
4+
5+
---
6+
7+
## 🧮 **Basic Math Tool Tests**
8+
9+
### Prompt 1: Basic Math Operations
10+
```
11+
Test the basic_math tool with these calculations:
12+
1. Add these numbers: 15, 25, 10
13+
2. Subtract 45 from 100
14+
3. Multiply 12 by 8
15+
4. Divide 144 by 12
16+
5. Calculate 22 divided by 7 with 4 decimal places precision
17+
6. Add -15 and 8
18+
7. Try to divide 10 by 0 (test error handling)
19+
20+
For each calculation, use the basic_math tool and report both the input and result.
21+
```
22+
23+
### Prompt 2: Basic Math Edge Cases
24+
```
25+
Test edge cases with the basic_math tool:
26+
1. Multiply very large numbers: 999999999 × 999999999
27+
2. Add many small decimals: 0.1 + 0.2 + 0.3 + 0.4 + 0.5
28+
3. Divide with high precision: 1 ÷ 3 with 10 decimal places
29+
4. Subtract resulting in negative: 5 - 12
30+
5. Multiply by zero: 500 × 0
31+
32+
Report any interesting behaviors or limitations you observe.
33+
```
34+
35+
---
36+
37+
## 📐 **Advanced Math Tool Tests**
38+
39+
### Prompt 3: Trigonometric Functions
40+
```
41+
Use the advanced_math tool to calculate:
42+
1. sin(90) in degrees
43+
2. cos(0) in radians
44+
3. tan(45) in degrees
45+
4. sin(π/2) in radians (use 1.5708 as approximation)
46+
5. cos(π) in radians (use 3.1416 as approximation)
47+
48+
Test both degree and radian modes where applicable.
49+
```
50+
51+
### Prompt 4: Logarithmic and Other Functions
52+
```
53+
Test these advanced mathematical functions:
54+
1. Natural logarithm: ln(2.718)
55+
2. Base-10 logarithm: log10(1000)
56+
3. Square root: sqrt(64)
57+
4. Absolute value: abs(-25)
58+
5. Factorial: factorial(6)
59+
6. Exponential: exp(2)
60+
7. Power function: test pow with value 3
61+
62+
For each function, use the advanced_math tool and explain what the result represents.
63+
```
64+
65+
---
66+
67+
## 📊 **Statistics Tool Tests**
68+
69+
### Prompt 5: Basic Statistical Analysis
70+
```
71+
Use the statistics tool to analyze this dataset: [12, 15, 18, 12, 20, 25, 18, 12, 30, 22]
72+
73+
Calculate:
74+
1. Mean (average)
75+
2. Median (middle value)
76+
3. Mode (most frequent value)
77+
4. Standard deviation
78+
5. Variance
79+
80+
Interpret what each statistic tells us about the dataset.
81+
```
82+
83+
### Prompt 6: Advanced Statistics
84+
```
85+
Test the stats_summary tool with this dataset: [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]
86+
87+
Then use the percentile tool to find:
88+
1. 25th percentile
89+
2. 75th percentile
90+
3. 90th percentile
91+
92+
Explain what these percentiles mean in practical terms.
93+
```
94+
95+
---
96+
97+
## 🔄 **Unit Conversion Tool Tests**
98+
99+
### Prompt 7: Length and Weight Conversions
100+
```
101+
Use the unit_conversion tool for these conversions:
102+
1. Convert 100 meters to feet
103+
2. Convert 50 kilograms to pounds
104+
3. Convert 24 inches to centimeters
105+
4. Convert 5 miles to kilometers (use "mi" and "km")
106+
107+
For each conversion, explain the practical application of the result.
108+
```
109+
110+
### Prompt 8: Temperature and Volume Conversions
111+
```
112+
Test temperature and volume conversions:
113+
1. Convert 32°F to Celsius (use "F" and "C")
114+
2. Convert 100°C to Fahrenheit
115+
3. Convert 273.15 Kelvin to Celsius (use "K" and "C")
116+
4. Convert 5 liters to gallons (use "l" and "gal")
117+
5. Convert 1 gallon to liters
118+
119+
Explain when these conversions might be needed in real-world scenarios.
120+
```
121+
122+
### Prompt 9: Batch Conversions
123+
```
124+
Use the batch_conversion tool to convert multiple values at once:
125+
1. Convert [1, 2, 3, 4, 5] meters to feet
126+
2. Convert [10, 20, 30, 40, 50] pounds to kilograms (use "lb" and "kg")
127+
128+
Compare the efficiency of batch vs individual conversions.
129+
```
130+
131+
---
132+
133+
## 💰 **Financial Tool Tests**
134+
135+
### Prompt 10: Basic Financial Calculations
136+
```
137+
Test these financial scenarios with the financial tool:
138+
1. Simple interest: $5000 principal, 4% rate, 3 years
139+
2. Compound interest: $5000 principal, 4% rate, 3 years, monthly compounding (12 periods)
140+
3. Loan payment: $250000 loan, 3.5% rate, 30 years
141+
4. ROI calculation: initial investment $10000, final value $15000
142+
143+
Explain what each calculation tells an investor or borrower.
144+
```
145+
146+
### Prompt 11: Advanced Financial Analysis
147+
```
148+
Test advanced financial tools:
149+
1. Use the npv tool with these cash flows: [-50000, 15000, 20000, 25000, 30000] at 8% discount rate
150+
2. Use the irr tool with the same cash flows
151+
3. Use loan_comparison tool to compare:
152+
- Loan A: $200000, 4.5% rate, 30 years
153+
- Loan B: $200000, 3.8% rate, 15 years
154+
155+
Interpret the results for investment decision-making.
156+
```
157+
158+
---
159+
160+
## 🧮 **Expression Evaluation Tests**
161+
162+
### Prompt 12: Simple Expressions
163+
```
164+
Test the expression_eval tool with:
165+
1. Simple arithmetic: "10 + 5 * 2"
166+
2. With parentheses: "(10 + 5) * 2"
167+
3. Using pi constant: "pi * 4"
168+
4. Using e constant: "e * 2"
169+
5. With variables: "x * 2 + y" where x=10, y=5
170+
171+
Note which expressions work and which encounter errors.
172+
```
173+
174+
### Prompt 13: Complex Expressions (Test Limitations)
175+
```
176+
Test these more complex expressions to identify limitations:
177+
1. "sqrt(16) + 4"
178+
2. "sin(pi/2) + cos(0)"
179+
3. "pow(2, 3) + 1"
180+
4. "2^3 + sqrt(9)"
181+
5. "abs(-5) + ln(e)"
182+
183+
Document which functions work within expressions vs. as individual function calls.
184+
```
185+
186+
---
187+
188+
## 🎯 **Comprehensive Integration Tests**
189+
190+
### Prompt 14: Multi-Tool Workflow
191+
```
192+
Create a comprehensive analysis using multiple tools:
193+
194+
Scenario: Analyzing a small business investment
195+
1. Use basic_math to calculate total startup costs: $25000 + $15000 + $8000
196+
2. Use financial tool to calculate loan payment for the total at 5.5% for 7 years
197+
3. Use statistics to analyze projected monthly revenues: [3500, 4200, 3800, 4500, 4100, 3900, 4300]
198+
4. Use unit_conversion to convert 500 square meters to square feet for office space
199+
5. Use expression_eval to calculate monthly profit: "revenue - expenses" where revenue=4100, expenses=2800
200+
201+
Present this as a business analysis report.
202+
```
203+
204+
### Prompt 15: Scientific Calculation Workflow
205+
```
206+
Perform a scientific calculation sequence:
207+
1. Use advanced_math to calculate sin(30°), cos(30°), and tan(30°)
208+
2. Use expression_eval to verify the trigonometric identity: "sin_val^2 + cos_val^2" where sin_val and cos_val are your results from step 1
209+
3. Use basic_math to calculate the area of a circle with radius 5: π × r²
210+
4. Use unit_conversion to convert this area from m² to ft²
211+
5. Use statistics to analyze measurement errors: [4.98, 5.02, 4.97, 5.01, 4.99, 5.03, 4.96]
212+
213+
Present as a scientific measurement report.
214+
```
215+
216+
---
217+
218+
## 🔍 **Error Testing and Edge Cases**
219+
220+
### Prompt 16: Systematic Error Testing
221+
```
222+
Test error handling across different tools:
223+
1. basic_math: Try division by zero
224+
2. advanced_math: Try factorial of negative number
225+
3. statistics: Try operations on empty dataset []
226+
4. unit_conversion: Try invalid units "xyz" to "abc"
227+
5. expression_eval: Try malformed expression "2 + + 3"
228+
6. financial: Try negative time period
229+
230+
Document how each tool handles invalid inputs.
231+
```
232+
233+
### Prompt 17: Boundary Testing
234+
```
235+
Test boundary conditions:
236+
1. Very large numbers: 999999999999 × 999999999999
237+
2. Very small numbers: 0.000000001 × 0.000000001
238+
3. Maximum precision: Calculate 1/7 with maximum decimal places
239+
4. Large datasets: Generate and analyze statistics for 100 random numbers
240+
5. Extreme temperatures: Convert -273°C to Kelvin and Fahrenheit
241+
242+
Report any limitations or unexpected behaviors.
243+
```
244+
245+
---
246+
247+
## 📝 **Usage Instructions for AI Agents**
248+
249+
### How to Use These Prompts:
250+
1. **Copy and paste** any prompt directly to an AI agent with calculator server access
251+
2. **Sequential testing**: Use prompts in order for systematic coverage
252+
3. **Custom modifications**: Adjust numbers and scenarios for specific use cases
253+
4. **Error documentation**: Note any failures or limitations discovered
254+
5. **Performance observation**: Monitor response times and accuracy
255+
256+
### Expected Outcomes:
257+
- **Functional verification**: Confirm all tools work as expected
258+
- **Limitation discovery**: Identify areas needing improvement
259+
- **Integration testing**: Verify tools work well together
260+
- **Error handling**: Confirm robust error responses
261+
- **Performance assessment**: Evaluate speed and accuracy
262+
263+
### Reporting Template:
264+
```
265+
## Test Results for [Tool Name]
266+
- **Prompt Used**: [Prompt number and description]
267+
- **Tests Passed**: X/Y
268+
- **Failures**: [List any failures with error messages]
269+
- **Performance**: [Response time observations]
270+
- **Notes**: [Any interesting observations]
271+
```
272+
273+
---
274+
275+
## 🎯 **Quick Test Commands**
276+
277+
For rapid testing, use these single-line prompts:
278+
279+
```bash
280+
# Quick basic math test
281+
"Calculate: 15+25, 100-45, 12*8, 144/12 using basic_math tool"
282+
283+
# Quick advanced math test
284+
"Calculate: sin(90°), cos(0), sqrt(64), factorial(5) using advanced_math tool"
285+
286+
# Quick statistics test
287+
"Find mean, median, mode of [10,20,30,20,40] using statistics tool"
288+
289+
# Quick unit conversion test
290+
"Convert: 10m→ft, 5kg→lb, 25°C→°F using unit_conversion tool"
291+
292+
# Quick financial test
293+
"Calculate simple interest: $1000, 5%, 2 years using financial tool"
294+
```
295+
296+
These prompts provide comprehensive testing coverage and can be used with any AI agent that has access to the calculator server tools.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Avinash Sangle
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

0 commit comments

Comments
 (0)