Skip to main content
Glama

Google OR-Tools server

by Jacck

MCP-OR工具

使用 Google OR-Tools 进行约束求解的模型上下文协议 (MCP) 服务器实现。该实现旨在通过标准化约束模型规范与大型语言模型配合使用。

概述

MCP-ORTools 通过模型上下文协议将 Google 的 OR-Tools 约束编程求解器与大型语言模型相集成,使 AI 模型能够:

  • 提交并验证约束模型
  • 设置模型参数
  • 解决约束满足和优化问题
  • 检索和分析解决方案

安装

  1. 安装软件包:
pip install git+https://github.com/Jacck/mcp-ortools.git
  1. 配置 Claude Desktop 在%APPDATA%\Claude\claude_desktop_config.json (Windows) 或~/Library/Application Support/Claude/claude_desktop_config.json (macOS) 创建配置文件:
{ "mcpServers": { "ortools": { "command": "python", "args": ["-m", "mcp_ortools.server"] } } }

型号规格

模型以 JSON 格式指定,包含三个主要部分:

  • variables :定义变量及其域
  • constraints :使用 OR-Tools 方法的约束列表
  • objective :可选优化目标

约束语法

约束必须使用 OR-Tools 方法语法:

  • .__le__()表示小于或等于 (<=)
  • .__ge__()表示大于或等于 (>=)
  • .__eq__()表示相等 (==)
  • .__ne__()表示不等于 (!=)

使用示例

简单优化模型

{ "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 } }

背包问题

示例:选择值为 [3,1,2,1]、权重为 [2,2,1,1] 的项目,总权重限制为 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)", // Item p0 must be selected "p1.__ne__(p2)", // Can't select both p1 and p2 "(p2 + p3).__ge__(1)" // Must select at least one of p2 or p3 ] }

特征

  • 全面支持 OR-Tools CP-SAT 求解器
  • 基于 JSON 的模型规范
  • 支持:
    • 整数和布尔变量(域:[最小值,最大值])
    • 使用 OR-Tools 方法语法的线性约束
    • 线性优化目标
    • 超时和求解器参数
    • 二元约束和关系
    • 投资组合选择问题
    • 背包问题

约束中支持的操作

  • 基本算术:+、-、*
  • 比较: .(),.(),.等式(), .()
  • 变量的线性组合
  • 通过约束组合的二进制逻辑

发展

开发设置:

git clone https://github.com/Jacck/mcp-ortools.git cd mcp-ortools pip install -e .

模型响应格式

求解器以 JSON 格式返回解决方案:

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

状态值:

  • 最佳:找到最佳解决方案
  • 可行:找到可行的解决方案
  • 不可行:不存在解决方案
  • 未知:无法确定解决方案

执照

MIT 许可证 - 详情请参阅许可证文件

-
security - not tested
A
license - permissive license
-
quality - not tested

MCP-ORTools 通过 MCP 将 Google 的 OR-Tools 约束编程求解器与大型语言模型相集成,使 AI 模型能够:

提交并验证约束模型 设置模型参数 解决约束满足和优化问题 检索并分析解决方案

  1. 概述
    1. 安装
      1. 型号规格
        1. 约束语法
      2. 使用示例
        1. 简单优化模型
        2. 背包问题
      3. 特征
        1. 约束中支持的操作
      4. 发展
        1. 模型响应格式
          1. 执照

            Related MCP Servers

            • -
              security
              A
              license
              -
              quality
              A Model Context Protocol (MCP) server that exposes MiniZinc constraint solving capabilities to Large Language Models.
              Last updated -
              83
              Python
              MIT License
              • Linux
              • Apple
            • -
              security
              A
              license
              -
              quality
              MCP-Logic is a server that provides AI systems with automated reasoning capabilities, enabling logical theorem proving and model verification using Prover9/Mace4 through a clean MCP interface.
              Last updated -
              20
              MIT License
              • Linux
              • Apple
            • A
              security
              A
              license
              A
              quality
              This server provides a minimal template for creating AI assistant tools using the ModelContextProtocol, featuring a simple 'hello world' tool example and development setups for building custom MCP tools.
              Last updated -
              1
              1
              8
              TypeScript
              The Unlicense
              • Apple
            • -
              security
              F
              license
              -
              quality
              A production-ready MCP server built with FastAPI, providing an enhanced tool registry for creating, managing, and documenting AI tools for Large Language Models (LLMs).
              Last updated -
              13
              Python

            View all related MCP servers

            MCP directory API

            We provide all the information about MCP servers via our MCP API.

            curl -X GET 'https://glama.ai/api/mcp/v1/servers/Jacck/mcp-ortools'

            If you have feedback or need assistance with the MCP directory API, please join our Discord server