Skip to main content
Glama

MCP Logic

A self-contained MCP server for first-order logic reasoning, implemented in TypeScript with no external binary dependencies.

Original: https://github.com/angrysky56/mcp-logic/


Feature Status

✅ = Implemented | 🔲 = Planned | 🔬 = Research/Vision

Core Reasoning

  • Theorem Proving — Resolution-based proving via Tau-Prolog

  • Model Finding — Finite model enumeration (domain ≤25 with SAT)

  • Counterexample Detection — Find models refuting conclusions

  • Syntax Validation — Pre-validate formulas with detailed errors

  • CNF Clausification — Transform FOL to Conjunctive Normal Form

  • Tseitin Transformation — Linear-size CNF conversion for SAT (avoids exponential blowup)

  • DIMACS Export — Export CNF for external SAT solvers

  • Symmetry Breaking — Lex-leader for model search (reduces search space exponentially)

  • SAT-Backed Model Finding — Scale to domain 25+ with automatic SAT threshold

  • Isomorphism Filtering — Skip equivalent models (deferred until "findAllModels" use case)

  • Proof Traces — Step-by-step derivation output (via include_trace)

Engine Federation

  • Multi-Engine Architecture — Automatic engine selection

  • Prolog Engine (Tau-Prolog) — Horn clauses, Datalog, equality

  • SAT Engine (MiniSat) — General FOL, non-Horn formulas

  • SMT Engine (Z3) — High-performance SMT solver with arithmetic & quantifiers

  • ASP Engine (Clingo) — Answer Set Programming (Constraints & Models)

  • Engine Parameter — Explicit engine selection via engine param

  • Iterative Deepening — Progressive inference limit strategy for complex proofs

  • Resource Management — Automatic cleanup of WASM resources (Z3 contexts)

  • Prover9 WASM — Optional high-power ATP (deferred until SAT+iterative proves insufficient)

  • Demodulation — Equational term rewriting (deferred until equality workloads show perf issues)

Logic Features

  • Arithmetic Support — Built-in: lt, gt, plus, minus, times, divides

  • Equality Reasoning — Reflexivity, symmetry, transitivity, congruence

  • Rewriting System — Knuth-Bendix style term rewriting for efficient equality handling (Prolog)

  • Extended Axiom Library — Ring, field, lattice, equivalence relation axioms

  • Function Interpretation — Full function support in model finding

  • Typed/Sorted FOL — Domain-constraining type annotations (research)

  • Modal Logic — Necessity, possibility operators (research)

  • Probabilistic Logic — Weighted facts, Bayesian inference (research)

MCP Protocol

  • Session-Based Reasoning — Incremental knowledge base construction with resource cleanup

  • Axiom Resources — Browsable libraries (category, Peano, ZFC, ring, lattice, etc.)

  • Reasoning Prompts — Templates for proof patterns

  • Verbosity Control — minimal/standard/detailed responses

  • Structured Errors — Machine-readable error codes and suggestions

  • Streaming Progress — Real-time progress notifications (via MCP notifications)

  • High-Power Mode — Extended limits with warning (via highPower option)

Advanced Engines

  • SMT (Z3 WASM) — Theory reasoning (arithmetic, arrays), Equality, Quantifiers.

  • ASP (Clingo) — Non-monotonic reasoning, defaults, preferences.

  • Neural-Guided — LLM-suggested proof paths with validation

  • Higher-Order Logic — Quantify over predicates (research)

Testing & Benchmarks

  • Unit Tests — 265+ tests passing, 80%+ coverage

  • Pelletier Problems — P1-P10 benchmark suite (extensible to P1-P75)

  • Symmetry Benchmarks — Bell number validation tests

  • SAT Model Tests — Group theory and algebraic structure verification

  • Resilience Tests — Resource leak detection and complexity limit verification

  • TPTP Library Subset — Standard ATP benchmarks


Related MCP server: Congo River Compositional Intelligence

Quick Start

Installation

git clone <repository>
cd mcplogic
pnpm install
pnpm run build

Running the Server

pnpm start

Verification

Run the comprehensive health check to verify build, tests, and engine availability:

pnpm run verify

Claude Desktop / MCP Client Configuration

Add to your MCP configuration:

{
  "mcpServers": {
    "mcp-logic": {
      "command": "node",
      "args": ["/path/to/mcplogic/dist/index.js"]
    }
  }
}

CLI Tools

The package includes a CLI for offline usage and verification:

# Check engine status
mcplogic check

# Prove a theorem from a file
mcplogic prove problem.p

# Find a model
mcplogic model theory.p

# Interactive REPL
mcplogic repl

Available Tools

Core Reasoning Tools

Tool

Description

prove

Prove statements using resolution with engine selection

check-well-formed

Validate formula syntax with detailed errors

find-model

Find finite models satisfying premises

find-counterexample

Find counterexamples showing statements don't follow

verify-commutativity

Generate FOL for categorical diagram commutativity

get-category-axioms

Get axioms for category/functor/monoid/group

translate-text

Translate natural language to FOL (requires LLM)

Session Management Tools

Tool

Description

create-session

Create a new reasoning session with TTL

assert-premise

Add a formula to a session's knowledge base

query-session

Query the accumulated KB with a goal

retract-premise

Remove a specific premise from the KB

list-premises

List all premises in a session

clear-session

Clear all premises (keeps session alive)

delete-session

Delete a session entirely


Engine Selection

The prove tool supports automatic or explicit engine selection:

{
  "name": "prove",
  "arguments": {
    "premises": ["foo | bar", "-foo"],
    "conclusion": "bar",
    "engine": "auto",
    "include_trace": true
  }
}

The include_trace option (boolean) enables step-by-step derivation output in the response, useful for debugging or understanding the proof path.

Engine

Best For

Capabilities

prolog

Horn clauses, Datalog

Equality, arithmetic, efficient unification

sat

Propositional, Finite Domain

Boolean logic, CNF solving

z3

General FOL, SMT

Arithmetic, Quantifiers, Equality

clingo

Answer Set Programming

Constraints (Experimental)

auto

Default — selects based on formula

Analyzes clause structure & features

Engine Capabilities

Engine

Strength

Arithmetic

Quantifiers

Equality

Model Size

Z3

High (SMT)

✅

✅

✅

Large

Clingo

High (ASP)

✅

Limited

✅

Large

Prolog

Medium (Resolution)

✅

Limited (Horn)

✅

Small/Medium

SAT

Low (Propositional)

❌

❌

❌

Small


Formula Syntax

This server uses first-order logic (FOL) syntax compatible with Prover9:

Quantifiers

  • all x (...) — Universal quantification (∀x)

  • exists x (...) — Existential quantification (∃x)

Connectives

  • -> — Implication (→)

  • <-> — Biconditional (↔)

  • & — Conjunction (∧)

  • | — Disjunction (∨)

  • - — Negation (¬)

Examples

# All men are mortal, Socrates is a man
all x (man(x) -> mortal(x))
man(socrates)

# Transitivity of greater-than
all x all y all z ((greater(x, y) & greater(y, z)) -> greater(x, z))

MCP Resources

Resource URI

Description

logic://axioms/category

Category theory axioms

logic://axioms/monoid

Monoid structure

logic://axioms/group

Group axioms

logic://axioms/ring

Ring structure

logic://axioms/lattice

Lattice structure

logic://axioms/equivalence

Equivalence relations

logic://axioms/peano

Peano arithmetic

logic://axioms/set-zfc

ZFC set theory basics

logic://axioms/propositional

Propositional tautologies

logic://templates/syllogism

Aristotelian syllogism patterns

logic://engines

Available reasoning engines (JSON)


Verbosity Control

All tools support a verbosity parameter:

Level

Description

Use Case

minimal

Just success/result

Token-efficient LLM chains

standard

+ message, bindings, engineUsed

Default balance

detailed

+ Prolog program, statistics

Debugging


Limitations (Current)

  1. Model Size — Finder limited to domains ≤25 elements (using SAT)

  2. Inference Depth — Complex proofs may exceed default limit (increase via inference_limit or use iterative strategy)

  3. Higher-Order — Only first-order logic supported

Future improvements may address these limitations as real-world usage dictates.


Development

pnpm run build     # Compile TypeScript
pnpm test          # Run test suite
pnpm run dev       # Development mode with auto-reload

License

MIT


Future Directions

Potential enhancements will be driven by real-world usage:

  • Isomorphism Filtering — Skip equivalent models in exhaustive model enumeration

  • Proof Traces — Step-by-step derivation output for educational/debugging use cases

  • Demodulation — Equational term rewriting optimization for equality-heavy workloads

  • Streaming Progress — Real-time progress notifications for long-running operations

  • Extended Benchmarks — TPTP library subset and group theory problem suites

  • Advanced Engines — SMT (Z3), ASP (Clingo)

  • Evolution Engine — Genetic algorithm for evolving efficient proof strategies

  • Neural-Guided — LLM-suggested proof paths with validation

Troubleshooting

WASM Engines (Z3 / Clingo)

If you encounter errors related to z3-solver or clingo-wasm:

  1. Ensure your environment supports WebAssembly.

  2. In browser environments, ensure the .wasm files are served correctly. The check command can verify basic functionality in Node.js.

  3. If you see OOM or memory errors, try running with the default engine (Prolog) or increasing the timeout/inference limits.

build:browser Failures

Ensure you have run pnpm install to get the latest type definitions. The browser build relies on specific overrides for WASM modules that are handled in src/engines/*/index.ts.

Available Tools

13 tools
assert-premiseA

Add a formula to a session's knowledge base.

When to use: Building up premises incrementally in a session.

Example: session_id: "abc-123..." formula: "all x (man(x) -> mortal(x))" → Adds the formula to the session KB

Inputs: session_id (required), formula (required), verbosity.

check-well-formedA

Check if logical statements are well-formed with detailed syntax validation.

When to use: Before calling prove/find-model to catch syntax errors early. When NOT to use: You already know the formula syntax is correct.

Example: statements: ["all x (P(x) -> Q(x))"] → Returns: { valid: true, statements: [...] }

Common syntax issues:

  • Use lowercase for predicates/functions: man(x), not Man(x)

  • Quantifiers: "all x (...)" or "exists x (...)"

  • Operators: -> (implies), & (and), | (or), - (not), <-> (iff)

Inputs: statements (required), verbosity.

clear-sessionA

Clear all premises from a session (keeps session alive).

When to use: Start fresh within the same session.

Example: session_id: "abc-123..." → Clears all premises, session remains valid

Inputs: session_id (required), verbosity.

create-sessionA

Create a new reasoning session for incremental knowledge base construction.

When to use: You want to build up premises incrementally and query multiple times. When NOT to use: Single query with all premises known upfront (use prove directly).

Example: ttl_minutes: 30 → Returns: { session_id: "uuid...", expires_at: ... }

Notes:

  • Sessions auto-expire after TTL (default: 30 minutes)

  • Maximum 1000 concurrent sessions

  • Session ID must be passed to all session operations

Inputs: ttl_minutes, verbosity.

delete-sessionA

Delete a session entirely.

When to use: Done with a session, want to free resources.

Example: session_id: "abc-123..." → Session is deleted and ID becomes invalid

Inputs: session_id (required), verbosity.

find-counterexampleA

Find a counterexample showing the conclusion doesn't follow from premises.

When to use: You suspect a conclusion doesn't logically follow and want proof. When NOT to use: You want to prove the conclusion (use prove instead).

Example: premises: ["P(a)"] conclusion: "P(b)" → Returns counterexample where P(a)=true but P(b)=false

How it works: Searches for a model satisfying premises ∧ ¬conclusion. If found, proves the conclusion doesn't logically follow.

Inputs: premises (required), conclusion (required), domain_size, max_domain_size, +1 more.

find-modelA

Find a finite model satisfying the given premises.

When to use: You want to show premises are satisfiable (have at least one model). When NOT to use: You want to prove a conclusion follows (use prove instead).

Example: premises: ["exists x P(x)", "all x (P(x) -> Q(x))"] → Returns: { success: true, model: { domain: [0], predicates: {...} } }

Performance notes:

  • Searches domains size 2 through max_domain_size (default: 10)

  • Larger domains take exponentially longer

  • Use domain_size to search a specific size only

Inputs: premises (required), domain_size, max_domain_size, verbosity.

get-category-axiomsA

Get FOL axioms for category theory concepts.

Available concepts:

  • category: Composition, identity, associativity axioms

  • functor: Preserves composition and identity

  • natural-transformation: Naturality condition

  • monoid: Binary operation with identity and associativity

  • group: Monoid with inverses

Example: concept: "monoid" → Returns axioms for monoid structure

Inputs: concept (required), functor_name, verbosity.

list-premisesA

List all premises in a session's knowledge base.

When to use: Review what has been asserted so far.

Example: session_id: "abc-123..." → Returns: { premises: ["all x (man(x) -> mortal(x))", "man(socrates)"] }

Inputs: session_id (required), verbosity.

proveA

Prove a logical statement using resolution.

When to use: You have premises and want to verify a conclusion follows logically. When NOT to use: You want to find counterexamples (use find-counterexample instead).

Example: premises: ["all x (man(x) -> mortal(x))", "man(socrates)"] conclusion: "mortal(socrates)" → Returns: { success: true, result: "proved" }

Common issues:

  • "No proof found" often means inference limit reached, not that the theorem is false

  • Try increasing inference_limit for complex proofs

Inputs: premises (required), conclusion (required), inference_limit, enable_arithmetic, +3 more.

query-sessionA

Query the accumulated knowledge base in a session.

When to use: After asserting premises, query for a conclusion.

Example: session_id: "abc-123..." goal: "mortal(socrates)" → Attempts to prove the goal from accumulated premises

Inputs: session_id (required), goal (required), inference_limit, verbosity.

retract-premiseA

Remove a specific premise from a session's knowledge base.

When to use: You need to undo an assertion or explore alternative premises.

Example: session_id: "abc-123..." formula: "man(plato)" → Removes the exact formula if found

Inputs: session_id (required), formula (required), verbosity.

verify-commutativityA

Verify that a categorical diagram commutes by generating FOL premises and conclusion.

When to use: You have a categorical diagram and want to verify path equality. When NOT to use: For non-categorical reasoning (use prove directly).

Example: path_a: ["f", "g"], path_b: ["h"] object_start: "A", object_end: "C" → Generates premises/conclusion for proving compose(f,g) = h

Output: Returns premises and conclusion to pass to the prove tool.

Inputs: path_a (required), path_b (required), object_start (required), object_end (required), +2 more.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A4.3/5.0

    Scored across 13 tools

    Disambiguation5/5

    Each tool has a clearly distinct purpose with minimal overlap. For example, prove and find-counterexample are complementary for logical verification, while session management tools like create-session and delete-session handle specific lifecycle stages. The descriptions explicitly state when to use and when not to use each tool, preventing confusion.

    Naming Consistency4/5

    Most tools follow a consistent verb-noun pattern with hyphens (e.g., assert-premise, clear-session, find-model). However, get-category-axioms and verify-commutativity slightly deviate by using more descriptive nouns, but they remain readable and fit the overall style. The naming is predictable and aids in understanding tool functions.

    Tool Count5/5

    With 13 tools, the set is well-scoped for a logic reasoning server, covering core operations like session management, premise handling, proof verification, and model finding. Each tool serves a specific role without redundancy, such as list-premises for review and retract-premise for corrections, making the count appropriate for the domain.

    Completeness5/5

    The tool set provides comprehensive coverage for logical reasoning workflows, including session lifecycle (create, clear, delete), premise management (assert, list, retract), verification (prove, find-counterexample, query-session), and specialized tasks like model finding and category theory support. No obvious gaps exist; agents can perform end-to-end reasoning tasks effectively.

    Maintenance

    ActivityInactive
    ResponsivenessOutdated data

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      Provides symbolic reasoning capabilities by converting natural language logical problems into Answer Set Programming (ASP) format and solving them using the Clingo solver. Enables users to perform formal logical reasoning, verify logical arguments, and get step-by-step explanations for complex logical problems.
      5
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables formal logical reasoning, mathematical problem-solving, and proof construction across 11 logic systems including propositional, predicate, modal, fuzzy, and probabilistic logic. Integrates external solvers (Z3, ProbLog, Clingo) for advanced reasoning, with support for proof storage, argument scoring, and cross-system translation.
      1
      MIT