Token导航 LogoToken导航TokenDH.com
z3 MCP logo
搜索检索stdio官方级别未说明来源级核验

z3 MCP

MCP Server

An MCP server for the z3 theorem prover

工具数

0

提示词数

0

GitHub Stars

5

资源数

0
PythonClaude搜索Claude DesktopClaudeCline

安装说明

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

作者 / 组织

javergar

提供方

javergar

最后核验

2026/5/18 03:32

运行时

Python

快速接入

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

命令预览

python -m z3_poc.examples.main

详细介绍

Z3定理的函数规划证明

使用函数式编程原理对Z3定理证明器功能进行弃权的Python实现,通过模型上下文协议(MCP)服务器公开。

概述

该项目演示了如何使用Z3定理证明器和函数式编程方法来解决复杂的约束满足问题,并分析实体之间的关系。它利用了 returns 函数式编程抽象库,并通过MCP服务器公开其功能。

特性

  • 约束满足问题:解决具有变量和约束的复杂问题
  • 关系分析:分析和推断实体之间的关系
  • 函数式编程:使用纯函数、不可变数据结构和一元错误处理
  • MCP服务器:通过标准化接口展示Z3功能

项目结构

z3_mcp/
├── core/                  # Core implementation
│   ├── solver.py          # Constraint satisfaction problem solving
│   └── relationships.py   # Relationship analysis
├── models/                # Data models
│   ├── constraints.py     # Models for constraint problems
│   └── relationships.py   # Models for relationship analysis
├── server/                # MCP server
│   └── main.py            # Server implementation
└── examples/              # Example usage
    └── main.py            # Demonstration of capabilities

技术栈

  • Z3求解器:用于约束求解的Microsoft定理证明器
  • 退货:用于一元运算和错误处理的函数式编程库
  • 派丹蒂克:数据验证和序列化
  • FastMCP:模型上下文协议的实现

安装

此项目使用 uv 用于依赖性管理。

# Clone the repository
git clone https://github.com/javergar/z3_mcp.git
cd z3_mcp

# Install dependencies
uv pip install -e .

# Install development dependencies (optional)
uv pip install -e ".[dev]"

用法

运行示例

该项目包括几个示例,展示了Z3求解器的功能:

# Run the examples
python -m z3_poc.examples.main

示例包括:

  • N皇后问题
  • 家庭关系推断
  • 因果关系时态推理
  • 密码谜题(发送+更多=金钱)

运行MCP服务器

启动MCP服务器,通过模型上下文协议公开Z3功能:

# Run the server
python -m z3_poc.server.main

用Claude/Cline建立MCP服务器

要通过VSCode中的Cline扩展与Claude一起使用Z3求解器MCP服务器,您需要配置 settings.json 文件:

  1. 配置:将以下内容添加到 mcpServers 设置文件中的对象:
"z3-solver": {
  "command": "uv",
  "args": [
    "--directory",
    "/path/to/your/z3_poc",
    "run",
    "z3_poc/server/main.py"
  ],
  "disabled": false,
  "autoApprove": [
    "simple_constraint_solver", 
    "simple_relationship_analyzer", 
    "solve_constraint_problem", 
    "analyze_relationships"
  ]
}
  1. 配置选项:

- command:要运行的命令(使用 uv Python环境管理) - args:命令参数,包括项目路径和服务器脚本 - disabled:设置为 false 启用服务器 - autoApprove:未经明确批准可使用的工具清单

  1. 重启:更新设置后,重新启动VSCode或Claude Desktop应用程序以使更改生效。

配置后,Claude将可以通过MCP服务器访问Z3求解器功能。

MCP工具

服务器提供以下工具:

solve_constraint_problem

使用完整的问题模型解决约束满足问题。

# Example input
{
  "problem": {
    "variables": [
      {"name": "x", "type": "integer"},
      {"name": "y", "type": "integer"}
    ],
    "constraints": [
      {"expression": "x + y == 10"},
      {"expression": "x >= 0"},
      {"expression": "y >= 0"}
    ],
    "description": "Find non-negative values for x and y that sum to 10"
  }
}

analyze_relationships

使用完整的RelationshipQuery模型分析实体之间的关系。

# Example input
{
  "query": {
    "relationships": [
      {"person1": "Alice", "person2": "Bob", "relation": "sibling"},
      {"person1": "Bob", "person2": "Charlie", "relation": "sibling"}
    ],
    "query": "sibling(Alice, Charlie)"
  }
}

simple_constraint_solver

一个更简单的界面,用于解决约束问题,而不需要完整的问题模型。

# Example input
{
  "variables": [
    {"name": "x", "type": "integer"},
    {"name": "y", "type": "integer"}
  ],
  "constraints": [
    "x + y == 10",
    "x <= 5",
    "y <= 5"
  ],
  "description": "Find values for x and y"
}

simple_relationship_analyzer

一个更简单的接口,用于分析关系,而不需要完整的RelationshipQuery模型。

# Example input
{
  "relationships": [
    {"person1": "Bob", "person2": "Hanna", "relation": "sibling"},
    {"person1": "Bob", "person2": "Claudia", "relation": "sibling"}
  ],
  "query": "sibling(Hanna, Claudia)"
}

函数式编程方法

这个项目演示了几个函数式编程原理:

  1. 不可变数据结构:使用Pydantic模型进行不可变数据表示
  2. 结果类型:使用 returns.result.Result 用于无例外的错误处理
  3. 也许类型:使用 returns.maybe.Maybe 用于处理可为null的值
  4. 做记号:使用生成器表达式 Result.do() 用于顺序操作
  5. 模式匹配:使用Python的match case来处理不同的结果类型

do符号示例 analyze_relationships:

expr = (
    RelationshipResult(...)
    for entities in create_entities(query.relationships)
    for relations in create_relations(query.relationships)
    for _ in add_relationship_assertions(solver, query.relationships, entities, relations)
    for query_expr in parse_query(query.query, entities, relations)
    for (result, explanation, is_satisfiable) in evaluate_query(solver, query_expr)
)

return Result.do(expr)

贡献

欢迎投稿!请随时提交拉取请求。

许可证

此项目根据MIT许可证获得许可-有关详细信息,请参阅许可证文件。

目录标签

目录标签

PythonClaude搜索research-and-datamathgptmath-solvermath-assistant定理证明本地部署约束求解关系推理函数式编程MCP协议

支持客户端

Claude DesktopClaudeCline

接入字段

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

stdio

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

none

运行时(runtime,运行环境)

Python

工具数量(toolCount,工具数)

0

资源数量(resourceCount,资源数)

0

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

0

权限和风险

stdionone部署方式未说明

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

安装前确认

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

来源信息

继续浏览同类 MCP