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.
To get started with MCP-ORTools:
Install the package using pip:
pip install git+https://github.com/Jacck/mcp-ortools.git
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"]
}
}
}
Models are specified in JSON format with three main sections:
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 (!=){
"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
}
}
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
}
}
{
"constraints": [
"p0.__eq__(1)",
"p1.__ne__(p2)",
"(p2 + p3).__ge__(1)"
]
}
MCP-ORTools supports:
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:
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.
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.
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"
]
}
}
}
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.
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.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.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