OR-Tools MCP server

Integrates Google's OR-Tools to solve constraint satisfaction and optimization problems for decision-making in logistics and operations research.
Back to servers
Setup instructions
Provider
Jacck
Release date
Dec 21, 2024
Language
Python
Stats
13 stars

This MCP-ORTools server implements the Model Context Protocol to integrate Google's OR-Tools constraint programming solver with Large Language Models. It allows AI models to submit constraint models, solve optimization problems, and retrieve solutions through a standardized format.

Installation

To get started with MCP-ORTools:

  1. Install the package using pip:

    pip install git+https://github.com/Jacck/mcp-ortools.git
    
  2. Configure Claude Desktop by creating a configuration file:

    Windows:

    // %APPDATA%\Claude\claude_desktop_config.json
    {
      "mcpServers": {
        "ortools": {
          "command": "python",
          "args": ["-m", "mcp_ortools.server"]
        }
      }
    }
    

    macOS:

    // ~/Library/Application Support/Claude/claude_desktop_config.json
    {
      "mcpServers": {
        "ortools": {
          "command": "python",
          "args": ["-m", "mcp_ortools.server"]
        }
      }
    }
    

Model Specification

Models are specified in JSON format with three main sections:

  • variables: Define variables and their domains
  • constraints: List of constraints using OR-Tools methods
  • objective: Optional optimization objective

Constraint Syntax

Constraints must use OR-Tools method syntax:

  • .__le__() for less than or equal (<=)
  • .__ge__() for greater than or equal (>=)
  • .__eq__() for equality (==)
  • .__ne__() for not equal (!=)

Usage Examples

Simple Optimization Model

{
    "variables": [
        {"name": "x", "domain": [0, 10]},
        {"name": "y", "domain": [0, 10]}
    ],
    "constraints": [
        "(x + y).__le__(15)",
        "x.__ge__(2 * y)"
    ],
    "objective": {
        "expression": "40 * x + 100 * y",
        "maximize": true
    }
}

Knapsack Problem

This example selects items with values [3,1,2,1] and weights [2,2,1,1], with a total weight limit of 2:

{
    "variables": [
        {"name": "p0", "domain": [0, 1]},
        {"name": "p1", "domain": [0, 1]},
        {"name": "p2", "domain": [0, 1]},
        {"name": "p3", "domain": [0, 1]}
    ],
    "constraints": [
        "(2*p0 + 2*p1 + p2 + p3).__le__(2)"
    ],
    "objective": {
        "expression": "3*p0 + p1 + 2*p2 + p3",
        "maximize": true
    }
}

Additional Constraints Example

{
    "constraints": [
        "p0.__eq__(1)",         
        "p1.__ne__(p2)",        
        "(p2 + p3).__ge__(1)"   
    ]
}

Features

MCP-ORTools supports:

  • Full OR-Tools CP-SAT solver functionality
  • JSON-based model specification
  • Integer and boolean variables (domain: [min, max])
  • Linear constraints using OR-Tools method syntax
  • Linear optimization objectives
  • Timeouts and solver parameters
  • Binary constraints and relationships
  • Portfolio selection problems
  • Knapsack problems

Supported Operations in Constraints

  • Basic arithmetic: +, -, *
  • Comparisons: .le(), .ge(), .eq(), .ne()
  • Linear combinations of variables
  • Binary logic through combinations of constraints

Response Format

The solver returns solutions in JSON format:

{
    "status": "OPTIMAL",
    "solve_time": 0.045,
    "variables": {
        "p0": 0,
        "p1": 0,
        "p2": 1,
        "p3": 1
    },
    "objective_value": 3.0
}

Status values include:

  • OPTIMAL: Found optimal solution
  • FEASIBLE: Found feasible solution
  • INFEASIBLE: No solution exists
  • UNKNOWN: Could not determine solution

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "ortools" '{"command":"python","args":["-m","mcp_ortools.server"]}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "ortools": {
            "command": "python",
            "args": [
                "-m",
                "mcp_ortools.server"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "ortools": {
            "command": "python",
            "args": [
                "-m",
                "mcp_ortools.server"
            ]
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later