mcp-solver
It is an MCP server that solves constraint problems by having your MCP host write and run Python programs against six solver backends.
Pick a backend with
select_backend:pysat(SAT),maxsat(weighted MaxSAT),z3(SMT: integers, reals, bitvectors),cpmpy(constraint programming),clingo(answer set programming), ordidp(dynamic programming). This starts a persistent IPython kernel with that backend's library and returns modeling instructions (the template).Write and iterate on code in the kernel with
python_exec(state persists; timeout up to 300 s).Inspect kernel state (kernels, variables, packages) with
python_status, and stop runaway code withpython_interrupt(state preserved).Restart or create kernels with
python_reset, optionally installing extra packages alongside the backend's libraries.Submit the final, self-contained program with
submit_code: it is compile-checked, run standalone in a fresh isolated environment (240 s, 4 MB stdout limit), self-checked viamain(check=True), and stored as a resource (mcp-solver://submissions/{id}, last 50 kept).Read resources:
mcp-solver://guide(workflow, backend choice, time limits) andmcp-solver://template/{solver}.Handle outcomes including UNSAT / "no solution exists" as valid results, and enable per-episode statistics via
MCP_SOLVER_STATS.Work without an MCP host through the
mcp-solverCLI / mcp-minion, or benchmark withmcp-solver-benchover 30 bundled test problems and their validators.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@mcp-solver solve this scheduling problem with 3 workers and 5 tasks"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
MCP Solver
MCP Solver is an MCP server for constraint solving with SAT, MaxSAT, SMT, constraint programming, answer set programming and dynamic programming. You describe a problem in plain words to your MCP host, such as Claude Desktop or Claude Code. The host's language model writes a Python program for one of six backends, each built on a solver library, and runs it in a kernel, a Python process that the server starts. When the host submits the program, the server runs it once more on its own, and you get the solution as JSON together with the program.
This is version 4. Version 3, described in the SAT 2025 paper, works differently (see From v3 to v4). To connect the server to your host, see Quick start.
Example
The following small scheduling problem is shortened from
tests/problems/clingo/shift_assignment.md.
The run below solved it with the clingo backend (answer set programming).
Assign two employees, Anna and Ben, to three shifts: morning, afternoon, evening. Each shift gets exactly one employee, and nobody works more than two shifts. Anna prefers all three shifts, Ben only the morning. Maximize the number of shifts that go to an employee who prefers them. Return JSON with
satisfiable,assignmentandsatisfied_preferences.
The program printed this solution:
{"satisfiable": true, "assignment": {"afternoon": "anna", "evening": "anna", "morning": "ben"}, "satisfied_preferences": 3}The submitted program has 98 lines. This excerpt shows its shape:
import json
import itertools
import clingo
# ... 6 lines: EMPLOYEES, SHIFTS and PREFERENCES, the instance data
ASP_RULES = """
1 { assigned(Shift,Employee) : employee(Employee) } 1 :- shift(Shift).
:- employee(Employee), 3 { assigned(Shift,Employee) : shift(Shift) }.
satisfied(Shift) :- assigned(Shift,Employee), prefers(Employee,Shift).
preference_score(Score) :- Score = #count { Shift : satisfied(Shift) }.
#maximize { 1,Shift : satisfied(Shift) }.
"""
# ... 2 lines: quote(value) writes a name as a quoted string for clingo
def solve():
# ... 28 lines: add the data as facts, ground, keep each model in on_model
result = control.solve(on_model=on_model)
if not result.satisfiable:
return {"satisfiable": False}
if not result.exhausted:
raise RuntimeError("Optimization did not finish, so optimality is unproven")
return best
def verify(solution):
# ... 24 lines: check each constraint and the score, try all assignments
assert actual_score == max(feasible_scores), "assignment is not preference-optimal"
def main(check=False):
solution = solve()
if check:
verify(solution)
print(json.dumps(solution))
if __name__ == "__main__":
main()This example comes from one run of the command
mcp-solver clingo --problem tests/problems/clingo/shift_assignment.md (see
Command line) on version 4.5.0 with the
default model, openai/gpt-5.6-terra. The problem's validator accepted the
solution.
Related MCP server: mcp-optimizer
Quick start
You need Python 3.13 or 3.14 and uv on the
PATH (the server starts its kernels through uv). The server runs no language
model and needs no API key. The PyPI package is agentic-mcp-solver. Do not
install the PyPI package mcp-solver, a third-party upload of stale v2.0.0
code (a PEP 541 transfer request is
pending). The commands keep the names mcp-solver and mcp-solver-serve.
Claude Desktop. Add the server to claude_desktop_config.json. uvx
fetches the package from PyPI, so there is no install step:
{
"mcpServers": {
"mcp-solver": {
"command": "uvx",
"args": ["--python", "3.14", "--from", "agentic-mcp-solver[agent]", "mcp-solver-serve"]
}
}
}Restart Claude Desktop after editing the file. If it cannot find uvx, put
the absolute path of uvx (the output of which uvx) in command.
Claude Code. Register the server once (add -s user to make it
available in all projects):
claude mcp add mcp-solver -- uvx --python 3.14 --from "agentic-mcp-solver[agent]" mcp-solver-serveAny other MCP host. Configure a stdio server with the same command.
Then describe your problem to the host and ask it to use MCP Solver. You do
not write the program yourself. To install the commands instead, run
uv tool install --python 3.14 "agentic-mcp-solver[agent]". For a source
checkout and for troubleshooting, see INSTALL.md.
Backends
Backend | Problem class | Library | Typical use |
| Boolean satisfiability (SAT) | python-sat | placements, colorings, covers |
| Weighted MaxSAT | python-sat | hard constraints plus weighted preferences |
| SMT | z3-solver | integer and real arithmetic, verification |
| Constraint programming (CP) | CPMpy | rosters, timetables, assignment |
| Answer set programming (ASP) | clingo | rules with defaults and exceptions, reachability |
| Domain-independent dynamic programming | didppy | routing with time windows, sequencing, packing |
The kernel starts with the packages of the chosen backend: python-sat[pb],
z3-solver, cpmpy, clingo, or didppy>=0.11.1,<0.12. A didp model is
a state transition system (DIDP, Kuroiwa and Beck). By
default the program solves it with didppy's anytime beam search (CABS).
How it works
Select a backend.
select_backend(solver)takes a backend name such asclingo. It starts the kernel, an IPython kernel that keeps its state between calls, with that backend's library. It returns the backend's modeling instructions, called the template.Write and run. The host runs code in the kernel with
python_exec, builds the constraint model step by step, and runs the solver on it.Check. The template asks for a program in three parts.
solve()builds and solves the constraint model and returns the solution as a dict.verify(solution)re-checks every constraint and the objective value in plain Python and raisesAssertionErrorwhen a check fails.main(check=False)runssolve(), runsverify()only whencheckis true, and prints the solution as JSON. A__main__guard callsmain(). In the kernel, the host runsmain(check=True)as the final test.Submit.
submit_code(code)takes the final program and passes it through the submission gate. The server checks that the program compiles and then runs it once on its own, in a fresh temporary directory withuv run --isolatedand the kernel's packages. This standalone run has none of the kernel's state, may take at most 240 s and may print at most 4 MB. If it exits nonzero, times out, prints too much or prints nothing, the server rejects the submission and names the reason, for example the last traceback line. The host can then fix the program and submit it again.Self-check. After an accepted run, the server loads the program in a second fresh environment, calls
main(check=True)within what is left of the 240 s, and reports the outcome asself_check:passed,failedornot_available(for example whenmain()takes nocheckargument). The self-check is information only. A failed self-check does not reject the submission, since a wrongverify()can fail a right solution.
The server does not compare the solution with the problem. An accepted submission means that the program ran without the kernel's state, exited with code 0 and printed output.
The kernels come from ipython_mcp, the kernel server of
agentic-python-coder 4
(>=4,<5), which mcp-solver-serve controls. Below, "engine" means
agentic-python-coder.
Command line and mcp-minion
mcp-minion is the project's scripted agent, a separate PyPI package
developed in minion/. It does what an MCP host does, driven by a
script instead of a chat, and calls a language model through
OpenRouter with your API key. The mcp-solver
command uses it to solve a problem without an MCP host:
mcp-solver pysat "Place 8 non-attacking queens on an 8x8 board and give one solution."
mcp-solver pysat --problem tests/problems/pysat/n_queens.mdHere mcp-minion talks to the engine's kernel server directly, with the
template as its system prompt. The CLI writes the submitted program to
<basename>_code.py in the working directory, where <basename> is the
problem file's name without .md (n_queens_code.py above) or task for a
task given on the command line. The CLI then makes a standalone run of the
program with uv run --isolated (360 s limit) and prints its output, the
solution JSON, to stdout. A run log run_*.json goes to the working
directory too.
Option | Description |
| Read the task from a markdown file instead of the command line |
| Agent model: an alias, a model |
| Working directory for the run (default: current directory) |
| Maximum agent steps (default 30) |
| Maximum input plus output tokens of the run, 0 for none (default 2,000,000) |
| Suppress progress output |
| Take templates from a source checkout (on by default inside one, or set |
| Use the packaged templates |
| Write the run statistics, including tokens and cost, as JSON |
mcp-minion can also drive mcp-solver-serve the way an MCP host does, from a
run folder that holds config.json and task.md (see
minion/README.md). In a source checkout,
mcp-solver-runfolder clingo shift_assignment ~/demos/shift writes one for a
bundled test problem, and
uv run --project /path/to/mcp-solver --extra agent mcp-minion -v ~/demos/shift
runs it.
The mcp-solver command looks for OPENROUTER_API_KEY in the environment,
in ~/.config/coder/.env and in ~/.mcp-minion. The standalone
mcp-minion command looks in the environment, in the run folder's .env
and in ~/.mcp-minion. A key in the environment or in ~/.mcp-minion (a
line OPENROUTER_API_KEY=...) serves both.
The MCP server in detail
mcp-solver-serve speaks MCP over stdio, takes no arguments and has six tools:
select_backend(solver)takes a backend name and creates the kernel or restarts it for a new problem or backend. The engine knows this kernel by the idsolver. The result is the full template as text, followed by a note. The note says whether the kernel is fresh or was recycled, names its id and packages, and asks the host to run the complete program withpython_execbefore callingsubmit_code.python_exec(code, timeout=30, kernel_id=None)runs code in the kernel. The server limits itstimeoutto 300 s.python_reset(packages=None, kernel_id=None)restarts the kernel. Extrapackagesare installed next to the backend's libraries, which stay.python_status(kernel_id=None)lists kernels, variables and packages.python_interrupt(kernel_id=None)stops running code and keeps the kernel's state.submit_code(code)runs the submission gate and the self-check of steps 4 and 5 in How it works. The reply to an accepted submission containsexecuted,exit_code,stdout(the last 20,000 characters),self_check(its status and a message) and a link to the stored program,mcp-solver://submissions/{id}(the server keeps the last 50). When stdout is longer, the reply says that it shows only the end. The server returns a rejected submission as an error result and does not store it. Before anyselect_backend, the check is compile-only and the reply says so.
After select_backend, kernel tool calls without kernel_id act on this
kernel. A call with an explicit kernel_id goes to the engine unchanged. The
server also offers the resources mcp-solver://guide (workflow, backend
choice, time limits), mcp-solver://template/{solver} (each template,
without selecting a backend) and the stored submissions.
Statistics. Set MCP_SOLVER_STATS=/path/to/stats.jsonl in the env
block of the host's server configuration (a variable set only in your shell
may not reach the server). The server then writes one JSON line per episode
(from one select_backend call to the next, or to server shutdown) with
tool-call counts, execution failures, submit attempts and successes,
python_exec calls before the first submission, the self-check status of
the last accepted submission, and wall time.
submit_code results contain a compact snapshot as structured content. The
server cannot see how many tokens the host uses, since MCP does not pass that
on, so compare hosts by their tool usage.
Environment. Kernels and standalone runs get a filtered environment: a
short whitelist (HOME, PATH, locale, temp, proxy, CA bundle) and the
prefixes UV_, CODER_, MCP_SOLVER_, XDG_, LC_, minus names that
contain KEY, TOKEN, SECRET, PASSWORD or CREDENTIAL. API keys in
the environment therefore do not reach model-written code. That code still
runs with your file permissions and can read credentials stored in files or
inside a passed URL. The filter is not a sandbox.
Benchmark harness
The repository contains 30 test problems in tests/problems/<backend>/,
each with an output-format section and a *_ground_truth.py validator that
reads the solution JSON on stdin and returns {"valid": ..., "message": ...}.
Validators of optimization problems recompute the optimum.
mcp-solver-bench solves the problems through the CLI and validates every
result:
mcp-solver-bench # every backend
mcp-solver-bench pysat z3 --runs 3 --jobs 4 # two backends, 3 runs each, 4 in parallelA run counts as valid only if the validator accepts the solution and the
program imports its backend's library. Results are appended to
results.jsonl in the output directory (default
bench_results/<timestamp>). The same problems run as pytest end-to-end
tests, for example with uv run pytest minion/e2e_tests -k didp.
On two larger benchmarks, Claude Code with Claude Opus 5.5 as the host and
mcp-solver-serve 4.5.0 solved all 229 problems, each in one session with
one submission: 101 of 101 in
CP-Bench v3 (cpmpy backend) and
128 of 128 in ASP-Bench v1.2
(clingo backend). The benchmark's validator checked every
solution. A session took 40 s (CP-Bench) and 59 s (ASP-Bench) in the median.
The templates were revised while these benchmarks were run, in two places
after a failure on a single problem, so the figures describe the released
templates on these problems and are not a held-out test.
From v3 to v4
The SAT 2025 paper, "Bridging Language Models and Symbolic Solvers via the
Model Context Protocol",
describes v3, an MCP server with model-editing tools (add_item,
replace_item, solve_model, ...) through which the host's language model
builds a solver model item by item for the server to solve. The v3 code is
still on the v3 branch,
unchanged. v4 replaces these tools with the execution of a complete Python
program and follows the IPython-kernel approach of the
CP-Agent and
ASP-Bench papers.
v3 (SAT 2025 paper) | v4 | |
Who solves | The host's language model, via model-editing tools | The host's language model (or mcp-minion), as a solver programmer |
Unit of work | Model items ( | A complete, runnable Python program |
Execution | Inside the MCP server | In a kernel, then once more in a standalone run |
Checking | Left to the host's language model |
|
Result | Transient model state | A program you keep, plus its solution |
Backends | MiniZinc, PySAT, MaxSAT, Z3, ASP | PySAT, MaxSAT, Z3, CPMpy, clingo, DIDP |
Citations
Stefan Szeider, "Bridging Language Models and Symbolic Solvers via the Model Context Protocol", in 28th International Conference on Theory and Applications of Satisfiability Testing (SAT 2025), LIPIcs, volume 341, pages 30:1–30:12, Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2025. Describes v3.
Stefan Szeider, "CP-Agent: Agentic Constraint Programming", in Proceedings of the 3rd International Workshop on Large Language Models For Code (LLM4Code 2026), pages 6–13, ACM, 2026. The IPython-kernel approach that v4 uses.
Stefan Szeider, "ASP-Bench: From Natural Language to Logic Programs", in Proceedings of the 2026 IEEE/ACM 2nd International Workshop on Neuro-Symbolic Software Engineering (NSE '26), pages 1–8, ACM, 2026. Its benchmark accepts a solution only after a validator has checked it, as the test problems of v4 do.
License
MIT. See LICENSE.
Available Tools
6 toolspython_execA
Execute Python code in the persistent solving kernel.
Runs in the kernel set up by select_backend unless kernel_id overrides it. State persists across calls (variables, imports). Raise timeout (seconds, max 300) for long solver runs.
Inputs: code (required), timeout, kernel_id.
python_interruptB
Interrupt running code in the solving kernel (state is preserved).
Inputs: kernel_id.
python_resetA
Create a new kernel (no kernel_id) or reset one (with kernel_id).
Prefer select_backend, which installs the right solver packages for you. The kernel created or reset here becomes the target of bare python_exec calls.
Inputs: packages, kernel_id.
python_statusC
Check kernel state: active kernels, defined variables, packages.
Inputs: kernel_id.
select_backendA
Start solving a constraint problem: call this FIRST, once per problem.
Sets up a persistent IPython kernel preloaded with the backend's solver library and helper functions, and returns the modeling instructions for that backend. Calling it again recycles the kernel for a new problem (previous session state is cleared).
Backends:
pysat: Boolean satisfiability — feasibility, combinatorial search
maxsat: weighted optimization over Boolean constraints
z3: SMT — integers/reals/bitvectors, proofs, program verification
cpmpy: finite-domain constraint programming — scheduling, assignment, puzzles
clingo: Answer Set Programming — logic rules, defaults, reachability
didp: dynamic programming (state-space search) — routing, sequencing, packing
Unsure which backend fits? Read the resource mcp-solver://guide first.
Then iterate with python_exec (write, run, verify against the problem statement), and finish by calling submit_code with the final, verified, self-contained program. UNSAT / "no solution exists" is a valid outcome.
Inputs: solver (required).
submit_codeA
Submit the final, verified, self-contained solver program.
Call ONCE at the end, only after executing the program via python_exec and passing your verification. The code is syntax-checked; on success it is stored and linked as a resource (the server keeps the last 50).
Inputs: code (required).
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 6 tools
Most tools are clearly distinct: python_status, python_interrupt, python_exec, and submit_code each have a unique role. The only mild overlap is between select_backend and python_reset (both create/configure kernels), but descriptions explicitly steer users to prefer select_backend, resolving the ambiguity.
Four tools share a consistent python_<action> prefix (python_status, python_interrupt, python_exec, python_reset), but select_backend and submit_code break this pattern with a verb_noun convention. Two coexisting conventions make it mixed but still readable.
Six tools is well-scoped for a constraint-solving workflow: backend setup, execution, kernel management, and final submission. Each tool earns its place with no redundancy.
The lifecycle (select_backend -> python_exec iterate -> submit_code, with status/interrupt/reset for kernel control) is well covered. Minor gaps: no tool to list or retrieve previously submitted solutions (only a resource mention), but core workflows are complete.
Maintenance
Related MCP Connectors
A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yo…
A Model Context Protocol server for Wix AI tools
MCP server for progressive tool usage at any scale (see https://klavis.ai)
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceMCP-ORTools integrates Google's OR-Tools constraint programming solver with Large Language Models through the MCP, enabling AI models to: Submit and validate constraint models Set model parameters Solve constraint satisfaction and optimization problems Retrieve and analyze solution22MIT
- AlicenseBqualityDmaintenanceMathematical Optimization MCP Server with PuLP and OR-Tools support135MIT
- AlicenseNot gradedqualityDmaintenanceEnables solving Constraint Satisfaction Problems (CSP) like N-Queens, graph coloring, and Sudoku, as well as Linear Programming optimization problems through both MCP tools and HTTP API endpoints.2MIT
- AlicenseNot gradedqualityNot gradedmaintenanceAn MCP server that enables Large Language Models to interactively create, edit, and solve constraint models using backends like MiniZinc, Z3, PySAT, and Clingo. It bridges natural language with symbolic reasoning for solving complex logical, SAT, SMT, and optimization problems.MIT