DEV Community

Cover image for MiniZinc MCP for your AI Agent
carban
carban

Posted on

MiniZinc MCP for your AI Agent

Hello Again! 👋

I just want to share a new tool I've been developing for the community: a MiniZinc MCP tool. This tool empowers your AI agents by allowing them to model and solve combinatorial and optimization problems. Check out the GitHub repository:
👉 github.com/carban/minizinc-mcp

minizinc-mcp-logo

Constraint Modeling

In computer science, there are many combinatorial and optimization problems that researchers have been working on, for example problems like the Knapsack problem, scheduling optimization, planning, resource allocation, and more. All of these are great examples of problems we can model and solve using a Constraint Modeling Language.

minizinc-mcp

What is MiniZinc?

MiniZinc is a free and open-source constraint modeling language. You can use MiniZinc to model constraint satisfaction and optimization problems in a high-level,
And that's why it's awesome:, a MiniZinc model does not dictate how to solve the problem. Instead, the MiniZinc compiler translates your model into different forms suitable for a wide range of underlying solvers such as Constraint Programming (CP), Mixed Integer Linear Programming (MIP) or Boolean Satisfiability (SAT) solvers. You focus on the modeling, and the solver searches for the solution. In other words, it does the hard part for you.

The MiniZinc language lets users write models in a way that is close to a mathematical formulation of the problem, using familiar notation such as existential and universal quantifiers, sums over index sets, or logical connectives like implications and if-then-else statements.

Let's see an example:

Imagine you are packing a backpack for a hike. You have a maximum weight capacity of 15 kg. You can choose from four items, each with a specific weight and value. You want to maximize the total value of the items you take without exceeding the weight limit.

Available Items:
Item 1: Weight = 2 kg, Value = $10
Item 2: Weight = 4 kg, Value = $10
Item 3: Weight = 6 kg, Value = $12
Item 4: Weight = 9 kg, Value = $18

Mathematical Model

Parameters:

W=15(Maximum weight capacity)W = 15 \text{(Maximum weight capacity)}

v=[10,10,12,18](Item values)v = [10, 10, 12, 18]\text{(Item values)}

w=[2,4,6,9](Item weights)w = [2, 4, 6, 9]\text{(Item weights)}

Decision Variables:

xi0,1i1,2,3,4 x_i \in {0, 1} \quad \forall i \in {1, 2, 3, 4}

Where:

xi=1; if item i is selectedx_i = 1 ; \text{ if item i is selected}

xi=0; otherwisex_i = 0 ; \text{ otherwise}

Constraints:

Total weight cannot exceed capacity W:

i=14wixiW \sum_{i=1}^{4} w_i x_i \le W

Which expands to:

2x1+4x2+6x3+9x415 2x_1 + 4x_2 + 6x_3 + 9x_4 \le 15

Objective Function:

Maximize total value:

maxi=14vixi \max \sum_{i=1}^{4} v_i x_i

Which expands to:

max10x1+10x2+12x3+18x4 \max \quad 10x_1 + 10x_2 + 12x_3 + 18x_4

MiniZinc code

% Decision variables: 1 if item is included, 0 otherwise
var 0..1: x1;
var 0..1: x2;
var 0..1: x3;
var 0..1: x4;

% Weight constraint
constraint 2*x1 + 4*x2 + 6*x3 + 9*x4 <= 15;

% Objective: Maximize total value
solve maximize 10*x1 + 10*x2 + 12*x3 + 18*x4;

% Output formatting
output ["x1: ", show(x1), "\n",
        "x2: ", show(x2), "\n",
        "x3: ", show(x3), "\n",
        "x4: ", show(x4), "\n",
        "Total Value: ", show(10*x1 + 10*x2 + 12*x3 + 18*x4)];
Enter fullscreen mode Exit fullscreen mode

Result

x1: 1
x2: 1
x3: 0
x4: 1
Total Value: 38
Enter fullscreen mode Exit fullscreen mode

What the MCP does?

Today, in most cases, it's not even necessary to formally model problems from scratch; AI can do that for us (in most cases, I repeat). This makes it much easier for developers to express questions in natural language, get answers from the model faster, and iterate or optimize workflows seamlessly.

By pairing LLMs with MiniZinc via MCP, you can speed up problem modeling, validate correctness, execute models, and analyze results using natural language, unlocking one of the biggest advantages of working with modern AI agents.

This MCP creates a layer of communication between your AI Agent and MiniZinc allowing you to:

Tool Description
list_solvers Lists every MiniZinc solver installed on the machine. The returned tag names (e.g. gecode, chuffed, highs) can be passed to solve_model.
validate_model Parses and type-checks MiniZinc model code without solving it. Useful for checking model syntax up front. Returns VALID or INVALID with an error message.
solve_model Solves a MiniZinc model given as source code: once, exhaustively (all_solutions), or with a solution / time limit. Returns the status, solution(s), objective value (for optimization problems), and solver statistics.
solve_model_by_path Same as solve_model but loads the model and its optional data (.dzn) file from paths instead of source code.
get_model_info Inspects a model without solving it: returns its solve method (satisfy/minimize/maximize) and the declared input parameters and output variables with their types. Useful for an agent to know exactly which params a model expects.
get_flatzinc Compiles a model (and optional data) to FlatZinc text without solving it. Returns the .fzn model, the .ozn output model, and flattening statistics. Useful for debugging and low-level inspection.

Examples

A basic one:
"Find the optimal solution to a knapsack problem with items having weisghts [2,3,4,5] and values [3,4,5,6] and capacity 7"

minizinc-mcp-example-1

A tough one:
"A banana cake which takes 250g of self-raising flour, 2 mashed bananas, 75g sugar and 100g of butter, and a chocolate cake which takes 200g of self-raising flour, 75g of cocoa, 150g sugar and 150g of butter. We can sell a chocolate cake for $4.50 and a banana cake for $4.00. And we have 4kg self-raising flour, 6 bananas, 2kg of sugar, 500g of butter and 500g of cocoa. The question is how many of each sort of cake should we bake for the fete to maximise the profit."

minizinc-mcp-example-2

Install it 🤖

Prerequisites

Only two things need to be installed, once per machine:

  • uvcurl -LsSf https://astral.sh/uv/install.sh | sh
  • MiniZinc 2.6+ with the minizinc executable on PATH (includes a default solver, Gecode)

Everything else is fetched automatically by uv — there is no clone, no venv setup, and no manual pip install on your side.

Install the server (pick one)

Install it globally (best if you use it in several projects):

uv tool install --from git+https://github.com/carban/minizinc-mcp minizinc-mcp
Enter fullscreen mode Exit fullscreen mode

Or run it on demand each time, with nothing installed:

uvx --from git+https://github.com/carban/minizinc-mcp minizinc-mcp
Enter fullscreen mode Exit fullscreen mode

Wire it into your MCP client

The server runs over stdio. Tell your MCP client to launch it:

opencode — project level (add this to opencode.jsonc in your project):

{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "minizinc": {
      "type": "local",
      "command": ["uvx", "--from", "git+https://github.com/carban/minizinc-mcp", "minizinc-mcp"]
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Researching

Additionally, this tool aims to support scientific research and the integration of computational models with AI agents. By enabling new approaches to problem-solving, it opens up a wide range of possibilities.

If you have new ideas, tools or improvements to this project just let me know commenting this post or creating a new issue in the GitHub repo github.com/carban/minizinc-mcp

Share the project with a friend! 🌟

This is open-source project and just getting started, you can star it on GitHub, it helps others find it.

Top comments (0)