Metadata-Version: 2.4
Name: math-logic-mcp
Version: 0.2.0
Summary: MCP server providing verified math & logic tools for small LLMs (Mistral, Llama, DeepSeek)
Author: Open Source Community
License-Expression: Apache-2.0
Project-URL: Homepage, https://github.com/ismailkerimov/math-logic-mcp
Project-URL: Repository, https://github.com/ismailkerimov/math-logic-mcp
Project-URL: Bug Tracker, https://github.com/ismailkerimov/math-logic-mcp/issues
Keywords: mcp,llm,reasoning,symbolic,math,logic,proof,tool-calling
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: sympy>=1.12
Requires-Dist: z3-solver>=4.12.2
Requires-Dist: pydantic>=2.0
Requires-Dist: mcp[cli]>=1.0.0
Provides-Extra: dev
Requires-Dist: pytest>=7.4; extra == "dev"
Requires-Dist: pytest-cov>=4.1; extra == "dev"
Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
Requires-Dist: black>=23.7; extra == "dev"
Requires-Dist: flake8>=6.0; extra == "dev"
Requires-Dist: mypy>=1.4; extra == "dev"
Requires-Dist: isort>=5.12; extra == "dev"
Provides-Extra: full
Requires-Dist: ortools>=9.7.2996; extra == "full"
Requires-Dist: litellm>=1.26.0; extra == "full"
Requires-Dist: redis>=5.0.0; extra == "full"
Requires-Dist: lark>=1.1; extra == "full"
Dynamic: license-file

# math-logic-mcp

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

[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](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)](https://modelcontextprotocol.io), 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)

```bash
pip install -e .
```

### Install (full — all solvers)

```bash
pip install -e ".[full]"
```

### Run the MCP server

```bash
# 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`:

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

### Configure in Cursor

Add to `.cursor/mcp.json`:

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

## Use as a Python Library

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

## 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 |

```bash
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

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

## Docker

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

## License

Apache 2.0 — see [LICENSE](LICENSE).
