Skip to main content

MCP server providing verified math & logic tools for small LLMs (Mistral, Llama, DeepSeek)

Project description

math-logic-mcp

MCP server that gives small LLMs verified symbolic-math & logic tools.

License

Small language models (Mistral, Llama, Phi, Gemma) struggle with multi-step math and formal logic. Instead of fine-tuning, give them tools. This project exposes a set of verified math and logic solvers via the Model Context Protocol (MCP), so any MCP-compatible LLM can call them as functions.

Features

Tool What it does Backend
verify_arithmetic Safe arithmetic evaluation Python stdlib (zero deps)
solve_equation Symbolic equation solving SymPy (optional)
simplify_expression Simplify / factor / expand SymPy (optional)
compute_derivative Differentiation SymPy (optional)
compute_integral Integration SymPy (optional)
check_logic SAT / tautology / truth tables Z3 (optional)

Every result includes proof steps and verification — the LLM gets a machine-checked answer, not a guess.

Quick Start

Install (minimal — arithmetic only)

pip install -e .

Install (full — all solvers)

pip install -e ".[full]"

Run the MCP server

# stdio transport (for Claude Desktop, Cursor, etc.)
math-logic-mcp

# HTTP/SSE transport (for remote clients)
math-logic-mcp --http

Configure in Claude Desktop

Add to ~/Library/Application Support/Claude/claude_desktop_config.json:

{
  "mcpServers": {
    "math-logic": {
      "command": "math-logic-mcp"
    }
  }
}

Configure in Cursor

Add to .cursor/mcp.json:

{
  "mcpServers": {
    "math-logic": {
      "command": "math-logic-mcp"
    }
  }
}

Use as a Python Library

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']

Architecture

LLM ─── MCP Protocol ──▶ mcp_server.py
                              │
                          engine.py  (router → solver → result)
                              │
              ┌───────────────┼───────────────┐
              ▼               ▼               ▼
     ArithmeticSolver   SymPySolver      Z3Solver
      (zero deps)       (pip: sympy)    (pip: z3-solver)

The router classifies each problem by regex patterns and routes to the best available solver. Solvers are loaded lazily — if SymPy isn't installed, algebra problems gracefully report the missing dependency.

Installation Extras

Extra What it adds Install size
(none) Arithmetic only ~1 MB
[sympy] + algebra, calculus, simplification ~50 MB
[z3] + propositional logic, SAT ~30 MB
[full] Everything ~80 MB
[dev] + pytest, ruff ~85 MB
pip install -e ".[sympy]"     # algebra + calculus
pip install -e ".[z3]"        # logic
pip install -e ".[full]"      # everything
pip install -e ".[full,dev]"  # everything + dev tools

Development

git clone https://github.com/user/math-logic-mcp.git
cd math-logic-mcp
pip install -e ".[full,dev]"
pytest tests/ -v

Docker

docker build -t math-logic-mcp .
docker run -p 8080:8080 math-logic-mcp

License

Apache 2.0 — see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

math_logic_mcp-0.2.0.tar.gz (22.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

math_logic_mcp-0.2.0-py3-none-any.whl (22.8 kB view details)

Uploaded Python 3

File details

Details for the file math_logic_mcp-0.2.0.tar.gz.

File metadata

  • Download URL: math_logic_mcp-0.2.0.tar.gz
  • Upload date:
  • Size: 22.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for math_logic_mcp-0.2.0.tar.gz
Algorithm Hash digest
SHA256 d3e1c2f6c69d9aa50f677dfbf07177c3b0283a5aeac913b6efc74e2844109af0
MD5 2ce913d14baed576378b402e4f6ded68
BLAKE2b-256 05087f31769f4ac81e741427fbb3dd4b8b51d50c306ab598d295c5b1dfc398ae

See more details on using hashes here.

File details

Details for the file math_logic_mcp-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: math_logic_mcp-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 22.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for math_logic_mcp-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aa0abcb072de7a45bfe5fc6c5109be8a25e006ac20d93531e1b25b87c0b47c83
MD5 9823e4d0b66af09e5f121d3d4c6c6f3b
BLAKE2b-256 50d51d5644b8f3a9b8fd5434a471d762bd37311f681da5a1c18d609f1286e9a2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page