# rikarazome/prolog-reasoner [Health: Active]

**Category:** 👨‍💻 Code Execution  
**Repository:** https://github.com/rikarazome/prolog-reasoner  
**GitHub Stars:** 11  
**Views:** 3  
**Installs:** 0  
**Upvotes:** 0  
**Directory Page:** https://allmcps.com/mcp/rikarazome-prolog-reasoner

## Description
SWI-Prolog execution for LLMs with CLP(FD), negation-as-failure, and recursion. Benchmarked 90% vs 73% LLM-only accuracy on 30 logic problems.

## Tools
Capabilities this server exposes over MCP:

- **execute_prolog** — Execute Prolog code and return reasoning results.

Write Prolog facts and rules, then run a query against them.
Supports CLP(FD) constraints, negation-as-failure, and all
standard SWI-Prolog features.
- **list_rule_bases** — List all saved rule bases with description and tags.

Returns ``{"rule_bases": [{"name": str, "description": str,
"tags": list[str]}, ...]}`` sorted by name. Metadata is extracted
from the leading ``% description:`` / ``% tags:`` comments of each
rule base file (see §4.10).
- **get_rule_base** — Retrieve the Prolog source of a saved rule base.
- **save_rule_base** — Save a named rule base containing Prolog rules that can be reused
across ``execute_prolog`` calls.

Use this for stable, reusable knowledge (e.g. ``piece_moves`` for
chess piece movement rules). For one-time facts, include them
directly in ``prolog_code`` instead.
- **delete_rule_base** — Delete a saved rule base by name.

## Claude Desktop Quick Installation
Install path detected from listing signals. Uses `uvx` (confidence: high):

```json
"mcpServers": {
  "prolog-reasoner": {
    "command": "uvx",
    "args": ["prolog-reasoner"]
  }
}
```

## Documentation

## What rikarazome/prolog-reasoner MCP server does

The rikarazome/prolog-reasoner MCP server lets an MCP client submit SWI-Prolog facts and rules together with a query. The main execution tool returns the resulting solutions, whether execution succeeded, and metadata such as elapsed time, result count, truncation status, and the rule bases used. Prolog source remains visible as the intermediate representation, so an agent or developer can inspect and revise the logic before running it again.

The server also provides named rule bases for reusable knowledge. A rule base can hold stable domain rules, while each execution call supplies only the situation-specific facts. Rule bases can be listed, read, saved, overwritten, or deleted. Leading comments containing description and tag metadata are used when listing them.

## How it works

An `execute_prolog` call accepts `prolog_code` and `query`, with optional rule-base names, a maximum result count, and proof tracing. Selected rule bases are loaded before the supplied code. The query runs through SWI-Prolog, including support for constraint logic programming over finite domains, negation-as-failure, recursion, and other standard SWI-Prolog behavior.

Results are returned as JSON-like data with output and query fields. Successful calls include execution metadata. Failed calls include an error category and a natural-language explanation; documented categories include syntax, undefined predicate, unbound variable, type, domain, evaluation, permission, timeout, and trace-related errors. Proof tracing is optional and adds a structured proof tree, but it does not support CLP(FD), higher-order predicates, or `assert`/`retract`.

## Setup and configuration

Install the Python package with `pip install prolog-reasoner`, and make sure SWI-Prolog 9.0 or newer is installed and available on the system PATH. The MCP server itself does not require an OpenAI or Anthropic API key. Those providers apply to the separate library-mode natural-language-to-Prolog pipeline.

Claude Desktop can launch the server through `uvx` with the `prolog-reasoner` package, or through the installed `prolog-reasoner` executable. Docker is also documented as an option that bundles SWI-Prolog. The server requires Python 3.10 or newer when installed as the Python package.

Rule files are stored under `~/.prolog-reasoner/rules/` by default. The directory can be changed with `PROLOG_REASONER_RULES_DIR`; bundled rule content can be supplied through `BUNDLED_RULES_DIR`. Rule-base names may contain lowercase letters, numbers, underscores, and hyphens, and must be between one and 64 characters.

## Tools and capabilities

The rikarazome/prolog-reasoner MCP server exposes these tools:

- `execute_prolog`: Run supplied Prolog code and a query, optionally loading named rule bases and limiting returned solutions.
- `list_rule_bases`: List saved rule bases alphabetically with descriptions and tags.
- `get_rule_base`: Retrieve the raw source for a named rule base.
- `save_rule_base`: Validate and store a named rule base for later calls.
- `delete_rule_base`: Remove a saved rule base.

Saved content is parse-validated before writing, and oversized rule bases are rejected. The separate Python library also includes direct Prolog execution and an LLM-dependent translation pipeline, but those library features are not required for MCP use.

## Limitations and notes

The rikarazome/prolog-reasoner MCP server executes Prolog supplied by the connected client; it does not translate natural language or call an external LLM as part of the MCP server. The client must formulate the facts, rules, and query. Returned solutions are capped at 100 by default and may be truncated when more results exist. Proof tracing has feature restrictions and performance overhead. The server also depends on a local SWI-Prolog installation unless run through the documented Docker setup.

_Full upstream README: https://allmcps.com/mcp/rikarazome-prolog-reasoner/readme_

