Cover image
Try Now
2024-12-27

Implementación del servidor del Protocolo de contexto del modelo (MCP) utilizando Google o Tools para resolver restricciones

3 years

Works with Finder

1

Github Watches

1

Github Forks

9

Github Stars

MCP-ORTools

A Model Context Protocol (MCP) server implementation using Google OR-Tools for constraint solving. Designed for use with Large Language Models through standardized constraint model specification.

Overview

MCP-ORTools integrates Google's OR-Tools constraint programming solver with Large Language Models through the Model Context Protocol, enabling AI models to:

  • Submit and validate constraint models
  • Set model parameters
  • Solve constraint satisfaction and optimization problems
  • Retrieve and analyze solutions

Installation

  1. Install the package:
pip install git+https://github.com/Jacck/mcp-ortools.git
  1. Configure Claude Desktop Create the configuration file at %APPDATA%\Claude\claude_desktop_config.json (Windows) or ~/Library/Application Support/Claude/claude_desktop_config.json (macOS):
{
  "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

Example: Select items with values [3,1,2,1] and weights [2,2,1,1] with 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)",         // 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
    ]
}

Features

  • Full OR-Tools CP-SAT solver support
  • JSON-based model specification
  • Support for:
    • 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

Development

To setup for development:

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

Model 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:

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

License

MIT License - see LICENSE file for details

相关推荐

  • NiKole Maxwell
  • I craft unique cereal names, stories, and ridiculously cute Cereal Baby images.

  • Andris Teikmanis
  • Latvian GPT assistant for developing GPT applications

  • Joshua Armstrong
  • Confidential guide on numerology and astrology, based of GG33 Public information

  • https://suefel.com
  • Latest advice and best practices for custom GPT development.

  • Navid RezaeiSarchoghaei
  • Professional Flask/SQLAlchemy code guide. Follow: https://x.com/navid_re

  • Emmet Halm
  • Converts Figma frames into front-end code for various mobile frameworks.

  • https://cantaspinar.com
  • Summarizes videos and answers related questions.

  • https://tovuti.be
  • Oede knorrepot die vasthoudt an de goeie ouwe tied van 't boerenleven

  • Elijah Ng Shi Yi
  • Advanced software engineer GPT that excels through nailing the basics.

  • apappascs
  • Descubra la colección más completa y actualizada de servidores MCP en el mercado. Este repositorio sirve como un centro centralizado, que ofrece un extenso catálogo de servidores MCP de código abierto y propietarios, completos con características, enlaces de documentación y colaboradores.

  • ShrimpingIt
  • Manipulación basada en Micrypthon I2C del expansor GPIO de la serie MCP, derivada de AdaFruit_MCP230xx

  • OffchainLabs
  • Implementación de la prueba de estaca Ethereum

  • huahuayu
  • Una puerta de enlace de API unificada para integrar múltiples API de explorador de blockchain similar a Esterscan con soporte de protocolo de contexto modelo (MCP) para asistentes de IA.

  • deemkeen
  • Controle su MBOT2 con un combo de potencia: MQTT+MCP+LLM

  • zhaoyunxing92
  • 本项目是一个钉钉 MCP (Protocolo del conector de mensajes )服务 , 提供了与钉钉企业应用交互的 API 接口。项目基于 Go 语言开发 支持员工信息查询和消息发送等功能。 支持员工信息查询和消息发送等功能。

  • pontusab
  • La comunidad de cursor y windsurf, encontrar reglas y MCP

    Reviews

    1 (1)
    Avatar
    user_2Qcp1tLS
    2025-04-16

    As a loyal user of mcp-ortools, I highly recommend this brilliant tool by Jacck. It seamlessly integrates with various applications and provides exceptional optimization solutions. The comprehensive documentation and active support community enhance its usability. Explore its features at https://github.com/Jacck/mcp-ortools and elevate your projects with mcp-ortools!