MCP cover image
See in Github
2025-04-01

Ein MCP -Server für den Z3 -Theorem -Prover

1

Github Watches

0

Github Forks

1

Github Stars

Z3 Theorem Prover with Functional Programming

A Python implementation of abstactions over the Z3 Theorem Prover capabilities using functional programming principles, exposed through a Model Context Protocol (MCP) server.

Overview

This project demonstrates how to use the Z3 Theorem Prover with a functional programming approach to solve complex constraint satisfaction problems and analyze relationships between entities. It leverages the returns library for functional programming abstractions and exposes its capabilities through an MCP server.

Features

  • Constraint Satisfaction Problems: Solve complex problems with variables and constraints
  • Relationship Analysis: Analyze and infer relationships between entities
  • Functional Programming: Uses pure functions, immutable data structures, and monadic error handling
  • MCP Server: Exposes Z3 capabilities through a standardized interface

Project Structure

z3_mcp/
├── core/                  # Core implementation
│   ├── solver.py          # Constraint satisfaction problem solving
│   └── relationships.py   # Relationship analysis
├── models/                # Data models
│   ├── constraints.py     # Models for constraint problems
│   └── relationships.py   # Models for relationship analysis
├── server/                # MCP server
│   └── main.py            # Server implementation
└── examples/              # Example usage
    └── main.py            # Demonstration of capabilities

Technical Stack

  • Z3 Solver: Microsoft's theorem prover for constraint solving
  • Returns: Functional programming library for monadic operations and error handling
  • Pydantic: Data validation and serialization
  • FastMCP: Implementation of the Model Context Protocol

Installation

This project uses uv for dependency management.

# Clone the repository
git clone https://github.com/javergar/z3_mcp.git
cd z3_mcp

# Install dependencies
uv pip install -e .

# Install development dependencies (optional)
uv pip install -e ".[dev]"

Usage

Running Examples

The project includes several examples that demonstrate the capabilities of the Z3 solver:

# Run the examples
python -m z3_poc.examples.main

Examples include:

  • N-Queens Problem
  • Family Relationship Inference
  • Temporal Reasoning with Causal Relationships
  • Cryptarithmetic Puzzle (SEND + MORE = MONEY)

Running the MCP Server

Start the MCP server to expose Z3 capabilities through the Model Context Protocol:

# Run the server
python -m z3_poc.server.main

Setting up the MCP Server with Claude/Cline

To use the Z3 solver MCP server with Claude through the Cline extension in VSCode, you need to configure the settings.json file:

  1. Configuration: Add the following to the mcpServers object in the settings file:
"z3-solver": {
  "command": "uv",
  "args": [
    "--directory",
    "/path/to/your/z3_poc",
    "run",
    "z3_poc/server/main.py"
  ],
  "disabled": false,
  "autoApprove": [
    "simple_constraint_solver", 
    "simple_relationship_analyzer", 
    "solve_constraint_problem", 
    "analyze_relationships"
  ]
}
  1. Configuration Options:

    • command: The command to run (using uv for Python environment management)
    • args: Command arguments, including the path to your project and the server script
    • disabled: Set to false to enable the server
    • autoApprove: List of tools that can be used without explicit approval
  2. Restart: After updating the settings, restart VSCode or the Claude Desktop app for the changes to take effect.

Once configured, Claude will have access to the Z3 solver capabilities through the MCP server.

MCP Tools

The server provides the following tools:

solve_constraint_problem

Solves a constraint satisfaction problem with a full Problem model.

# Example input
{
  "problem": {
    "variables": [
      {"name": "x", "type": "integer"},
      {"name": "y", "type": "integer"}
    ],
    "constraints": [
      {"expression": "x + y == 10"},
      {"expression": "x >= 0"},
      {"expression": "y >= 0"}
    ],
    "description": "Find non-negative values for x and y that sum to 10"
  }
}

analyze_relationships

Analyzes relationships between entities with a full RelationshipQuery model.

# Example input
{
  "query": {
    "relationships": [
      {"person1": "Alice", "person2": "Bob", "relation": "sibling"},
      {"person1": "Bob", "person2": "Charlie", "relation": "sibling"}
    ],
    "query": "sibling(Alice, Charlie)"
  }
}

simple_constraint_solver

A simpler interface for solving constraint problems without requiring the full Problem model.

# Example input
{
  "variables": [
    {"name": "x", "type": "integer"},
    {"name": "y", "type": "integer"}
  ],
  "constraints": [
    "x + y == 10",
    "x <= 5",
    "y <= 5"
  ],
  "description": "Find values for x and y"
}

simple_relationship_analyzer

A simpler interface for analyzing relationships without requiring the full RelationshipQuery model.

# Example input
{
  "relationships": [
    {"person1": "Bob", "person2": "Hanna", "relation": "sibling"},
    {"person1": "Bob", "person2": "Claudia", "relation": "sibling"}
  ],
  "query": "sibling(Hanna, Claudia)"
}

Functional Programming Approach

This project demonstrates several functional programming principles:

  1. Immutable Data Structures: Using Pydantic models for immutable data representation
  2. Result Type: Using returns.result.Result for error handling without exceptions
  3. Maybe Type: Using returns.maybe.Maybe for handling nullable values
  4. Do Notation: Using generator expressions with Result.do() for sequential operations
  5. Pattern Matching: Using Python's match-case for handling different result types

Example of do notation in analyze_relationships:

expr = (
    RelationshipResult(...)
    for entities in create_entities(query.relationships)
    for relations in create_relations(query.relationships)
    for _ in add_relationship_assertions(solver, query.relationships, entities, relations)
    for query_expr in parse_query(query.query, entities, relations)
    for (result, explanation, is_satisfiable) in evaluate_query(solver, query_expr)
)

return Result.do(expr)

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

相关推荐

  • https://suefel.com
  • Latest advice and best practices for custom GPT development.

  • NiKole Maxwell
  • I craft unique cereal names, stories, and ridiculously cute Cereal Baby images.

  • Yusuf Emre Yeşilyurt
  • I find academic articles and books for research and literature reviews.

  • https://maiplestudio.com
  • Find Exhibitors, Speakers and more

  • Carlos Ferrin
  • Encuentra películas y series en plataformas de streaming.

  • Joshua Armstrong
  • Confidential guide on numerology and astrology, based of GG33 Public information

  • Contraband Interactive
  • Emulating Dr. Jordan B. Peterson's style in providing life advice and insights.

  • Elijah Ng Shi Yi
  • Advanced software engineer GPT that excels through nailing the basics.

  • rustassistant.com
  • Your go-to expert in the Rust ecosystem, specializing in precise code interpretation, up-to-date crate version checking, and in-depth source code analysis. I offer accurate, context-aware insights for all your Rust programming questions.

  • Emmet Halm
  • Converts Figma frames into front-end code for various mobile frameworks.

  • lumpenspace
  • Take an adjectivised noun, and create images making it progressively more adjective!

  • apappascs
  • Entdecken Sie die umfassendste und aktuellste Sammlung von MCP-Servern auf dem Markt. Dieses Repository dient als zentraler Hub und bietet einen umfangreichen Katalog von Open-Source- und Proprietary MCP-Servern mit Funktionen, Dokumentationslinks und Mitwirkenden.

  • Mintplex-Labs
  • Die All-in-One-Desktop & Docker-AI-Anwendung mit integriertem Lappen, AI-Agenten, No-Code-Agent Builder, MCP-Kompatibilität und vielem mehr.

  • modelcontextprotocol
  • Modellkontext -Protokollserver

  • n8n-io
  • Fair-Code-Workflow-Automatisierungsplattform mit nativen KI-Funktionen. Kombinieren Sie visuelles Gebäude mit benutzerdefiniertem Code, SelbstHost oder Cloud, 400+ Integrationen.

  • WangRongsheng
  • 🧑‍🚀 全世界最好的 llm 资料总结(数据处理、模型训练、模型部署、 O1 模型、 MCP 、小语言模型、视觉语言模型) | Zusammenfassung der weltbesten LLM -Ressourcen.

  • wong2
  • Eine kuratierte Liste von Servern des Modellkontextprotokolls (MCP)

  • open-webui
  • Benutzerfreundliche KI-Schnittstelle (unterstützt Ollama, OpenAI-API, ...)

  • metorial
  • Containerisierte Versionen von Hunderten von MCP -Servern 📡 🧠

    Reviews

    2 (1)
    Avatar
    user_QrQSVuOj
    2025-04-16

    I have been using z3_mcp for a while now, and it has significantly improved my workflow. The seamless integration and robust features stand out, making complex project management much easier. Kudos to javergar for creating such a reliable and efficient tool. Highly recommended for anyone looking to enhance their productivity. Check it out at https://github.com/javergar/z3_mcp.