Token导航 LogoToken导航TokenDH.com
USolver MCP logo
金融服务stdio官方级别未说明来源级核验

USolver MCP

MCP Server

USolver是一个模型上下文协议服务器,提供解决组合、凸、整数和非线性优化问题的工具,支持多种求解器接口,适用于化学工程、金融投资组合优化、物流调度等多种场景。

工具数

0

提示词数

0

GitHub Stars

65

资源数

0
PythonClaude金融数据Claude DesktopClaudeCursor

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

sdiehl

提供方

sdiehl

最后核验

2026/5/17 20:21

运行时

Python

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

命令预览

uv run install.py

详细介绍

USolver

一个模型上下文协议服务器,提供用于解决组合、凸、整数规划和非线性优化问题的工具。将接口暴露给以下求解器:

  • highs -线性和混合整数规划求解器
  • ortools -组合优化求解器
  • cvxpy -凸优化求解器
  • z3 -布尔值、整数、实数和字符串上的SMT求解器

要安装,请运行 install.py 脚本。这将为Claude Desktop和/或Cursor安装MPC服务器。

uv run install.py

然后打开Claude或Cursor,您应该会看到MCP工具 usolver 可在工具列表中找到。

例子

要运行各个求解器示例,可以调用各个示例模块。每个模块都包含一个docstring,可用于提示语言模型解决问题。

  • 化学工程 -使用Z3 SMT求解器对具有流量连续性、压降和经济约束的流体输送系统进行管道设计优化
  • 链式求解器 -结合OR Tools用于餐桌布局和CVXPY用于员工调度的多阶段餐厅优化
  • 作业车间调度 -使用OR工具最小化完工时间,同时尊重操作优先级和机器容量的复杂调度问题
  • 物流 -使用HiGHS优化运输网络,以最大限度地降低多阶段供应链中的运输成本
  • 护士排班 -使用OR工具安排医院工作人员,在公平和可用性限制的情况下分配护士轮班
  • 投资组合理论 -使用CVXPY进行现代投资组合优化,以最大限度地提高回报,同时限制各资产类别的风险
  • 生产计划 -使用HiGHS进行制造优化,在机器、劳动力和材料限制的情况下实现利润最大化
  • 资源分配 -使用HiGHS混合整数规划进行项目组合选择,以在预算和资源限制内实现价值最大化
  • 网络流量 -使用HiGHS线性规划的最短路径优化,通过具有流守恒约束的有向图找到最小成本路线
  • 硬币问题 -使用Z3的经典逻辑谜题,找出哪6枚美国硬币总计1.15美元,但不能兑换各种面额
  • 密码算法 -使用Z3约束编程解决像SEND+MORE=MONEY这样的密码算术难题
  • 背包问题 -使用OR工具进行经典0/1背包优化,以在重量限制内实现价值最大化
  • 多线性优化 -使用Z3最小化受线性不等式约束的目标函数的混合约束线性规划
  • N皇后区 -使用OR Tools约束编程在N×N棋盘上放置N个皇后,没有攻击位置
  • 稀疏矩阵求解器 -大规模优化演示稀疏矩阵格式,以实现跨设施和时间段的内存高效资源分配

逻辑谜题

You and a friend pass by a standard coin operated vending machine and you decide to get a candy bar.
The price is US $0.95, but after checking your pockets you only have a dollar (US $1) and the machine
only takes coins. You turn to your friend and have this conversation:

You: Hey, do you have change for a dollar?
Friend: Let's see. I have 6 US coins but, although they add up to a US $1.15, I can't break a dollar.
You: Huh? Can you make change for half a dollar?
Friend: No.
You: How about a quarter?
Friend: Nope, and before you ask I cant make change for a dime or nickel either.
You: Really? and these six coins are all US government coins currently in production?
Friend: Yes.
You: Well can you just put your coins into the vending machine and buy me a candy bar, and I'll pay you back?
Friend: Sorry, I would like to but I can't with the coins I have.

What coins are your friend holding?

这可以输入到usolver中,它将生成一个约束系统:

$C$是六个未知硬币值的集合,从$C_1$到$C_6$,每个值都必须是表示美分的正整数。

$$ C=C_1、C_2、C_3、C_4、C_5、C_6、\\quad\\text{其中每个C_i\\in\\mathbb{Z}^+ $$

$\\mathcal{S}$是您可以从六个硬币中选择两个或多个硬币的所有可能方式的集合。

$$ \\matcal{S}={S\\mid-S\\subteq C\\land|S|\\ge 2\\} $$

将50美分硬币排除在自动售货机之外。

$$ v(x)=\\begin{cases}0&\\text{if}x=50\\\\x&\\text{if}x\\neq 50\\end{cases} $$

约束0:所有六个硬币的价值之和为115美分。

$$ \\sum\_{i=1}^{6}c_i=115 $$

限制1:不能兑换一美元。

$$ \\对于所有S\\in\\mathcal{S},\\quad\\sum\_{x\\in S}x\\neq 100 $$

限制2:不能兑换半美元。

$$ \\对于所有S\\in\\mathcal{S},\\quad\\sum\_{x\\in S}x\\neq 50 $$

限制3:一个季度内不能更改。

$$ \\对于所有S\\in\\mathcal{S},\\quad\\sum\_{x\\in S}x\\neq 25 $$

约束4:一分钱也不能兑换。

$$ \\对于所有S\\in\\mathcal{S},\\quad\\sum\_{x\\in S}x\\neq 10 $$

约束5:不能兑换镍币

$$ \\对于所有S\\in\\mathcal{S},\\quad\\sum\_{x\\in S}x\\neq 5 $$

限制6:如果不包括半美元,就不能以95美分的价格买到糖果。

$$ \\对于所有S\\in\\mathcal{S},\\quad\\sum\_{x\\in S}v(x)\\neq 95 $$

如果将此输入求解器,它将合成上述约束系统,用Z3求解,并返回解。

Your friend has: 1 half dollar, 1 quarter, and 4 dimes
This totals 50¢ + 25¢ + 40¢ = 115¢ = $1.15 ✓
This is exactly 6 coins ✓

现代投资组合理论

一个金融例子:

Objective: Maximize expected portfolio return
Constraints:

Bonds allocation cannot exceed 40%
Stocks allocation cannot exceed 60%
Real Estate allocation cannot exceed 30%
Commodities allocation cannot exceed 20%
All allocations must be non-negative
Total allocation must equal exactly 100%
Total weighted portfolio risk cannot exceed 10%

Given Data:

Expected returns: Bonds 8%, Stocks 12%, Real Estate 10%, Commodities 15%
Risk factors: Bonds 2%, Stocks 15%, Real Estate 8%, Commodities 20%

这是由langauge模型编译成一个凸优化问题,可以是cvxopt。

$$ \\开始{align} \\文本{maximization}\\quad&0.08x1+0.12x2+0.10x3+0.15x4\\ \\文本{受制于}\\quad&x_1+x_2+x_3+x_4=1\\ &x_1\\leq 0.4\\ &x_2\\leq 0.6\\ &x_3\\leq 0.3\\ &x_4\\leq 0.2\\ &0.02x_1+0.15x_2+0.08x_3+0.20x_4\\leq 0.10\\ &x_1,x_2,x_3,x_4\\geq 0 \\结束{align} $$

哪里:

  • $x_1$=债券分配
  • $x_2$=股票分配
  • $x_3$=房地产分配
  • $x_4$=商品分配

答案是:

Bonds: 30.0%
Stocks: 20.0%
Real Estate: 30.0% (at maximum allowed)
Commodities: 20.0% (at maximum allowed)
Maximum Expected Return: 10.8% annually

Z3

一个化学工程的例子:

Use usolver to design a water transport pipeline with the following requirements:

* Volumetric flow rate: 0.05 m³/s
* Pipe length: 100 m
* Water density: 1000 kg/m³
* Maximum allowable pressure drop: 50 kPa
* Flow continuity: Q = π(D/2)² × v
* Pressure drop: ΔP = f(L/D)(ρv²/2), where f ≈ 0.02 for turbulent flow
* Practical limits: 0.05 ≤ D ≤ 0.5 m, 0.5 ≤ v ≤ 8 m/s
* Pressure constraint: ΔP ≤ 50,000 Pa
* Find: optimal pipe diameter and flow velocity

线性规划

多线性优化示例:

Use usolver to solve the following linear programming problem:

Minimize: 12x + 20y
Subject to: 6x + 8y ≥ 100
           7x + 12y ≥ 120
           x ≥ 0
           y ∈ [0, 3]

这是由语言模型编译成的约束满足问题,可以用Z3解决。

$$ \\开始{对齐} \\文本{最小化}\\四边形&12x+20y\\ \\文本{主题}\\quad&6x+8y\\geq 100\\ &7x+12y\\geq 120\\ &x\\geq 0\\ &y\\in\[0,3\] \\结束{对齐} $$

哪里:

  • $x$=第一个决策变量(连续,非负)
  • $y$=第二个决策变量(连续,有界)

最佳解决方案是:

x = 15.0
y = 1.25
Objective value = 205.0

CVXPY

一个最小化线性系统2-范数的简单凸优化问题:

Use usolver to solve the following convex optimization problem:

Minimize: ||Ax - b||₂²
Subject to: 0 ≤ x ≤ 1
where 
  A = [1.0, -0.5; 0.5, 2.0; 0.0, 1.0] 
  b = [2.0, 1.0, -1.0]

OR工具

一个典型的工人轮班调度问题:

Use usolver to solve a nurse scheduling problem with the following requirements:

* Schedule 4 nurses (Alice, Bob, Charlie, Diana) across 3 shifts over (Monday, Tuesday, Wednesday)
* Shifts: Morning (7AM-3PM), Evening (3PM-11PM), Night (11PM-7AM)
* Each shift must be assigned to exactly one nurse each day
* Each nurse works at most one shift per day
* Distribute shifts evenly (2-3 shifts per nurse over the period)
* Charlie can't work on Tuesday.

链式示例

一个链式示例,使用OR工具优化表格布局,使用CVXPY优化员工调度。

Use usolver to optimize a restaurant's layout and staffing with the following requirements in two parts. Use combinatorial optimization to optimize for table layout and convex optimization to optimize for staff scheduling.

* Part 1: Optimize table layout
  - Mix of 2-seater, 4-seater, and 6-seater tables
  - Maximum floor space: 150 m²
  - Space requirements: 4m² (2-seater), 6m² (4-seater), 9m² (6-seater)
  - Maximum 20 tables total
  - Minimum mix: 2× 2-seaters, 3× 4-seaters, 1× 6-seater
  - Objective: Maximize total seating capacity

* Part 2: Optimize staff scheduling using Part 1's capacity
  - 12-hour operating day
  - Each staff member can handle 20 seats
  - Minimum 2 staff per hour
  - Maximum staff change between hours: 2 people
  - Variable demand: 40%-100% of capacity
  - Objective: Minimize labor cost ($25/hour per staff)

Docker使用

还可以直接从GitHub容器注册表运行MCP服务器。

docker run -p 8081:8081 ghcr.io/sdiehl/usolver:latest

然后将以下内容添加到您的客户端:

{
  "mcpServers": {
    "sympy-mcp": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "-p",
        "8081:8081",
        "--rm",
        "ghcr.io/sdiehl/usolver:latest"
      ]
    }
  }
}

许可证

根据Apache许可证2.0发布。请参阅 许可证 文件以获取详细信息。

目录标签

目录标签

PythonClaude金融数据优化求解本地部署数学建模运筹学工业工程金融分析

支持客户端

Claude DesktopClaudeCursor

接入字段

传输方式(transport,传输协议)

stdio

鉴权方式(authType,认证方式)

none

运行时(runtime,运行环境)

Python

工具数量(toolCount,工具数)

0

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

stdionone部署方式未说明

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

来源信息

继续浏览同类 MCP