-
Notifications
You must be signed in to change notification settings - Fork 293
Add comprehensive calculator-server to mcp-servers/go #951
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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]>
Hi, Great contribution! One request though, could you make this available under Apache 2.0 to be compatible with the core project before contributing (no need for a separate LICENSE, inherit from project LICENSE) - and review Closes #920 Thanks! |
- Replace MIT License with Apache License 2.0 for core project compatibility - Update README.md with Apache 2.0 license badge and statement - Maintain copyright holder as Avinash Sangle (2024) - Ensure compatibility with IBM and other Apache 2.0 licensed projects - Comprehensive documentation with updated licensing information 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> Signed-off-by: Avinash Sangle <[email protected]>
@crivetimihai I have updated the License to Apache 2.0 also added Signed-off-by line to be DCO compliant. Please review and accept. |
Clean up YAML formatting by removing trailing whitespace to fix yamllint errors in the calculator-server configuration file. This improves code quality and ensures consistent formatting across MCP servers. Signed-off-by: Avinash Sangle <[email protected]>
The LICENSE file in mcp-servers/go/calculator-server/ is no longer needed as the license was updated from MIT to Apache 2.0 at the project level. Signed-off-by: Avinash Sangle <[email protected]>
Add Apache-2.0 license headers with proper copyright, location, and authorship information to Python test files in calculator-server. - test_additional_tools.py: Added complete header with encoding, location, copyright, license, and author - test_tools.py: Added complete header with encoding, location, copyright, license, and author Ensures compliance with project licensing standards and proper attribution. Signed-off-by: Avinash Sangle <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Go Calculator Server - Code Review
High Priority Issues
1. Personal Information Exposure
File: cmd/server/main.go:5-8
- Issue: Hardcoded personal information (author name, email, GitHub, website)
- Fix: Remove personal details, keep generic project description only
2. Missing Function Implementation
File: internal/calculator/expression.go
- Issue:
factorial
function listed in schema but not implemented ingetMathFunctions()
- Fix: Add factorial function implementation with overflow protection
3. Security Risk - CORS Configuration
File: pkg/mcp/streamable_http_transport.go:63
- Issue: Default CORS allows all origins (
[]string{"*"}
) - Fix: Use restrictive default origins or require explicit configuration
Functional Issues
4. Handler Misplacement
File: cmd/server/main.go:175
- Issue: Unit conversion handled by
statsHandler
instead of dedicated handler - Fix: Create dedicated
UnitConversionHandler
or move tomathHandler
5. Missing pow Function in Advanced Math
File: Advanced math handler vs expression evaluator
- Issue:
pow
function only available in expression evaluation, not advanced math tools - Fix: Add
pow
function to advanced math handler
6. Silent Error Handling
File: pkg/mcp/streamable_http_transport.go:264
- Issue:
json.Marshal
error ignored with_
- Fix: Proper error handling and logging
Configuration Issues
7. Unused Rate Limiting
File: internal/config/config.go:80-83
- Issue: Rate limiting configuration defined but not implemented
- Fix: Implement rate limiting middleware or remove unused config
8. HTTP Error Code Mapping
File: pkg/mcp/streamable_http_transport.go:327-330
- Issue: All unknown JSON-RPC errors map to 500 status
- Fix: Add more specific error code mappings for custom errors
Code Quality Issues
9. Incomplete Variable Extraction
File: internal/calculator/expression.go:355-384
- Issue:
ExtractVariables
method incomplete and returns empty slice - Fix: Implement proper variable extraction or remove unused method
10. Hardcoded Magic Numbers
File: internal/calculator/expression.go:212
- Issue: Hardcoded overflow threshold
700
for exp function - Fix: Define as constant with documentation
…mproved functionality Add comprehensive Apache 2.0 license headers to all Go source files and tests. Improve expression parsing, error handling, and test coverage. Add .gitignore for proper dependency management. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> Signed-off-by: Avinash Sangle <[email protected]>
Remove obsolete test files and results documentation, update configuration samples and README to reflect current project state. Signed-off-by: Claude <[email protected]> Signed-off-by: Avinash Sangle <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remaining Issues for PR #951 - Calculator Server Review
Overview
This document tracks the remaining issues from the comprehensive code review of PR #951 that need to be addressed before merge approval.
Status: 4/10 major issues have been resolved. 6 issues remain to be verified/fixed.
✅ Resolved Issues
1. Personal Information Exposure ✅ FIXED
- Original Issue: Hardcoded personal information (author name, email, GitHub, website) in
cmd/server/main.go:5-8
- Resolution: All personal details removed, replaced with standard Apache 2.0 license headers only
2. CORS Security Risk ✅ FIXED
- Original Issue: Default CORS allows all origins (
[]string{"*"}
) inpkg/mcp/streamable_http_transport.go:63
- Resolution: Changed to restrictive defaults
["http://localhost:3000", "http://127.0.0.1:3000"]
with explicit production warnings
3. Missing Factorial Function ✅ FIXED
- Original Issue:
factorial
function listed in schema but not implemented ingetMathFunctions()
- Resolution: Factorial function properly implemented across advanced math handler, expression evaluator, with comprehensive tests and overflow protection
4. Licensing and DCO Compliance ✅ FIXED
- Original Issue: Apache 2.0 license compatibility and DCO compliance
- Resolution: Apache 2.0 license headers added throughout codebase, DCO sign-off included in commits
⚠️ Outstanding Issues (Requires Verification)
5. Handler Misplacement ⚠️ PENDING
- File:
cmd/server/main.go:175
- Issue: Unit conversion handled by
statsHandler
instead of dedicated handler - Required Fix: Create dedicated
UnitConversionHandler
or move tomathHandler
- Priority: Medium
- Status: Needs verification if this was addressed in recent commits
6. Silent Error Handling ⚠️ PENDING
- File:
pkg/mcp/streamable_http_transport.go:264
- Issue:
json.Marshal
error ignored with_
- Required Fix: Proper error handling and logging
- Priority: Medium
- Code Pattern:
_, err := json.Marshal(...)
whereerr
is ignored - Status: Needs code inspection to verify if addressed
7. Missing pow Function in Advanced Math ⚠️ PENDING
- Issue:
pow
function only available in expression evaluation, not advanced math tools - Required Fix: Add
pow
function to advanced math handler - Priority: Low
- Status: Function appears in documentation but needs verification in actual handler implementation
8. Unused Rate Limiting Configuration ⚠️ PENDING
- File:
internal/config/config.go:80-83
- Issue: Rate limiting configuration defined but not implemented
- Required Fix: Implement rate limiting middleware or remove unused config
- Priority: Low
- Status: Configuration exists but implementation needs verification
9. HTTP Error Code Mapping ⚠️ PENDING
- File:
pkg/mcp/streamable_http_transport.go:327-330
- Issue: All unknown JSON-RPC errors map to 500 status
- Required Fix: Add more specific error code mappings for custom errors
- Priority: Low
- Note: PR diff shows extensive error code mapping was added, needs verification if complete
10. Incomplete Variable Extraction ⚠️ PENDING
- File:
internal/calculator/expression.go:355-384
- Issue:
ExtractVariables
method incomplete and returns empty slice - Required Fix: Implement proper variable extraction or remove unused method
- Priority: Low
- Status: Method exists but functionality needs verification
Action Items
For Reviewer (@crivetimihai)
- Spot check remaining issues - Verify if items 5-10 have been addressed in recent commits
- Focus on medium priority items - Handler misplacement (#5) and silent error handling (#6)
- Consider acceptable risk - Determine if low priority items (#7-10) are blockers or can be addressed in follow-up PRs
For Author (@avisangle)
- Address handler misplacement - Ensure unit conversion uses appropriate handler
- Fix error handling - Replace any
_
ignored errors with proper handling - Complete missing implementations - Verify all documented functions are actually implemented
- Clean up unused code - Remove or implement rate limiting config and variable extraction
For Final Review
- Verify handler routing is correct
- Check all
json.Marshal
calls have proper error handling - Confirm
pow
function works in advanced math handler - Review error code mapping completeness
- Test variable extraction functionality
Notes
- All CI checks are passing ✅
- Core functionality appears complete ✅
- Security issues have been addressed ✅
- Most critical issues resolved ✅
The remaining issues are primarily code quality and completeness concerns rather than security or functional blockers.
Add comprehensive calculator-server to mcp-servers/go
Summary
This PR adds a comprehensive calculator MCP server to the
mcp-servers/go
collection, providing extensive mathematical capabilities for AI assistants and applications.Features Added
🧮 Mathematical Operations
🔧 Technical Implementation
🛠️ MCP Tools Provided
calculate
: Basic arithmetic operations with validationcalculate_advanced
: Advanced mathematical functions including trigonometry and logarithmsevaluate_expression
: Complex expression parsing and evaluation with operator precedencecalculate_statistics
: Statistical analysis of datasets with multiple metricscalculate_finance
: Financial calculations including PV, FV, PMT, and investment analysisconvert_units
: Unit conversion between different measurement systemsIntegration Details
The calculator-server follows the established patterns in
mcp-servers/go
and integrates seamlessly with:Testing & Validation
Files Added
Usage Example
This addition significantly enhances the mathematical capabilities available in the MCP ecosystem and provides a robust foundation for AI assistants requiring computational tools.