数学计算协议服务器

基于高性能chuk-mcp-server框架构建的可配置数学计算协议服务器,提供642种数学函数和灵活的传输选项,适用于各种数学计算场景。

  • by IBM
  • Python
  • 本地部署
  • 4 星标
  • 更新于
在 GitHub 查看 chrishayuk/chuk-mcp-math-server

使用说明

🧮 Chuk MCP数学服务器

高度可配置 数学计算协议(MCP)服务器 它提供了全面的数学函数和灵活的传输选项。基于高性能chuk-mcp服务器框架构建。

⚡ 演出

  • 36000+转/分 峰值吞吐量(继承自chuk mcp服务器)
  • 低于3毫秒的延迟 每次工具调用
  • 642数学函数 可用的
  • 零配置启动 -开箱即用

✨ 特性

🔢 数学能力

  • 642数学函数 跨多个域
  • 数论:素数测试、因子分解、GCD、LCM、序列(328个函数)
  • 算术:基本操作、高级计算(44个功能)
  • 三角学:综合三角运算(71个函数)
  • 线性代数:向量和矩阵运算(33个函数)
  • 统计:描述性和推理统计(15个函数)
  • 微积分:衍生工具、集成、根查找(9个功能)
  • 几何:形状、距离、交点(12个函数)
  • 概率:分配职能(10个职能)
  • 高级操作:复杂的数学运算(22个函数)
  • 序列:数学序列(12个函数)
  • 常量:数学常数(25个函数)
  • 转化:单位和类型转换(7个功能)
  • 实时计算:具有适当错误处理的异步处理
  • 功能过滤:可按域、类别或功能配置allowlists和denylists

🚀 交通与建筑

  • 双重运输:STDIO(克劳德桌面)和HTTP支持
  • 高性能:基于chuk-mcp服务器框架构建
  • 自动检测:自动选择最佳运输模式
  • 生产就绪:36000+RPS,延迟<3ms
  • 类型安全:从Python类型提示自动生成模式

⚙️ 配置

  • CLI配置:全面的命令行选项
  • 文件配置:支持YAML和JSON配置文件
  • 环境变量:容器友好配置
  • 动态过滤:使用allowlists和denylists进行运行时函数过滤
  • 精细控制:按功能、域或类别筛选

🛡️ 生产特点

  • 零配置:使用合理的默认值即可开箱即用
  • 高测试覆盖率:97%的代码覆盖率,114个综合测试
  • 类型安全:使用mypy进行100%类型检查,完全Pydantic原生
  • 错误处理:优雅的故障管理
  • 日志记录:可配置的日志级别和输出
  • MCP资源:用于函数发现和统计的内置资源
  • 超时管理:可配置的计算超时

🚀 快速开始

💡 现在试试! 使用我们的免费公共服务器 https://math.chukai.io/mcp -无需安装!看 公用服务器 下面的部分。

安装

使用uvx(推荐-无需安装!)

使用服务器的最简单方法是 uvx,无需安装即可运行:

uvx chuk-mcp-math-server

这将自动下载并运行最新版本。非常适合克劳德桌面!

使用紫外线(建议用于开发)

# Install from PyPI
uv pip install chuk-mcp-math-server

# Or clone and install from source
git clone https://github.com/chuk-mcp/chuk-mcp-math-server.git
cd chuk-mcp-math-server
uv sync

使用pip(传统)

pip install chuk-mcp-math-server

基本用法

STDIO传输(克劳德桌面)

# Start server with STDIO transport (default)
uv run chuk-mcp-math-server

# Starts immediately with all 642 functions available

HTTP传输(Web API)

# Start HTTP server
uv run chuk-mcp-math-server --transport http --port 8000

# Server will be available at http://localhost:8000

Claude桌面集成

添加到您的Claude桌面配置(~/Library/Application Support/Claude/claude_desktop_config.json 在macOS上):

选项1:使用公共服务器(最简单)

连接到托管的公共服务器:

{
  "mcpServers": {
    "math": {
      "command": "uvx",
      "args": [
        "chuk-mcp-client",
        "https://math.chukai.io/mcp"
      ]
    }
  }
}

这不需要本地安装,并且始终是最新的!

选项2:使用uvx在本地运行

{
  "mcpServers": {
    "math": {
      "command": "uvx",
      "args": ["chuk-mcp-math-server"]
    }
  }
}

选项3:使用本地安装在本地运行

{
  "mcpServers": {
    "math": {
      "command": "uv",
      "args": [
        "--directory",
        "/absolute/path/to/chuk-mcp-math-server",
        "run",
        "chuk-mcp-math-server"
      ]
    }
  }
}

重要提示: 使用绝对路径,而不是相对路径或 ~ 路径。

重新启动Claude Desktop并问:“你能检查97是否是素数吗?”-Claude将使用数学服务器!

HTTP API使用示例

# Test the server
curl http://localhost:8000/mcp \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "tools/list"
  }'

# Call a mathematical function
curl http://localhost:8000/mcp \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "id": 2,
    "method": "tools/call",
    "params": {
      "name": "is_prime",
      "arguments": {"n": 97}
    }
  }'

📖 文档

可用功能

服务器提供 642数学函数 跨越这些领域:

域 函数 示例
算术与数论 (420) 基本运算、素数、序列、可分性 add, multiply, modulo, is_prime, fibonacci, gcd
三角学 (71) 三角函数,双曲线,转换 sin, cos, tan, sinh, radians_to_degrees
线性代数 (33) 向量和矩阵运算 dot_product, cross_product, matrix_multiply
统计 (15) 描述性统计 mean, median, std_dev, variance
微积分 (9) 衍生品、整合、根查找 derivative, integrate, newton_raphson
几何 (12) 形状、距离、交点 circle_area, distance, triangle_area
概率 (10) 分配功能 normal_pdf, binomial_pmf
其他 (17) 高级操作、序列、常量、转换 factorial, combinations, pi_digits

功能过滤

控制暴露的功能:

# Only expose specific functions
chuk-mcp-math-server --functions add subtract multiply divide

# Expose only arithmetic domain
chuk-mcp-math-server --domains arithmetic

# Exclude specific functions
chuk-mcp-math-server --exclude-functions slow_function

# Combine filters
chuk-mcp-math-server --domains arithmetic number_theory --categories core primes

配置选项

命令行

# Basic configuration
chuk-mcp-math-server --transport http --port 8080 --host 0.0.0.0

# Function filtering
chuk-mcp-math-server --domains arithmetic --functions is_prime add

# Performance tuning
chuk-mcp-math-server --cache-strategy smart --timeout 60

# Logging
chuk-mcp-math-server --verbose  # Debug logging
chuk-mcp-math-server --quiet    # Minimal logging

配置文件

# config.yaml
transport: "http"
port: 8000
host: "0.0.0.0"
log_level: "INFO"

# Function filtering (allowlist: only these are enabled, denylist: these are excluded)
domain_allowlist: ["arithmetic", "number_theory"]
function_allowlist: ["is_prime", "fibonacci", "add", "multiply"]
function_denylist: ["deprecated_function"]  # Exclude specific functions

# 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

# Save current config
chuk-mcp-math-server --domains arithmetic --save-config my-config.yaml

# Show current config
chuk-mcp-math-server --show-config

MCP资源

服务器提供了用于自检的内置资源:

# List available functions (via MCP resource)
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "resources/read",
  "params": {
    "uri": "math://available-functions"
  }
}

# Get function statistics
{
  "jsonrpc": "2.0",
  "id": 2,
  "method": "resources/read",
  "params": {
    "uri": "math://function-stats"
  }
}

# Get server configuration
{
  "jsonrpc": "2.0",
  "id": 3,
  "method": "resources/read",
  "params": {
    "uri": "math://server-config"
  }
}

🛠️ 发展

项目结构

chuk-mcp-math-server/
├── src/chuk_mcp_math_server/
│   ├── __init__.py              # Package initialization
│   ├── cli.py                   # CLI implementation
│   ├── config.py                # Base configuration (Pydantic)
│   ├── math_config.py           # Math-specific configuration
│   ├── function_filter.py       # Function filtering logic
│   └── math_server.py           # Main server (uses chuk-mcp-server)
├── tests/                       # Test suite (97% coverage, 114 tests)
├── pyproject.toml              # Project configuration
└── README.md                   # This file

开发设置

# Clone the repository
git clone https://github.com/chuk-mcp/chuk-mcp-math-server.git
cd chuk-mcp-math-server

# Install development dependencies
uv sync

# Install in editable mode
uv pip install -e ".[dev]"

运行测试

# Run tests
make test

# Run tests with coverage
make test-cov

# Run specific test file
uv run pytest tests/test_config.py -v

代码质量

# Run all quality checks (lint, typecheck, security, tests)
make check

# Format code
make format

# Run linting
make lint

# Run type checking
make typecheck

# Run security checks
make security

建筑

# Build distribution packages
make build

# This creates wheel and source distributions in dist/

本地运行

# Run with verbose logging
uv run chuk-mcp-math-server --verbose

# Run HTTP server
make run-http

# Run STDIO server (default)
make run

自定义服务器

from chuk_mcp_math_server import create_math_server

# Create server with custom configuration
server = create_math_server(
    transport="http",
    port=9000,
    domain_allowlist=["arithmetic"],  # Only arithmetic functions
    function_denylist=["deprecated_func"],  # Exclude specific functions
    log_level="DEBUG"
)

# Run the server
server.run()

🚀 部署

码头工人

使用Docker构建和运行:

# Build the Docker image
make docker-build

# Run the container
make docker-run

# Or manually:
docker build -t chuk-mcp-math-server .
docker run -p 8000:8000 chuk-mcp-math-server

服务器将在以下时间可用 http://localhost:8000.

Fly.io

部署到公共服务器的Fly.io:

# Install flyctl if you haven't already
curl -L https://fly.io/install.sh | sh

# Login to Fly.io
flyctl auth login

# Deploy (first time)
flyctl launch

# Or deploy updates
flyctl deploy

# Check status
flyctl status

# View logs
flyctl logs

这 fly.toml 端口8000上的HTTP模式配置已设置。服务器将根据流量自动缩放(最小0,自动启动/停止)。

环境变量

通过Fly.io secrets进行配置:

# Set environment variables
flyctl secrets set MCP_SERVER_LOG_LEVEL=INFO
flyctl secrets set MCP_MATH_CACHE_STRATEGY=smart

# View secrets
flyctl secrets list

GitHub操作

该存储库包括自动化工作流:

  • 测试:在所有PR和提交上运行(Ubuntu、Windows、macOS)
  • 发布:推送标签时创建GitHub版本
  • 发布:在发布时自动发布到PyPI
  • 飞行部署:在主分支推送时自动部署到Fly.io

要创建版本,请执行以下操作:

# Bump version in pyproject.toml
make bump-patch  # or bump-minor, bump-major

# Commit the version change
git add pyproject.toml uv.lock
git commit -m "Bump version to 0.2.1"
git push

# Create and push a tag to trigger release
make publish

这将自动:

  1. 使用changelog创建GitHub版本
  2. 在所有平台上运行测试
  3. 构建并发布到PyPI
  4. 部署到Fly.io(如果已配置)

📊 演出

基准测试

  • 峰值吞吐量:36000+请求/秒
  • 平均延迟:每次工具调用<3ms
  • 启动时间:约2秒(加载642个函数)
  • 内存使用:~50MB基线
  • 成功率:100%负载测试

性能来自:

  • chuk mcp服务器框架:高性能MCP实施
  • 异步操作:所有函数调用的非阻塞I/O
  • 类型安全性:零开销的自动架构验证
  • 优化注册表:快速查找和执行函数

优化提示

  • 使用函数过滤来减少内存占用
  • 为重复计算启用缓存(--cache-strategy smart)
  • web API使用HTTP传输,本地/Claude Desktop使用STDIO
  • 调整 --max-concurrent-calls 适用于高通量场景

🔧 故障排除

常见问题

服务器无法启动

# Verify installation
python -c "import chuk_mcp_math_server; print(chuk_mcp_math_server.__version__)"

# Verify configuration
chuk-mcp-math-server --show-config

# Debug mode
chuk-mcp-math-server --verbose

功能未加载

# Check if chuk-mcp-math is installed
python -c "import chuk_mcp_math; print(chuk_mcp_math.__version__)"

# Verify function count
chuk-mcp-math-server --show-config | grep total_filtered

Claude桌面未显示工具

  1. 使用 绝对路径 在claude_desktop_config json中(不是 ~ 或相对)
  2. 手动测试: echo '{"jsonrpc":"2.0","method":"tools/list","id":1}' | uv run chuk-mcp-math-server
  3. 配置更改后重新启动Claude Desktop
  4. 检查克劳德桌面日志(帮助→ 显示日志)

HTTP连接问题

# Test server health
curl http://localhost:8000/mcp \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","method":"tools/list","id":1}'

🌐 公用服务器

免费的公共数学服务器可在 https://math.chukai.io/mcp 供任何人使用!

特性

  • ✅ 始终可用:托管在Fly.io上,具有自动扩展功能
  • ✅ 始终保持最新:从主分支自动部署
  • ✅ 全部642个功能:完整的数学函数库
  • ✅ 无需安装:只需添加到Claude Desktop配置中
  • ✅ 免费使用:不需要身份验证或API密钥

快速开始

将此添加到您的Claude Desktop配置中:

{
  "mcpServers": {
    "math": {
      "command": "uvx",
      "args": [
        "chuk-mcp-client",
        "https://math.chukai.io/mcp"
      ]
    }
  }
}

然后重新启动Claude Desktop并问:“你能检查97是否是素数吗?”

测试公共服务器

服务器需要通过HTTP对MCP进行会话管理。使用 chuk-mcp-client 要连接:

# Install the client
uvx chuk-mcp-client https://math.chukai.io/mcp

# Or test with curl (requires session ID from chuk-mcp-server)
curl https://math.chukai.io/mcp \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","method":"tools/list","id":1}'

备注:服务器使用chuk-mcp服务器的基于会话的HTTP传输,这需要 chuk-mcp-client 以进行适当的会话管理。

隐私和使用

  • 不记录工具调用或个人数据
  • 无费率限制(合理使用适用)
  • 根据需求自动缩放
  • 源代码是开放的,可审计的

自我寄宿

想举办自己的活动吗?请参阅 部署 以上部分是Docker和Fly.io的说明。

🤝 贡献

我们欢迎捐款!以下是如何提供帮助:

  1. 克隆该仓库
  2. 创建要素分支(git checkout -b feature/amazing-feature)
  3. 进行更改
  4. 如果适用,添加测试
  5. 确保测试通过(pytest)
  6. 提交拉取请求

代码风格

  • 遵循PEP 8指南
  • 使用mypy和Pydantic保持100%的类型安全
  • 在适当的地方添加类型提示
  • 更新新功能的文档
  • 保持README最新
  • 追求高测试覆盖率(目前为97%)

📋 需求

核心依赖关系

  • Python 3.11+
  • chuk-mcp-server >= 0.6 (提供高性能MCP框架)
  • chuk-mcp-math >= 0.1.0 (提供数学函数)
  • pyyaml >= 6.0.2 (用于YAML配置)

通过chuk mcp服务器包含什么

  • 高性能HTTP/STDIO传输
  • 自动类型推断和验证
  • 内置日志记录和错误处理
  • 零配置启动功能
  • 生产级性能(36K+RPS)

可选依赖关系

  • 开发工具: pytest, pytest-asyncio
  • 全部可选: pip install -e .[dev]

🏗️ 建筑

建立在 chuk mcp服务器 框架:

  • chuk mcp服务器:高性能MCP服务器框架(36K+RPS)
  • 丘数学:数学函数库(642个函数)
  • 此服务器:通过过滤和配置将两者连接起来

重构后的架构更简单,性能更高:

  • 删除了自定义基础服务器实现
  • 使用chuk-mcp-server的基于装饰器的API
  • 维护所有过滤和配置功能
  • 获得自动性能优化

📝 许可证

此项目根据Apache许可证2.0获得许可-请参阅 许可证 文件以获取详细信息。

🙏 致谢

🔗 链接


模型上下文协议生态系统的高性能数学计算