MCP Connector

Integrate AI with Constraint Solvers

MCP Solver exposes constraint solving, SAT, SMT, and ASP capabilities to LLMs through the Model Context Protocol, enabling AI models to create, edit, and solve

Works with githubminizincpysatz3clingo

91
Spark score
out of 100
Updated 10 months ago
Version 1.0.0
Models
universal

Add to Favorites

Why it matters

Empower AI models with advanced constraint solving, SAT, SMT, and ASP capabilities. This asset enables interactive creation, editing, and solving of complex models using industry-standard tools like MiniZinc, PySAT, Z3, and Clingo.

Outcomes

What it gets done

01

Connect language models to constraint satisfaction problem (CSP) solvers.

02

Enable AI to generate, modify, and solve models in MiniZinc, PySAT, Z3, and Clingo.

03

Provide interactive problem-solving for AI agents through a Model Context Protocol server.

04

Facilitate optimization and complex reasoning tasks for AI applications.

Install

Add it to your toolbox

Run in your project directory:

curl -fsSL https://spark.entire.vc/get/vb-solver | bash

Capabilities

Tools your agent gets

clear_model

Remove all items from the constraint model

add_item

Add a new item at a specific index in the model

delete_item

Delete an item by index from the model

replace_item

Replace an item by index in the model

get_model

Get the current model contents with numbered items

solve_model

Solve the constraint model with optional timeout parameter

Overview

Solver MCP Server

MCP Solver is a Model Context Protocol server that integrates constraint solving, SAT, SMT, and ASP capabilities with Large Language Models. Use MCP Solver when you need an LLM to solve combinatorial optimization, scheduling, resource allocation, logic puzzles, or verification problems through formal constraint reasoning across five different solving paradigms.

What it does

MCP Solver is a Model Context Protocol server that bridges Large Language Models with five symbolic solving backends: MiniZinc constraint modeling, PySAT for SAT problems, MaxSAT optimization, Z3 SMT solving, and Clingo Answer Set Programming. It provides tools including clear_model, add_item, delete_item, replace_item, get_model, and solve_model that allow AI models to interactively construct and solve formal constraint programs.

When to use - and when NOT to

Use MCP Solver when you need an LLM to tackle combinatorial optimization, scheduling, resource allocation, logic puzzles, or verification problems that require formal constraint reasoning. It enables translating natural language problem statements into executable constraint models across different solving paradigms. Do NOT use this if your problem is purely statistical or numeric optimization better suited to gradient-based methods, or if you need real-time solving with sub-millisecond latency requirements.

Inputs and outputs

The server provides tools to add, delete, and replace items at specific indices in the model. The get_model tool returns the current model content with numbered items. The solve_model tool solves the model with a timeout parameter.

Integrations

MCP Solver integrates with five distinct solving backends, each requiring specific dependencies:

  • MiniZinc: Constraint modeling language with Chuffed solver integration, global constraints, and optimization support; includes get_solution for accessing solution values (requires minizinc package)
  • PySAT: Python SAT toolkit supporting multiple solvers (Glucose3, Glucose4, Lingeling) with CNF and cardinality constraints (at_most_k, at_least_k, exactly_k) for boolean constraint solving (requires python-sat package)
  • MaxSAT: Weighted CNF optimization via RC2 solver with hard and soft constraint support and objective tracking (requires python-sat package)
  • Z3: SMT solver with rich type system (booleans, integers, reals, bitvectors, arrays), quantifiers, optimization capabilities, and template library (requires z3-solver package)
  • Clingo: Answer Set Programming solver for declarative logic programming with choice rules, aggregates, optimization statements, and answer set inspection (requires clingo package)

The included MCP client is based on the ReAct agent framework and requires an API key from an LLM provider. The default LLM is Claude Sonnet 3.7 (requires ANTHROPIC_API_KEY environment variable). The client also supports other LLM providers including OpenAI, Google (Gemini), OpenRouter and local models via LM Studio.

Installation and usage

Install with Python 3.11+ and the uv package manager:

git clone https://github.com/szeider/mcp-solver.git
cd mcp-solver
uv venv
source .venv/bin/activate
uv pip install -e ".[all]"  # Install all solvers

Launch specific solver modes:

mcp-solver-mzn      # MiniZinc mode
mcp-solver-pysat    # PySAT mode
mcp-solver-maxsat   # MaxSAT mode
mcp-solver-z3       # Z3 mode
mcp-solver-asp      # ASP mode

Test with the included client:

uv pip install -e ".[client]"
uv run run-test mzn --problem <path/to/problem.md>

Who it's for

MCP Solver is designed for development, experimentation, and diagnostic purposes. The system architecture and theoretical foundations are detailed in the accompanying research paper by Stefan Szeider, "Bridging Language Models and Symbolic Solvers via the Model Context Protocol," SAT 2025.

Source README

MCP Solver

MCP Compatible License: MIT Python Version

A Model Context Protocol (MCP) server that exposes constraint solving, SAT, SMT, and ASP capabilities to Large Language Models.


Overview

The MCP Solver integrates constraint solving, SAT, SMT, and ASP with LLMs through the Model Context Protocol, enabling AI models to interactively create, edit, and solve:

For a detailed description of the MCP Solver's system architecture and theoretical foundations, see the accompanying research paper: Stefan Szeider, "Bridging Language Models and Symbolic Solvers via the Model Context Protocol", SAT 2025.

Available Tools

In the following, item refers to some part of the (MiniZinc/PySAT/Z3/ASP) code, and model to the encoding.

Tool Name Description
clear_model Remove all items from the model
add_item Add new item at a specific index
delete_item Delete item at index
replace_item Replace item at index
get_model Get current model content with numbered items
solve_model Solve the model (with timeout parameter)

System Requirements

  • Python and project manager uv
  • Python 3.11+
  • Mode-specific requirements: MiniZinc, PySAT, Python Z3 (required packages are installed via pip)
  • Operating systems: macOS, Windows, Linux (with appropriate adaptations)

Installation

MCP Solver requires Python 3.11+, the uv package manager, and solver-specific dependencies (MiniZinc, Z3, or PySAT).

For detailed installation instructions for Windows, macOS, and Linux, see INSTALL.md.

Quick start:

git clone https://github.com/szeider/mcp-solver.git
cd mcp-solver
uv venv
source .venv/bin/activate
uv pip install -e ".[all]"  # Install all solvers

Available Modes / Solving Backends

The MCP Solver provides five distinct operational modes, each integrating with a different constraint solving backend. Each mode requires specific dependencies and offers unique capabilities for addressing different classes of problems.

MiniZinc Mode

MiniZinc mode provides integration with the MiniZinc constraint modeling language with the following features:

  • Rich constraint expression with global constraints
  • Integration with the Chuffed constraint solver
  • Optimization capabilities
  • Access to solution values via get_solution

Dependencies: Requires the minizinc package (uv pip install -e ".[mzn]")

Configuration: To run in MiniZinc mode, use:

mcp-solver-mzn

PySAT Mode

PySAT mode allows interaction with the Python SAT solving toolkit with the following features:

  • Propositional constraint modeling using CNF (Conjunctive Normal Form)
  • Access to various SAT solvers (Glucose3, Glucose4, Lingeling, etc.)
  • Cardinality constraints (at_most_k, at_least_k, exactly_k)
  • Support for boolean constraint solving

Dependencies: Requires the python-sat package (uv pip install -e ".[pysat]")

Configuration: To run in PySAT mode, use:

mcp-solver-pysat

MaxSAT Mode

MaxSAT mode provides specialized support for optimization problems with PySAT, featuring:

  • Weighted Conjunctive Normal Form (WCNF) support
  • Integration with the RC2 MaxSAT solver
  • Optimization capabilities with objective tracking
  • Support for both hard and soft constraints

Dependencies: Requires the python-sat package (uv pip install -e ".[pysat]")

Configuration: To run in MaxSAT mode, use:

mcp-solver-maxsat

Z3 Mode

Z3 mode provides access to Z3 SMT (Satisfiability Modulo Theories) solving capabilities with the following features:

  • Rich type system: booleans, integers, reals, bitvectors, arrays
  • Constraint solving with quantifiers
  • Optimization capabilities
  • Template library for common modeling patterns

Dependencies: Requires the z3-solver package (uv pip install -e ".[z3]")

Configuration: To run in Z3 mode, use:

mcp-solver-z3

ASP Mode

ASP (Answer Set Programming) mode provides integration with ASP solvers (e.g., Clingo) for declarative problem solving with logic programs. Features include:

  • Expressive logic programming for combinatorial and knowledge representation problems
  • Support for constraints, choice rules, aggregates, and optimization statements
  • Integration with the Clingo solver for efficient answer set computation
  • Access to answer sets and model inspection

Dependencies: Requires the clingo package (uv pip install -e ".[asp]" or included in [all])

Configuration: To run in ASP mode, use:

mcp-solver-asp

MCP Test Client

The MCP Solver includes an MCP client for development, experimentation, and diagnostic purposes, based on the ReAct agent framework. This client serves as an intermediary between an LLM and the MCP server, facilitating the translation of natural language problem statements into formal constraint programming solutions.

Installation

# Install client dependencies
uv pip install -e ".[client]"

# Verify client installation and configuration
uv run test-setup-client

The client requires an API key from an LLM provider. For Anthropic (the default LLM is Claude Sonnet 3.7), set the ANTHROPIC_API_KEY environment variable. This can be set in your environment or included in a .env file in the project root.

The client also supports other LLM providers including OpenAI, Google (Gemini), OpenRouter and even local models via LM Studio. You can specify which model to use with the --mc command line flag. See INSTALL.md for details on model code formats.

Usage

The client provides specialized commands for each solver backend:

# MiniZinc mode
uv run run-test mzn --problem <path/to/problem.md>

# PySAT mode
uv run run-test pysat --problem <path/to/problem.md>

# MaxSAT mode
uv run run-test maxsat --problem <path/to/problem.md>

# Z3 mode
uv run run-test z3 --problem <path/to/problem.md>

# ASP mode
uv run run-test asp --problem <path/to/problem.md>

Examples

Example 1: Casting Problem (MiniZinc)

This is based on an example by George Johnson (NYT, July 13, 1999).

User

Suppose that a theatrical director feels obligated to cast either his ingenue, Actress Alvarez, or his nephew, Actor Cohen, in a production. But Miss Alvarez won't be in a play with Mr. Cohen (her former lover), and she demands that the cast include her new flame, Actor Davenport. The producer, with her own favors to repay, insists that Actor Branislavsky have a part. But Mr. Branislavsky won't be in any play with Miss Alvarez or Mr. Davenport. Can the director cast the play?

System: clear_model

Model cleared

System: add_item (multiple)

var bool: alvarez;
var bool: cohen;
var bool: branislavsky;
var bool: davenport;
constraint alvarez \/ cohen;                          % Must cast either Alvarez or Cohen
constraint not (alvarez /\ cohen);                    % Alvarez won't work with Cohen
constraint alvarez -> davenport;                      % If Alvarez is cast, Davenport must be cast
constraint branislavsky;                              % Branislavsky must be cast
constraint not (branislavsky /\ alvarez);             % Branislavsky won't work with Alvarez
constraint not (branislavsky /\ davenport);           % Branislavsky won't work with Davenport
solve satisfy;

System: solve_model

{'status': 'SAT', 'solution': Solution(alvarez=False, cohen=True, branislavsky=True, davenport=False, _checker=''), 'solve_time': 0.0}

The solution (cast Cohen and Branislavsky, but not Alvarez or Davenport) satisfies all constraints.

Example 2: N-Queens Problem (MiniZinc)

User

Check whether you can place n Queens on an nxn chessboard. Try n=10,20,30,40 and compare the solving times

System: clear_model

Model cleared

System: add_item (multiple)

int: n = 10;
array[1..n] of var 1..n: queens;
constraint alldifferent(queens);
constraint alldifferent([queens[i] + i | i in 1..n]);
constraint alldifferent([queens[i] - i | i in 1..n]);
solve satisfy;

System: solve_model (with n=10, 20, 30, and 40 by changing the value of n)

Solve times comparison: n=10: 0.001s n=20: 0.005s n=30: 0.040s n=40: 0.043s

Solutions exist for all tested board sizes. Time complexity increases non-linearly but remains manageable up to n=40.

Example 3: Traveling Salesperson Problem (MiniZinc)

User

A saleswoman based in Vienna needs to plan her upcoming tour through Austria, visiting each province capital once. Help find the shortest route. Distances in km: 1=Vienna, 2=St. Pölten, 3=Eisenstadt, 4=Linz, 5=Graz, 6=Klagenfurt, 7=Salzburg, 8=Innsbruck, 9=Bregenz

[Distance matrix table provided in user message]

System: add_item (multiple)

include "globals.mzn";
int: n = 9;
array[1..n,1..n] of int: dist = [|0,65,60,184,195,319,299,478,631|65,0,125,119,130,254,234,413,566|60,125,0,184,157,281,261,440,593|184,119,184,0,208,252,136,315,468|195,130,157,208,0,136,280,459,629|319,254,281,252,136,0,217,391,566|299,234,261,136,280,217,0,188,343|478,413,440,315,459,391,188,0,157|631,566,593,468,629,566,343,157,0|];
array[1..n] of var 1..n: succ;
var int: total_dist = sum(i in 1..n)(dist[i,succ[i]]);
constraint circuit(succ);
solve minimize total_dist;

System: solve_model

{'status': 'SAT', 'solution': Solution(objective=1564, succ=[2, 4, 1, 7, 3, 5, 9, 6, 8], _checker=''), 'solve_time': 0.002}

Optimal route: Vienna → St. Pölten → Linz → Salzburg → Bregenz → Innsbruck → Klagenfurt → Graz → Eisenstadt → Vienna with a total distance of 1,564 km.

FAQ

Common questions

Discussion

Questions & comments · 0

Sign In Sign in to leave a comment.