Skip to main content
Glama
lollix91

dali2-logic-reasoner

by lollix91
README.md
# DALI2-Agent-Brain-MCP

MCP server that exposes the [DALI2-Agent-Brain](https://github.com/lollix91/DALI2-Agent-Brain)
logic reasoner as a set of tools for any MCP-compatible client (Unsloth Studio,
Claude Desktop, Cursor, etc.).

## What it does

The DALI2-Agent-Brain is a symbolic verification system: an LLM proposes an
answer, then a **Prolog meta-interpreter** formally verifies it. This MCP
server lets external chat clients call that verification pipeline as a tool.

```
Unsloth Studio chat  ──MCP──►  dali2-mcp-server  ──REST──►  DALI2-Agent-Brain
 (LLM generates                  (this repo)                 (Prolog verifier)
  a response)                                                  │
                                                               ▼
                                                    verified / unverified
                                                    + derivation trace
```

## Tools exposed

| Tool | Description |
|------|-------------|
| `solve_and_verify` | Submit a reasoning problem; get a formally verified answer + trace |
| `verify_reasoning` | Submit a claim + evidence for standalone logical verification |
| `check_status` | Check if the DALI2 brain is reachable and AI is configured |

## Prerequisites

1. **DALI2-Agent-Brain running** — start it from the main repo:
   ```bat
   cd DALI2-Agent-Brain
   start.bat sk-or-YOUR_OPENROUTER_KEY
   ```
   This brings up Redis + DALI2 + the GUI on `http://localhost:8090`.

2. **Python 3.10+** with the MCP dependencies:
   ```bash
   pip install -r requirements.txt
   ```
   Or with `uv`:
   ```bash
   uv sync
   ```

3. **Copy `.env.example` to `.env`** and adjust if needed:
   ```bash
   cp .env.example .env
   ```

## Configuration for Unsloth Studio

Use `mcp_config.json` (or `mcp_config_uv.json` if using `uv`):

```json
{
  "mcpServers": {
    "dali2-logic-reasoner": {
      "command": "python",
      "args": ["-m", "dali2_mcp.server"],
      "env": {
        "DALI2_URL": "http://localhost:8090"
      }
    }
  }
}
```

Paste this into the Unsloth Studio MCP tools configuration panel. Adjust
`DALI2_URL` if the DALI2-Agent-Brain runs on a different host/port.

### Using uv (recommended)

If you use [`uv`](https://docs.astral.sh/uv/) as your Python package manager,
use `mcp_config_uv.json` instead:

```json
{
  "mcpServers": {
    "dali2-logic-reasoner": {
      "command": "uv",
      "args": ["run", "dali2-mcp"],
      "env": {
        "DALI2_URL": "http://localhost:8090"
      }
    }
  }
}
```

## Running the server manually (for testing)

```bash
python -m dali2_mcp.server
```

The server communicates over stdio (standard MCP transport). It will wait for
JSON-RPC messages on stdin and respond on stdout.

## How it works

1. The MCP client (e.g. Unsloth Studio chat) calls a tool like
   `solve_and_verify` with a reasoning question.
2. This server forwards it as `POST /api/ask` to the DALI2-Agent-Brain GUI.
3. The DALI2 brain:
   - Classifies the task (syllogism, propositional, argument, math)
   - Asks the LLM to propose a structured answer
   - Runs the symbolic verifier (finite model checker / truth-table checker /
     arithmetic verifier)
   - Returns: answer, `verified` (true/false), and a derivation trace
4. This server formats the result and returns it to the chat client.

The key property: **a wrong-but-confident LLM answer is never accepted**,
because acceptance is gated by symbolic verification.

## Project structure

```
DALI2-Agent-Brain-MCP/
├── src/dali2_mcp/
│   ├── __init__.py
│   └── server.py          MCP server (stdio transport)
├── mcp_config.json        Config for Unsloth Studio (pip install)
├── mcp_config_uv.json     Config for Unsloth Studio (uv)
├── requirements.txt       Python dependencies
├── pyproject.toml         Package metadata + entry point
├── .env.example           Environment variable template
└── README.md
```

## Environment variables

| Variable | Default | Description |
|----------|---------|-------------|
| `DALI2_URL` | `http://localhost:8090` | URL of the DALI2-Agent-Brain GUI |