Opti-MCP

Opti-MCP

Enables AI assistants to solve linear, integer, mixed-integer, and knapsack optimization problems using Google OR-Tools via a simple JSON interface.

Category
访问服务器

README

Opti-MCP: Optimization MCP Server

A Model Context Protocol (MCP) server that provides tools for solving optimization problems using Google OR-Tools. This server enables AI assistants to solve Linear Programming (LP), Integer Programming (IP), Mixed-Integer Programming (MIP), and classic combinatorial optimization problems.

Features

  • Linear Programming: Solve continuous optimization problems with linear constraints
  • Integer/Mixed-Integer Programming: Solve optimization problems with integer decision variables
  • Knapsack Problem: Solve the classic 0/1 knapsack problem efficiently
  • Built on Google OR-Tools for robust, production-grade optimization
  • Simple JSON-based interface

Prerequisites

  • Node.js 18 or higher
  • Python 3.8 or higher
  • Google OR-Tools Python library

Installation

  1. Clone this repository:
git clone <your-repo-url>
cd opti-mcp
  1. Install Node.js dependencies:
npm install
  1. Install Python dependencies:
pip install ortools
  1. Build the TypeScript code:
npm run build

Configuration

Add to your MCP settings file (e.g., claude_desktop_config.json):

{
  "mcpServers": {
    "opti-mcp": {
      "command": "node",
      "args": ["/absolute/path/to/opti-mcp/dist/index.js"]
    }
  }
}

Available Tools

1. solve_linear_program

Solves linear programming problems where all variables are continuous.

Example: Production Planning

{
  "objective": {
    "coefficients": [3, 5],
    "maximize": true
  },
  "constraints": [
    {
      "coefficients": [1, 0],
      "upper_bound": 4
    },
    {
      "coefficients": [0, 2],
      "upper_bound": 12
    },
    {
      "coefficients": [3, 2],
      "upper_bound": 18
    }
  ],
  "variable_bounds": [[0, "Infinity"], [0, "Infinity"]]
}

This maximizes 3x₀ + 5x₁ subject to:

  • x₀ ≤ 4
  • 2x₁ ≤ 12
  • 3x₀ + 2x₁ ≤ 18
  • x₀, x₁ ≥ 0

2. solve_integer_program

Solves integer or mixed-integer programming problems.

Example: Assignment Problem

{
  "objective": {
    "coefficients": [1, 2, 3, 4],
    "maximize": false
  },
  "constraints": [
    {
      "coefficients": [1, 1, 0, 0],
      "lower_bound": 1,
      "upper_bound": 1
    },
    {
      "coefficients": [0, 0, 1, 1],
      "lower_bound": 1,
      "upper_bound": 1
    }
  ],
  "variable_bounds": [[0, 1], [0, 1], [0, 1], [0, 1]],
  "integer_variables": [0, 1, 2, 3]
}

This solves an assignment problem where variables must be binary (0 or 1).

3. solve_knapsack

Solves the 0/1 knapsack problem.

Example: Item Selection

{
  "values": [360, 83, 59, 130, 431, 67, 230, 52, 93, 125],
  "weights": [7, 0, 30, 22, 80, 94, 11, 81, 70, 64],
  "capacity": 850
}

Maximizes total value while keeping total weight ≤ capacity.

Example Problems

Diet Problem

Minimize cost while meeting nutritional requirements:

{
  "objective": {
    "coefficients": [2.5, 1.8, 3.0, 0.5],
    "maximize": false
  },
  "constraints": [
    {
      "coefficients": [10, 5, 8, 2],
      "lower_bound": 50
    },
    {
      "coefficients": [3, 8, 1, 6],
      "lower_bound": 30
    },
    {
      "coefficients": [5, 4, 7, 3],
      "lower_bound": 40
    }
  ]
}

Bin Packing

Pack items into minimum number of bins:

{
  "objective": {
    "coefficients": [1, 1, 1],
    "maximize": false
  },
  "constraints": [
    {
      "coefficients": [5, 0, 0],
      "upper_bound": 10
    },
    {
      "coefficients": [0, 7, 0],
      "upper_bound": 10
    },
    {
      "coefficients": [0, 0, 4],
      "upper_bound": 10
    }
  ],
  "integer_variables": [0, 1, 2]
}

Response Format

All solvers return a JSON response with:

{
  "status": "OPTIMAL",
  "objective_value": 34.0,
  "solution": [2.0, 6.0],
  "solve_time_ms": 15
}
  • status: OPTIMAL, INFEASIBLE, UNBOUNDED, or UNKNOWN
  • objective_value: The optimal value found (null if not optimal)
  • solution: Array of variable values (null if not optimal)
  • solve_time_ms: Time taken to solve in milliseconds

For knapsack problems:

{
  "status": "OPTIMAL",
  "total_value": 1030,
  "total_weight": 850,
  "selected_items": [0, 2, 3, 4],
  "capacity": 850
}

Development

# Watch mode for development
npm run dev

# Build for production
npm run build

# Run the server
npm start

How It Works

The MCP server:

  1. Receives optimization problems via MCP tool calls
  2. Translates them into Python scripts using OR-Tools
  3. Executes the Python scripts
  4. Returns formatted results

Limitations

  • Requires Python 3.8+ with OR-Tools installed
  • Currently uses GLOP for LP and SCIP for MIP (requires SCIP installation for best performance)
  • Large problems may take significant time to solve

License

MIT

Contributing

Contributions welcome! Please open an issue or PR.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选