Z3/SMT MCP Server
Enables constraint solving, logical reasoning, and satisfiability checking using the Z3 theorem prover via natural language.
README
Z3/SMT MCP Server
An MCP (Model Context Protocol) server that exposes Z3/SMT solver capabilities for constraint solving, logical reasoning, and satisfiability checking.
Features
- Direct Z3 Python code execution - Run arbitrary Z3 Python code
- SMT-LIB 2.0 support - Parse and solve SMT-LIB format problems
- Constraint checking - Check satisfiability of constraint lists
- Theorem proving - Prove theorems by showing unsatisfiability of negation
- Expression simplification - Simplify Z3 expressions
- Logic program solving - Parse and solve structured logic programs (Logic-LLM format)
- Session management - Incremental solving with push/pop support
Installation
# Using pip
pip install z3smt-mcp
# Or install from source
git clone https://github.com/z3smt-mcp/z3smt-mcp
cd z3smt-mcp
pip install -e .
Requirements
- Python >= 3.10
- z3-solver >= 4.12.0
- mcp >= 1.0.0
Usage
Running the Server
# Run directly
z3smt-mcp
# Or via Python
python -m z3smt_mcp.server
Claude Desktop Configuration
Add to your Claude Desktop config (claude_desktop_config.json):
{
"mcpServers": {
"z3smt": {
"command": "z3smt-mcp"
}
}
}
Or if installed from source:
{
"mcpServers": {
"z3smt": {
"command": "python",
"args": ["-m", "z3smt_mcp.server"]
}
}
}
Available Tools
solve
Execute Z3 Python code directly. All Z3 imports are pre-loaded.
# Example: Solve a system of linear equations
x = Int('x')
y = Int('y')
solver = Solver()
solver.add(x + y == 10)
solver.add(x - y == 4)
if solver.check() == sat:
print(solver.model())
# Output: [y = 3, x = 7]
solve_smtlib
Solve problems in SMT-LIB 2.0 format.
(declare-const x Int)
(declare-const y Int)
(assert (= (+ x y) 10))
(assert (= (- x y) 4))
(check-sat)
(get-model)
check_sat
Check satisfiability of a list of constraints with automatic variable detection.
{
"constraints": ["x + y == 10", "x > 0", "y > 0", "x < y"]
}
prove
Prove a theorem by showing its negation is unsatisfiable.
{
"theorem": "Implies(And(x > 0, y > 0), x + y > 0)",
"variables": {"x": "int", "y": "int"}
}
simplify
Simplify a Z3 expression.
{
"expression": "And(x > 0, Or(x > 0, y > 0))"
}
solve_logic_program
Solve structured logic programs in Logic-LLM format.
# Declarations
Color = EnumSort([red, green, blue])
assign = Function(Object -> Color)
# Constraints
assign(obj1) != assign(obj2)
Distinct([c:Color], assign(c))
Session Management Tools
session_add_variable- Add a variable to the sessionsession_add_constraint- Add a constraint to the sessionsession_check- Check satisfiability and get modelsession_push- Push a new context (for backtracking)session_pop- Pop context (backtrack)session_reset- Clear the sessionlist_sessions- List all active sessions
Examples
Solving Sudoku
# Create a 9x9 grid of integer variables
X = [[Int(f"x_{i}_{j}") for j in range(9)] for i in range(9)]
solver = Solver()
# Each cell contains a value in 1-9
for i in range(9):
for j in range(9):
solver.add(And(X[i][j] >= 1, X[i][j] <= 9))
# Each row has distinct values
for i in range(9):
solver.add(Distinct(X[i]))
# Each column has distinct values
for j in range(9):
solver.add(Distinct([X[i][j] for i in range(9)]))
# Each 3x3 box has distinct values
for box_i in range(3):
for box_j in range(3):
box = [X[3*box_i + i][3*box_j + j]
for i in range(3) for j in range(3)]
solver.add(Distinct(box))
# Add known values (example)
solver.add(X[0][0] == 5)
solver.add(X[0][1] == 3)
# ... more constraints
if solver.check() == sat:
m = solver.model()
for i in range(9):
print([m[X[i][j]] for j in range(9)])
Bit-Vector Arithmetic
# Solve for x where x * 3 == 21 in 8-bit arithmetic
x = BitVec('x', 8)
solver = Solver()
solver.add(x * 3 == 21)
if solver.check() == sat:
print(solver.model())
Array Theory
# Find an array where a[0] + a[1] == 10
a = Array('a', IntSort(), IntSort())
solver = Solver()
solver.add(a[0] + a[1] == 10)
solver.add(a[0] > 0)
solver.add(a[1] > 0)
if solver.check() == sat:
print(solver.model())
Credits
- Z3 solver implementation adapted from Logic-LLM
- MCP interface inspired by clingo-mcp
- Z3 Theorem Prover by Microsoft Research
License
MIT License
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。