MCP Math Server
A Mathematical Computation Protocol server providing 286 mathematical functions across multiple domains with flexible transport options (STDIO/HTTP) and streaming capabilities.
README
🧮 Chuk MCP Math Server
A highly configurable Mathematical Computation Protocol (MCP) server that provides comprehensive mathematical functions with flexible transport options and streaming capabilities.
✨ Features
🔢 Mathematical Capabilities
- 286 Mathematical Functions across multiple domains
- Number Theory: Prime testing, factorization, GCD, LCM, sequences
- Arithmetic: Basic operations, advanced calculations, statistics
- Real-time Computation: Async processing with timeout support
- Function Filtering: Configurable whitelisting/blacklisting by domain or category
🚀 Transport & Streaming
- Dual Transport: STDIO and HTTP support
- HTTP Streaming: Server-Sent Events for intensive computations
- WebSocket Ready: Extensible for real-time applications
- CORS Support: Cross-origin requests enabled
⚙️ Configuration
- CLI Configuration: Comprehensive command-line options
- File Configuration: YAML and JSON config file support
- Environment Variables: Container-friendly configuration
- Dynamic Filtering: Runtime function filtering capabilities
🛡️ Production Ready
- Health Monitoring: Built-in health check endpoints
- Error Handling: Graceful failure management
- Logging: Configurable log levels and output
- Rate Limiting: Optional request throttling
- Timeout Management: Configurable computation timeouts
🚀 Quick Start
Installation
# Clone the repository
git clone https://github.com/chuk-mcp/chuk-mcp-math-server.git
cd chuk-mcp-math-server
# Install dependencies
uv sync
# or
pip install -e .
Basic Usage
STDIO Transport (MCP Standard)
# Start server with STDIO transport
uv run chuk-mcp-math-server
# Or with Python
python src/chuk_mcp_math_server/math_server.py
HTTP Transport
# Start HTTP server
uv run chuk-mcp-math-server --transport http --port 8000
# Server will be available at http://localhost:8000
Example Client Usage
Test with Examples
# Test STDIO client
uv run examples/stdio_client_example.py
# Test HTTP client with streaming
uv run examples/http_client_example.py
Basic HTTP API Usage
# Check server status
curl http://localhost:8000/
# Health check
curl http://localhost:8000/health
# Sample response:
# {
# "server": "chuk-mcp-math-server",
# "version": "0.1.0",
# "functions_available": 286,
# "transport": "http"
# }
📖 Documentation
Available Functions
The server provides 286 mathematical functions across these domains:
| Domain | Functions | Examples |
|---|---|---|
| Arithmetic | Basic operations, statistics | add, multiply, mean, variance |
| Number Theory | Primes, factorization, sequences | is_prime, next_prime, fibonacci, gcd |
| Advanced Math | Complex calculations | sqrt, power, factorial, combinations |
Configuration Options
Command Line
# Basic configuration
chuk-mcp-math-server --transport http --port 8080 --host 0.0.0.0
# Function filtering
chuk-mcp-math-server --domains arithmetic number_theory --functions is_prime add
# Performance tuning
chuk-mcp-math-server --cache-strategy smart --timeout 60 --max-concurrent 20
# Logging
chuk-mcp-math-server --verbose # Debug logging
chuk-mcp-math-server --quiet # Minimal logging
Configuration File
# config.yaml
transport: "http"
port: 8000
host: "0.0.0.0"
enable_cors: true
log_level: "INFO"
# Function filtering
domain_whitelist: ["arithmetic", "number_theory"]
function_blacklist: ["slow_function"]
# Performance
cache_strategy: "smart"
cache_size: 1000
computation_timeout: 30.0
max_concurrent_calls: 10
# Use configuration file
chuk-mcp-math-server --config config.yaml
Environment Variables
export MCP_MATH_TRANSPORT="http"
export MCP_MATH_PORT=8000
export MCP_MATH_LOG_LEVEL="DEBUG"
export MCP_MATH_DOMAIN_WHITELIST="arithmetic,number_theory"
chuk-mcp-math-server
MCP Protocol Usage
Initialize Connection
{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2025-03-26",
"clientInfo": {
"name": "my-math-client",
"version": "1.0.0"
}
}
}
List Available Tools
{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/list"
}
Call Mathematical Function
{
"jsonrpc": "2.0",
"id": 3,
"method": "tools/call",
"params": {
"name": "is_prime",
"arguments": {
"n": 97
}
}
}
🛠️ Development
Project Structure
chuk-mcp-math-server/
├── src/chuk_mcp_math_server/
│ ├── __init__.py # Package initialization
│ ├── _version.py # Dynamic version management
│ ├── _cli.py # CLI utilities
│ └── math_server.py # Main server implementation
├── examples/
│ ├── stdio_client_example.py # STDIO client demo
│ └── http_client_example.py # HTTP client demo
├── tests/ # Test suite
├── pyproject.toml # Project configuration
└── README.md # This file
Development Setup
# Install development dependencies
uv sync --group dev
# Install with all optional features
pip install -e .[full]
# Run formatting
black src/ examples/
isort src/ examples/
# Run tests
pytest
# Version information
chuk-mcp-math-server-info
Adding New Functions
- Add mathematical functions to the
chuk-mcp-mathlibrary - Functions are automatically discovered and registered
- Use function filtering to control exposure
Custom Configuration
from chuk_mcp_math_server import ServerConfig, ConfigurableMCPMathServer
# Create custom configuration
config = ServerConfig(
transport="http",
port=9000,
domain_whitelist=["arithmetic"],
enable_cors=True,
log_level="DEBUG"
)
# Start server
server = ConfigurableMCPMathServer(config)
await server.run()
🌐 HTTP API Reference
Endpoints
| Endpoint | Method | Description |
|---|---|---|
/ |
GET | Server status and information |
/health |
GET | Health check and function count |
/mcp |
POST | MCP protocol messages |
HTTP Streaming
The server supports Server-Sent Events (SSE) for computationally intensive operations:
// Request with streaming
fetch('/mcp', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'text/event-stream'
},
body: JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'tools/call',
params: {
name: 'fibonacci',
arguments: { n: 1000 }
}
})
})
📊 Performance
Benchmarks
- Function Calls: ~1000 ops/sec (simple arithmetic)
- Prime Testing: ~100 ops/sec (medium-sized numbers)
- Memory Usage: ~50MB baseline + computation overhead
- Startup Time: ~2 seconds (286 functions loaded)
Optimization Tips
- Use
cache_strategy: "smart"for repeated calculations - Increase
max_concurrent_callsfor high-throughput scenarios - Use function filtering to reduce memory footprint
- Enable HTTP streaming for long-running computations
🔧 Troubleshooting
Common Issues
Server Won't Start
# Check dependencies
chuk-mcp-math-server-info
# Verify configuration
chuk-mcp-math-server --show-config
# Debug mode
chuk-mcp-math-server --verbose
Function Not Available
# List all functions
chuk-mcp-math-server --domains arithmetic --show-config
# Check filtering
chuk-mcp-math-server --functions is_prime add --show-config
HTTP Connection Issues
# Test server health
curl http://localhost:8000/health
# Check CORS settings
chuk-mcp-math-server --transport http --enable-cors
Debug Information
# Get detailed system info
chuk-mcp-math-server-info --info
# Check version detection
python -c "import chuk_mcp_math_server; chuk_mcp_math_server.print_version_info()"
🤝 Contributing
We welcome contributions! Please see our Contributing Guide for details.
Development Workflow
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Run the test suite
- Submit a pull request
Code Style
- Use
blackfor code formatting - Use
isortfor import sorting - Follow PEP 8 guidelines
- Add type hints where appropriate
📋 Requirements
Core Dependencies
- Python 3.11+
chuk-mcp >= 0.5chuk-mcp-math >= 0.1.0fastapi >= 0.116.1uvicorn >= 0.35.0httpx >= 0.28.1pyyaml >= 6.0.2
Optional Dependencies
- Development tools:
pytest,black,isort,mypy - All optional:
pip install chuk-mcp-math-server[full]
📝 License
This project is licensed under the MIT License - see the LICENSE file for details.
🙏 Acknowledgments
- Built on the Model Context Protocol (MCP)
- Mathematical functions provided by chuk-mcp-math
- Inspired by the need for accessible mathematical computation services
🔗 Links
- Documentation: GitHub Wiki
- Issues: GitHub Issues
- MCP Protocol: Official MCP Docs
- Mathematical Functions: chuk-mcp-math
Made with ❤️ by the Chuk MCP Team
Bringing mathematical computation to the Model Context Protocol ecosystem
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。