MCP cover image
See in Github
2025-04-06

用于约束优化和求解的模型上下文协议(MCP)服务器”

1

Github Watches

4

Github Forks

50

Github Stars


MCP Solver

MCP Compatible License: MIT Python Version

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


Overview

The MCP Solver integrates SAT, SMT and Constraint Solving 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, "MCP-Solver: Integrating Language Models with Constraint Programming Systems", arXiv:2501.00539, 2024.

Available Tools

In the following, item refers to some part of the (MinZinc/Pysat/Z3) 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 three 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

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

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.

Usage

The client provides specialized commands for each solver backend:

# MiniZinc mode
uv run test-client --query <query_file>.md

# PySAT mode
uv run test-client-pysat --query <query_file>.md

# Z3 mode
uv run test-client-z3 --query <query_file>.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.

Feedback

You can provide feedback to the author via this form.

Disclaimer

This MCP Solver is in its prototype stage and should be used with caution. Users are encouraged to experiment, but any use in critical environments is at their own risk.


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.

  • 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.

  • 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.

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

  • Alexandru Strujac
  • Efficient thumbnail creator for YouTube videos

  • 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
  • 发现市场上最全面,最新的MCP服务器集合。该存储库充当集中式枢纽,提供了广泛的开源和专有MCP服务器目录,并提供功能,文档链接和贡献者。

  • ShrimpingIt
  • MCP系列GPIO Expander的基于Micropython I2C的操作,源自ADAFRUIT_MCP230XX

  • Mintplex-Labs
  • 带有内置抹布,AI代理,无代理构建器,MCP兼容性等的多合一桌面和Docker AI应用程序。

  • n8n-io
  • 具有本机AI功能的公平代码工作流程自动化平台。将视觉构建与自定义代码,自宿主或云相结合,400+集成。

  • ravitemer
  • 一个功能强大的Neovim插件,用于管理MCP(模型上下文协议)服务器

  • WangRongsheng
  • 🧑‍🚀 llm 资料总结(数据处理、模型训练、模型部署、 o1 模型、mcp 、小语言模型、视觉语言模型)|摘要世界上最好的LLM资源。

  • jae-jae
  • MCP服务器使用剧作《无头浏览器》获取网页内容。

  • patruff
  • Ollama和MCP服务器之间的桥梁,使本地LLMS可以使用模型上下文协议工具

  • open-webui
  • 用户友好的AI接口(支持Ollama,OpenAi API,...)

    Reviews

    1 (1)
    Avatar
    user_1c3jY8gI
    2025-04-17

    As a dedicated user of mcp-solver, I must say this tool has been a game-changer for managing my computational problems. The author, szeider, has done a remarkable job by providing such a robust solution. The solver's performance is top-notch, and it integrates seamlessly into my workflow. Highly recommend checking it out at https://github.com/szeider/mcp-solver!