MCP Logic

MCP Logic

Enables first-order logic reasoning including theorem proving, model finding, counterexample detection, and category theory diagram verification using pure TypeScript with no external dependencies.

Category
访问服务器

README

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/

Features

  • Theorem Proving - Prove logical statements using resolution
  • Model Finding - Find finite models satisfying premises
  • Counterexample Detection - Find models showing conclusions don't follow
  • Syntax Validation - Pre-validate formulas with detailed error messages
  • Categorical Reasoning - Built-in support for category theory proofs
  • Session-Based Reasoning - Incremental knowledge base construction
  • Verbosity Control - Token-efficient responses for LLM chains
  • Self-Contained - Pure npm dependencies, no external binaries

Quick Start

Installation

git clone <repository>
cd nodejs
npm install
npm run build

Running the Server

npm start

Or for development with auto-reload:

npm run dev

Claude Desktop / MCP Client Configuration

Add to your MCP configuration:

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

Available Tools

Core Reasoning Tools

Tool Description
prove Prove statements using resolution
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

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

Verbosity Control

All tools support a verbosity parameter to control response size:

Level Description Use Case
minimal Just success/result Token-efficient LLM chains
standard + message, bindings Default balance
detailed + Prolog program, statistics Debugging
{
  "name": "prove",
  "arguments": {
    "premises": ["man(socrates)", "all x (man(x) -> mortal(x))"],
    "conclusion": "mortal(socrates)",
    "verbosity": "minimal"
  }
}

Minimal response: { "success": true, "result": "proved" }

Detailed response: Includes prologProgram, statistics.timeMs, etc.

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 (¬)

Predicates and Terms

  • Predicates: man(x), loves(x, y), greater(x, y)
  • Constants: socrates, a, b
  • Variables: x, y, z (lowercase, typically single letters)
  • Functions: f(x), successor(n)
  • Equality: x = y

Examples

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

# There exists someone who loves everyone
exists x all y loves(x, y)

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

Tool Usage Examples

1. Prove a Theorem

{
  "name": "prove",
  "arguments": {
    "premises": [
      "all x (man(x) -> mortal(x))",
      "man(socrates)"
    ],
    "conclusion": "mortal(socrates)"
  }
}

Expected Result: Theorem proved ✓

2. Find a Counterexample

{
  "name": "find-counterexample",
  "arguments": {
    "premises": ["P(a)"],
    "conclusion": "P(b)"
  }
}

Expected Result: Model found where P(a) is true but P(b) is false.

3. Validate Syntax

{
  "name": "check-well-formed",
  "arguments": {
    "statements": [
      "all x (P(x) -> Q(x))",
      "P(a) &"
    ]
  }
}

Expected Result: First formula valid, second has syntax error.

4. Session-Based Reasoning

Build up a knowledge base incrementally:

// 1. Create a session
{ "name": "create-session", "arguments": { "ttl_minutes": 30 } }
// → { "session_id": "abc-123...", "expires_at": "2024-..." }

// 2. Assert premises
{ "name": "assert-premise", "arguments": { 
    "session_id": "abc-123...", 
    "formula": "all x (man(x) -> mortal(x))" 
}}
{ "name": "assert-premise", "arguments": { 
    "session_id": "abc-123...", 
    "formula": "man(socrates)" 
}}

// 3. Query the KB
{ "name": "query-session", "arguments": { 
    "session_id": "abc-123...", 
    "goal": "mortal(socrates)" 
}}
// → { "success": true, "result": "proved" }

// 4. Cleanup
{ "name": "delete-session", "arguments": { "session_id": "abc-123..." } }

5. Verify Categorical Diagram

{
  "name": "verify-commutativity",
  "arguments": {
    "path_a": ["f", "g"],
    "path_b": ["h"],
    "object_start": "A",
    "object_end": "C",
    "with_category_axioms": true
  }
}

Expected Result: FOL premises and conclusion for proving g ∘ f = h.

6. Get Category Theory Axioms

{
  "name": "get-category-axioms",
  "arguments": {
    "concept": "category"
  }
}

Expected Result: 6 axioms defining a category (identity, composition, associativity).

Project Structure

nodejs/
├── package.json           # Project configuration
├── tsconfig.json          # TypeScript configuration
├── jest.config.js         # Test configuration
├── src/
│   ├── index.ts           # CLI entry point
│   ├── server.ts          # MCP server (13 tools)
│   ├── parser.ts          # FOL tokenizer & parser
│   ├── translator.ts      # FOL ↔ Prolog conversion
│   ├── logicEngine.ts     # Tau-Prolog wrapper
│   ├── syntaxValidator.ts # Syntax validation
│   ├── categoricalHelpers.ts # Category theory
│   ├── modelFinder.ts     # Finite model enumeration
│   ├── sessionManager.ts  # Session lifecycle management
│   └── types/
│       ├── index.ts       # Shared types & verbosity
│       ├── errors.ts      # Structured error system
│       └── tau-prolog.d.ts
├── tests/
│   ├── basic.test.ts
│   ├── parser.test.ts
│   ├── prover.test.ts
│   ├── errors.test.ts     # Error system tests
│   ├── session.test.ts    # Session management tests
│   └── verbosity.test.ts  # Verbosity control tests
└── dist/                  # Compiled output (after build)

Development

Run Tests

npm test

Build

npm run build

Type Checking

npx tsc --noEmit

Technical Details

Logic Engine

The server uses Tau-Prolog as its core inference engine. Tau-Prolog is an ISO-compliant Prolog interpreter written entirely in JavaScript, enabling:

  • Resolution-based theorem proving
  • Unification and backtracking
  • No external binary dependencies

Model Finder

For counterexample detection and model finding, the server includes a custom finite model enumerator that:

  • Searches domains of increasing size (2-10 elements)
  • Enumerates all possible interpretations
  • Checks formula satisfaction
  • Returns the first satisfying model

Session Manager

Sessions enable incremental knowledge base construction:

  • TTL-based expiration - Sessions auto-expire (default: 30 minutes)
  • Garbage collection - Expired sessions cleaned up every minute
  • Memory protection - Maximum 1000 concurrent sessions
  • CRUD operations - Assert, retract, list, clear premises

Structured Errors

All errors include machine-readable information:

interface LogicError {
  code: LogicErrorCode;    // 'PARSE_ERROR' | 'INFERENCE_LIMIT' | ...
  message: string;
  span?: { start, end, line, col };
  suggestion?: string;     // How to fix
  context?: string;        // The problematic input
}

Syntax Translation

Since Tau-Prolog uses Prolog syntax, the server includes a translator that converts between:

  • Input: Prover9-style FOL (all x (man(x) -> mortal(x)))
  • Internal: Prolog rules (mortal(X) :- man(X).)

This translation is transparent to users.

Limitations

  1. Inference Depth: Complex proofs may exceed inference limits
  2. Model Size: Model finder is limited to small finite domains (≤10 elements)
  3. Function Symbols: Limited support for complex function terms
  4. Higher-Order Logic: Only first-order logic is supported

Troubleshooting

"No proof found" for valid theorem

  • Try simpler premises
  • Check for syntax errors with check-well-formed
  • Increase inference_limit for complex proofs (default: 1000)

Model finder returns "no_model"

  • Increase max_domain_size parameter (default: 10)
  • Simplify the formula
  • Check for contradictory premises

Syntax validation warnings

  • Use lowercase for predicates/functions
  • Add spaces around operators for readability
  • Ensure balanced parentheses

Session errors

  • Check session hasn't expired (default TTL: 30 minutes)
  • Verify session_id is correct
  • Use list-premises to inspect session state

API Reference

prove

interface ProveArgs {
  premises: string[];       // List of FOL premises
  conclusion: string;       // Goal to prove
  inference_limit?: number; // Max inference steps (default: 1000)
  verbosity?: 'minimal' | 'standard' | 'detailed';
}

interface ProveResult {
  success: boolean;
  result: 'proved' | 'failed' | 'timeout' | 'error';
  message?: string;         // Human-readable message
  proof?: string[];
  bindings?: Record<string, string>[];
  error?: string;
  prologProgram?: string;   // (detailed only)
  statistics?: { timeMs: number; inferences?: number };  // (detailed only)
}

check-well-formed

interface CheckArgs {
  statements: string[];  // Formulas to validate
  verbosity?: 'minimal' | 'standard' | 'detailed';
}

interface ValidationResult {
  valid: boolean;
  formulaResults: Array<{
    formula: string;
    valid: boolean;
    errors: string[];
    warnings: string[];
  }>;
}

find-model

interface FindModelArgs {
  premises: string[];         // Formulas to satisfy
  domain_size?: number;       // Specific size or search 2-max
  max_domain_size?: number;   // Maximum domain size to try (default: 10)
  verbosity?: 'minimal' | 'standard' | 'detailed';
}

interface ModelResult {
  success: boolean;
  result: 'model_found' | 'no_model' | 'timeout' | 'error';
  model?: {
    domainSize: number;
    predicates: Record<string, string[]>;
    constants: Record<string, number>;
  };
  interpretation?: string;
  statistics?: { domainSize: number; searchedSizes: number[]; timeMs: number };
}

find-counterexample

interface CounterexampleArgs {
  premises: string[];
  conclusion: string;
  domain_size?: number;
  max_domain_size?: number;  // Maximum domain size to try (default: 10)
  verbosity?: 'minimal' | 'standard' | 'detailed';
}
// Returns ModelResult with counterexample interpretation

Session Tools

// create-session
interface CreateSessionArgs {
  ttl_minutes?: number;  // Session lifetime (default: 30, max: 1440)
}
interface CreateSessionResult {
  session_id: string;
  created_at: string;
  expires_at: string;
  ttl_minutes: number;
  active_sessions: number;
}

// assert-premise
interface AssertPremiseArgs {
  session_id: string;
  formula: string;
}

// query-session
interface QuerySessionArgs {
  session_id: string;
  goal: string;
  inference_limit?: number;
  verbosity?: 'minimal' | 'standard' | 'detailed';
}

// retract-premise
interface RetractPremiseArgs {
  session_id: string;
  formula: string;  // Exact formula to remove
}

// list-premises
interface ListPremisesArgs {
  session_id: string;
}
interface ListPremisesResult {
  session_id: string;
  premise_count: number;
  premises: string[];
}

// clear-session
interface ClearSessionArgs {
  session_id: string;
}

// delete-session
interface DeleteSessionArgs {
  session_id: string;
}

verify-commutativity

interface CommutativityArgs {
  path_a: string[];          // Morphisms in first path
  path_b: string[];          // Morphisms in second path
  object_start: string;      // Starting object
  object_end: string;        // Ending object
  with_category_axioms?: boolean;  // Include category axioms (default: true)
  verbosity?: 'minimal' | 'standard' | 'detailed';
}

interface CommutativityResult {
  premises: string[];
  conclusion: string;
  note: string;
}

get-category-axioms

interface AxiomsArgs {
  concept: 'category' | 'functor' | 'natural-transformation' | 'monoid' | 'group';
  functor_name?: string;     // For functor axioms (default: 'F')
  verbosity?: 'minimal' | 'standard' | 'detailed';
}

interface AxiomsResult {
  concept: string;
  axioms: string[];
}

License

MIT

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Run tests: npm test
  4. Submit a pull request

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选