Constrained Optimizationのロゴ

Constrained Optimization

コミュニティ
Sharmarajnish

General Purpose MCP Server (AI Agent) for Constrained Optimization

公開者Sharmarajnish
リポジトリMCP-Constrained-Optimization
言語Python
フォーク
2
スター
5
利用可能なツール
0
通信方式stdio
カテゴリ
ライセンスApache-2.0
リンク
  • ツールをAIワークフローに接続

    Constrained Optimizationは、対応するAIクライアントやAIエージェントから利用できるMCP機能を提供します。

  • 0個の利用可能なツール

    呼び出し可能なアクションを以下で確認できます。サーバーから提供されている場合は、名前や説明も表示されます。

  • コピーして使える設定

    セットアップ用の設定例を使って、お好みのMCPクライアントにこのサーバーを設定できます。

  • オープンソースの注目度

    リンク先のリポジトリには5件のスターと2件のフォークがあります。

Constrained Optimization MCP Server

A general-purpose Model Context Protocol (MCP) server for solving combinatorial optimization problems with logical and numerical constraints. This server provides a unified interface to multiple optimization solvers, enabling AI assistants to solve complex optimization problems across various domains.

🚀 Features

  • Unified Interface: Single MCP server for multiple optimization backends
  • AI-Ready: Designed for use with AI assistants through MCP protocol
  • Portfolio Focus: Specialized tools for portfolio optimization and risk management
  • Extensible: Modular design for easy addition of new solvers
  • High Performance: Optimized for large-scale problems
  • Robust: Comprehensive error handling and validation

🛠️ Supported Solvers

  • Z3 - SMT solver for constraint satisfaction problems
  • CVXPY - Convex optimization solver
  • HiGHS - Linear and mixed-integer programming solver
  • OR-Tools - Constraint programming solver

📦 Installation

bash
# Install the package
pip install constrained-opt-mcp

# Or install from source
git clone https://github.com/your-org/constrained-opt-mcp
cd constrained-opt-mcp
pip install -e .

📐 Mathematical Foundations

Optimization Theory

The Constrained Optimization MCP Server implements solutions for various classes of optimization problems:

Linear Programming (LP)

$$\min_{x} c^T x \quad \text{subject to} \quad Ax \leq b, \quad x \geq 0$$

Quadratic Programming (QP)

$$\min_{x} \frac{1}{2}x^T Q x + c^T x \quad \text{subject to} \quad Ax \leq b, \quad x \geq 0$$

Convex Optimization

$$\min_{x} f(x) \quad \text{subject to} \quad g_i(x) \leq 0, \quad h_j(x) = 0$$

Where $f$ and $g_i$ are convex functions.

Constraint Satisfaction Problems (CSP)

Find $x \in \mathcal{D}$ such that $C_1(x) \land C_2(x) \land \ldots \land C_k(x)$

Portfolio Optimization (Markowitz)

$$\max_{w} \mu^T w - \frac{\lambda}{2} w^T \Sigma w \quad \text{subject to} \quad \sum_{i=1}^{n} w_i = 1, \quad w_i \geq 0$$

Where:

  • $w$: portfolio weights
  • $\mu$: expected returns
  • $\Sigma$: covariance matrix
  • $\lambda$: risk aversion parameter

Solver Capabilities

Problem TypeSolverComplexityMathematical Form
Constraint SatisfactionZ3NP-CompleteLogical constraints
Convex OptimizationCVXPYPolynomialConvex functions
Linear ProgrammingHiGHSPolynomialLinear constraints
Constraint ProgrammingOR-ToolsNP-CompleteDiscrete domains

🚀 Quick Start

1. Run Examples

bash
# Run individual examples
python examples/nqueens.py
python examples/knapsack.py
python examples/portfolio_optimization.py
python examples/job_shop_scheduling.py
python examples/nurse_scheduling.py
python examples/economic_production_planning.py

# Run interactive notebook
jupyter notebook examples/constrained_optimization_demo.ipynb

2. Start the MCP Server

bash
constrained-opt-mcp

3. Connect from AI Assistant

Add the server to your MCP configuration:

json
{
  "mcpServers": {
    "constrained-opt-mcp": {
      "command": "constrained-opt-mcp",
      "args": []
    }
  }
}

4. Use the Tools

The server provides the following tools:

  • solve_constraint_satisfaction - Solve logical constraint problems
  • solve_convex_optimization - Solve convex optimization problems
  • solve_linear_programming - Solve linear programming problems
  • solve_constraint_programming - Solve constraint programming problems
  • solve_portfolio_optimization - Solve portfolio optimization problems

📚 Examples

Constraint Satisfaction Problem

python
# Solve a simple arithmetic constraint problem
variables = [
    {"name": "x", "type": "integer"},
    {"name": "y", "type": "integer"},
]
constraints = [
    "x + y == 10",
    "x - y == 2",
]

# Result: x=6, y=4

Portfolio Optimization

python
# Optimize portfolio allocation
assets = ["Stocks", "Bonds", "Real Estate", "Commodities"]
expected_returns = [0.10, 0.03, 0.07, 0.06]
risk_factors = [0.15, 0.03, 0.12, 0.20]
correlation_matrix = [
    [1.0, 0.2, 0.6, 0.3],
    [0.2, 1.0, 0.1, 0.05],
    [0.6, 0.1, 1.0, 0.25],
    [0.3, 0.05, 0.25, 1.0],
]

# Result: Optimal portfolio weights and performance metrics

Linear Programming

python
# Production planning problem
sense = "maximize"
objective_coeffs = [3.0, 2.0]  # Profit per unit
variables = [
    {"name": "product_a", "lb": 0, "ub": None, "type": "cont"},
    {"name": "product_b", "lb": 0, "ub": None, "type": "cont"},
]
constraint_matrix = [
    [2, 1],  # Labor: 2*A + 1*B <= 100
    [1, 2],  # Material: 1*A + 2*B <= 80
]
constraint_senses = ["<=", "<="]
rhs_values = [100.0, 80.0]

# Result: Optimal production quantities

Portfolio Examples

  • Portfolio Optimization - Advanced portfolio optimization strategies including Markowitz, Black-Litterman, and ESG-constrained optimization
  • Risk Management - Risk management strategies including VaR optimization, stress testing, and hedging

Enhanced Portfolio Optimization Features

Equity Portfolio Optimization:

  • Sector diversification constraints (max 25% per sector)
  • Market cap constraints (large, mid, small cap allocations)
  • ESG (Environmental, Social, Governance) constraints
  • Liquidity requirements and individual position limits
  • Risk-return optimization with advanced metrics

Multi-Asset Portfolio Optimization:

  • Asset class constraints (equity, fixed income, alternatives, cash)
  • Regional exposure limits (developed vs emerging markets)
  • Alternative investment constraints (commodities, real estate, private equity)
  • Dynamic rebalancing and risk budgeting
  • Multi-period optimization with transaction costs

Advanced Risk Metrics:

  • Value at Risk (VaR) and Conditional VaR (CVaR)
  • Maximum Drawdown and Tail Risk
  • Factor exposure analysis and risk attribution
  • Stress testing and scenario analysis
  • Correlation and concentration risk management

Comprehensive Examples

🎯 Combinatorial Optimization

  • N-Queens Problem - Classic constraint satisfaction with chessboard visualization
  • Knapsack Problem - 0/1 and multiple knapsack variants with performance analysis

🏭 Scheduling & Operations

📊 Quantitative Economics & Finance

🧮 Interactive Learning

🧪 Testing

Run the comprehensive test suite:

bash
# Run all tests
pytest

# Run specific test categories
pytest tests/test_z3_solver.py
pytest tests/test_cvxpy_solver.py
pytest tests/test_highs_solver.py
pytest tests/test_ortools_solver.py
pytest tests/test_mcp_server.py

# Run with coverage
pytest --cov=constrained_opt_mcp

📖 Documentation

🏗️ Architecture

Core Components

  1. Core Models (constrained_opt_mcp/core/) - Base classes and problem types
  2. Solver Models (constrained_opt_mcp/models/) - Problem-specific model definitions
  3. Solvers (constrained_opt_mcp/solvers/) - Solver implementations
  4. MCP Server (constrained_opt_mcp/server/) - MCP server implementation
  5. Examples (constrained_opt_mcp/examples/) - Usage examples and demos

Supported Problem Types

Problem TypeSolverUse Cases
Constraint SatisfactionZ3Logic puzzles, verification, planning
Convex OptimizationCVXPYPortfolio optimization, machine learning
Linear ProgrammingHiGHSProduction planning, resource allocation
Constraint ProgrammingOR-ToolsScheduling, assignment, routing
Portfolio OptimizationMultipleRisk management, portfolio construction

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Run the test suite
  6. Submit a pull request

📄 License

This project is licensed under the Apache License 2.0. See the LICENSE file for details.

🆘 Support

For questions, issues, or contributions, please:

  1. Check the documentation
  2. Search existing issues
  3. Create a new issue
  4. Join our discussions

📈 Changelog

Version 1.0.0

  • Initial release
  • Support for Z3, CVXPY, HiGHS, and OR-Tools
  • Portfolio optimization examples
  • Comprehensive test suite
  • MCP server implementation

インストール

TypingMind
前提条件:

Node.js 18+

{
  "mcpServers": {
    "constrained-opt-mcp": {
      "command": "constrained-opt-mcp",
      "args": []
    }
  }
}

Constrained OptimizationのMCPを複数のAIモデルで活用

TypingMindはワークスペース単位でMCPツールに接続します。そのため、一度Constrained Optimizationに接続すれば、モデルごとに個別に設定することなく、TypingMind内のさまざまなAIモデルで利用できます。 このMCPは、デバイス上のTypingMind MCPコネクタを通じてローカルで動作します。

ローカルコネクタのセットアップガイド

MCPサーバーが、お使いのコンピューター上のローカルファイル、アプリ、非公開リソースにアクセスする必要がある場合は、この方法を使います。

1

MCP設定を開く

TypingMindで「設定」、「詳細設定」、「MCP」の順に進み、「コネクタを設定」を選択してください。

  1. ブラウザでTypingMindを開いてください。
  2. 設定アイコンをクリックしてください。
  3. 「詳細設定」に移動してください。
  4. 「MCP」セクションを開いてください。
  5. 「コネクタを設定」をクリックし、「このデバイス」を選択してください。
「このデバイス」が選択されたTypingMindのMCPコネクタ設定画面
2

コネクタのコマンドを実行

「このデバイス」を選択し、TypingMindからコマンドをコピーしてターミナルで実行してください。MCPの使用中は、プロセスを実行したままにしてください。

  1. TypingMindに表示されるセットアップコマンドをコピーしてください。
  2. macOSではターミナルを、WindowsではWindows Terminalを開いてください。
  3. コマンドを貼り付けて実行してください。
  4. ターミナルで続行の確認を求められた場合は、パッケージのインストールを承認してください。
  5. MCPツールの使用中は、ターミナルウィンドウを開いたまま、プロセスの実行を継続してください。
3

Constrained Optimizationをサーバーとして追加

コネクタのステータスが「準備完了」になったら、「サーバーを編集」をクリックし、MCPサーバーの設定を貼り付けてください。

  1. コネクタのステータスが「準備完了」になるまでお待ちください。
  2. 「サーバーを編集」をクリックしてください。
  3. Constrained OptimizationのMCPサーバー設定を貼り付けてください。
  4. サーバー一覧を保存してください。
  5. コネクタが引き続き使用可能か確認するには、更新してください。
稼働中のサーバーと「サーバーを編集」ボタンが表示されたTypingMindのMCP設定画面
{
  "mcpServers": {
    "constrained-optimization": {
      "command": "npx",
      "args": [
        "-y",
        "constrained-opt-mcp"
      ]
    }
  }
}
4

複数のモデルで同じ接続を使用

サーバー一覧を保存し、「プラグイン」を開いてConstrained OptimizationのMCPツールを有効にしてください。その後、TypingMindで対応するAIモデルを選択し、チャットでツールを使うか、AIエージェントに割り当ててください。

  1. TypingMindの「プラグイン」ページを開いてください。
  2. Constrained OptimizationのMCPツールを有効にしてください。
  3. チャットを開始し、使用するAIモデルを選択してください。
  4. MCPツールをチャットで使うか、AIエージェントに割り当ててください。
  5. MCPに再接続することなく、必要に応じて別のAIモデルに切り替えられます。
選択したAIモデルと有効なMCPツールを使用したTypingMindのチャット
Constrained Optimizationを使ってこのタスクを手伝ってもらえますか?
Constrained Optimization
はい、読みました。
Constrained Optimizationで調べた結果をお伝えします。

よくある質問

Constrained Optimization MCPサーバーは何に使いますか?

Constrained Optimizationは、対応するAIクライアントを外部ツールやコンテキストに接続するためのMCPサーバーです。TypingMindでは、このMCPサーバーを一度追加するだけで、AIワークスペース内でそのツールを利用できるようになります。

TypingMindでConstrained Optimization MCPを複数のAIモデルと併用できますか?

はい。TypingMindはワークスペース単位でMCPツールに接続するため、モデルごとにMCPサーバーを設定する必要はありません。Claude、ChatGPT、Geminiや、TypingMindで設定したその他のAIモデルでConstrained Optimizationを利用できます。

TypingMindでConstrained Optimization MCPを使うメリットは何ですか?

TypingMindは、複数のAIモデル、プロンプト、プラグイン、AIエージェント、APIキー、MCPツールを1つのワークスペースにまとめられる、LLMチャット向けの優れたフロントエンドです。Constrained Optimizationを接続すると、TypingMindでチャットのワークフローを整理しながら、お好みのモデルでそのMCPツールを利用できます。

Constrained Optimization MCPをTypingMindに接続するにはどうすればよいですか?

Constrained OptimizationはTypingMindのローカルMCPコネクタ経由で動作します。MCPサーバーがコンピューター上のローカルファイル、デスクトップアプリ、コマンドラインツール、プライベートリソースにアクセスする必要がある場合に最適です。

TypingMindでConstrained Optimization MCPのどのようなツールを利用できますか?

Constrained OptimizationはMCP機能を提供しています。TypingMindのプラグインページで有効にすると、チャットで使用したり、AIエージェントに割り当てたりできます。

Constrained Optimization MCPを使うには、APIキーをTypingMindと共有する必要がありますか?

いいえ。TypingMindはローカルファーストの設計で、モデルプロバイダー、APIキー、プロンプト、MCP設定をご自身で管理できます。Constrained Optimizationで認証が必要な場合は、接続の作成時に、そのMCPサーバーに必要なヘッダー、OAuth設定、またはローカル設定を追加してください。

関連するMCPサーバー

すべて見る

今すぐ自分専用のAIワークスペースを作成

ニュースレターに登録すると、新機能や今後のプレゼント企画のお知らせが届きます👇