数学逻辑mcp
MCP服务器,提供经过验证的小型LLM符号数学和逻辑工具。
 
小型语言模型(Mistral、Llama、Phi、Gemma)在多步数学和形式逻辑方面存在困难。代替微调, 给他们工具该项目通过 模型上下文协议(MCP),因此任何兼容MCP的LLM都可以将它们作为函数调用。
特性
| 工具 | 功能 | 后端 |
|---|---|---|
verify_arithmetic | 安全算术求值 | Python stdlib(零deps) |
solve_equation | 符号方程求解 | SymPy(可选) |
simplify_expression | 简化/因子化/扩展 | SymPy(可选) |
compute_derivative | 差异化 | SymPy(可选) |
compute_integral | 集成 | SymPy(可选) |
check_logic | SAT/同义反复/真值表 | Z3(可选) |
每个结果包括 验证步骤 和 验证 --LLM得到的是机器检查的答案,而不是猜测。
快速开始
从PyPI安装
pip install math-logic-mcp安装(全部-所有求解器)
pip install "math-logic-mcp[full]"运行MCP服务器
# stdio transport (for Claude Desktop, Cursor, etc.)
math-logic-mcp
# HTTP/SSE transport (for remote clients)
math-logic-mcp --http在Claude桌面中配置
添加 ~/Library/Application Support/Claude/claude_desktop_config.json:
{
"mcpServers": {
"math-logic": {
"command": "math-logic-mcp"
}
}
}在游标中配置
添加 .cursor/mcp.json:
{
"mcpServers": {
"math-logic": {
"command": "math-logic-mcp"
}
}
}用作Python库
from math_logic import MathLogicEngine
engine = MathLogicEngine()
# Arithmetic (always available)
result = engine.solve("compute 2 + 3 * 4")
print(result.solutions) # ['14']
# Algebra (requires sympy)
result = engine.solve("Solve x^2 - 4 = 0")
print(result.solutions) # ['x = -2', 'x = 2']
# Logic (requires z3-solver)
result = engine.solve('Check satisfiability of "p and q"')
print(result.solutions) # ['Satisfiable: p=True, q=True']建筑
LLM ─── MCP Protocol ──▶ mcp_server.py
│
engine.py (router → solver → result)
│
┌───────────────┼───────────────┐
▼ ▼ ▼
ArithmeticSolver SymPySolver Z3Solver
(zero deps) (pip: sympy) (pip: z3-solver)这 路由器 根据正则表达式模式对每个问题进行分类,并将其路由到最佳可用求解器。解算器加载缓慢——如果没有安装SymPy,代数问题会优雅地报告缺少的依赖关系。
安装附加
| 额外 | 它增加了什么 | 安装大小 |
|---|---|---|
| (无) | 仅算术 | ~1 MB |
[sympy] | +代数、微积分、简化 | ~50 MB |
[z3] | +命题逻辑,SAT | 约30 MB |
[full] | 所有内容 | ~80 MB |
[dev] | +pytest,ruff | ~ 85 MB |
pip install "math-logic-mcp[sympy]" # algebra + calculus
pip install "math-logic-mcp[z3]" # logic
pip install "math-logic-mcp[full]" # everything
pip install "math-logic-mcp[full,dev]" # everything + dev tools发展
git clone https://github.com/ismailkerimov/math-logic-mcp.git
cd math-logic-mcp
pip install -e ".[full,dev]"
pytest tests/ -v码头工人
docker build -t math-logic-mcp .
docker run -p 8080:8080 math-logic-mcp许可证
Apache 2.0——请参阅 许可证.
