Wolfram 语言 MCP 服务器
一个模型上下文协议(MCP)服务器,通过Wolfram语言/Mathematica集成提供强大的数学计算能力。该服务器采用FastMCP构建,以实现与Claude Desktop的无缝集成。
特点/功能
- 数学计算 - 评估复杂表达式
- 方程求解 - 解代数方程和微分方程
- 微积分运算 - 积分和微分
- 矩阵运算 - 线性代数计算
- 统计分析 - 统计指标与数据分析
- 符号数学 - 简化、因式分解和展开表达式
- 任意代码执行 - 执行任何Wolfram语言代码
- 数据可视化工作流程 - 使用Wolfram生成数据,使用React/Python进行可视化
先决条件
- Python 3.10及以上版本
- Wolfram Mathematica 14.0+ 或 Wolfram 引擎(开发者可免费使用)
- Claude Desktop(可译为“克劳德桌面版”或根据具体语境简化为“克劳德桌面”)
安装
1. 安装Wolfram Mathematica或Wolfram引擎
选项A:Wolfram Mathematica (商业)
- 从……下载 沃尔夫拉姆研究公司
选项B:Wolfram引擎 (开发者免费)
- 从……下载 Wolfram Engine(沃尔夫拉姆引擎)
- 需要免费激活许可证
2. 安装MCP服务器
# Clone the repository
git clone https://github.com/paraporoco/Wolfram-MCP.git
cd Wolfram-MCP
# Create virtual environment
python -m venv venv
# Activate virtual environment
# On Windows:
venv\Scripts\activate
# On macOS/Linux:
source venv/bin/activate
# Install dependencies
pip install -r requirements.txt3. 配置Claude桌面版
在您的Claude Desktop配置文件中添加:
Windows: %APPDATA%\Claude\claude_desktop_config.json\ macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
{
"mcpServers": {
"wolfram": {
"command": "C:\\Users\\YOUR_USERNAME\\Projects\\Wolfram-MCP\\venv\\Scripts\\python.exe",
"args": [
"C:\\Users\\YOUR_USERNAME\\Projects\\Wolfram-MCP\\wolfram_mcp_server.py"
]
}
}
}注: 根据您的安装位置调整路径。
4. 验证安装
重启Claude桌面应用并询问:
Can you test the Wolfram connection?克劳德应该使用 wolfram_test_connection 工具并报告成功。
可用工具
| 工具 | 描述 | 示例 |
|---|---|---|
wolfram_calculate | 评估数学表达式 | 2 + 2, Integrate[x^2, x] |
wolfram_solve | 解方程 | 解决 x^2 - 5x + 6 == 0 for x |
wolfram_integrate | 计算积分 | 积分 x^2 关于;就……而言 x |
wolfram_differentiate | 计算导数 | 求导 x^3 + 2x^2 + x |
wolfram_simplify | 简化表达式 | 简化 (x^2 - 1)/(x - 1) |
wolfram_factor | 因式分解表达式 | 因式分解 x^2 - 5x + 6 |
wolfram_expand | 展开表达式 | 展开 (x + 1)^3 |
wolfram_matrix_operations | 矩阵计算 | 的逆矩阵 {{1,2},{3,4}} |
wolfram_statistics | 统计分析 | 平均值为 {1, 2, 3, 4, 5} |
wolfram_execute | 执行任意Wolfram代码 | Table[Prime[n], {n, 1, 10}] |
wolfram_test_connection | 测试Wolfram连接 | 验证设置 |
可视化工作流程
Wolfram MCP在数学计算方面表现出色,但它返回的是符号表示而非渲染图像。若需视觉图表和图像,请使用混合工作流程:
Wolfram(计算)→ 数据提取 → 可视化工具(渲染)
📖 书籍 完整的可视化指南 - 关于创建美观、交互式图表的全面文档
快速示例
- 使用Wolfram生成数据:
Table[{x, Sin[x], Cos[x]}, {x, 0, 2*Pi, 0.1}]- 使用React或Python进行可视化:
- 见
examples/trig_visualization.jsx用于交互式React图表 - 见
examples/trig_plot.py用于出版质量的 matplotlib 图表
📁 代表文件夹的符号,可译为“文件夹”或“文件夹图标”。 查看所有示例 - 完整的工作示例,附带代码
______________________________________________________________________
使用示例
基础数学
What is the integral of x^2?
Solve the equation x^2 - 5x + 6 = 0高等微积分
Find the derivative of sin(x) * cos(x)
Compute the definite integral of x^2 from 0 to 1线性代数
Calculate the inverse of the matrix {{1,2},{3,4}}
Find the eigenvalues of {{4,1},{2,3}}统计学(或“统计数据”)
What is the mean of the dataset {1, 2, 3, 4, 5}?
Calculate the standard deviation of {10, 20, 30, 40, 50}符号数学
Simplify (x^2 - 1)/(x - 1)
Factor x^2 - 5x + 6
Expand (x + 1)^3配置
服务器默认使用以下路径的 WolframScript:
C:\Program Files\Wolfram Research\Mathematica\14.0\wolframscript.exe要使用不同的版本或位置,请修改路径中的 wolfram_mcp_server.py:
WOLFRAM_SCRIPT_PATH = r"C:\Your\Custom\Path\wolframscript.exe"
MATH_KERNEL_PATH = r"C:\Your\Custom\Path\MathKernel.exe"故障排除
“未找到Wolfram语言”
- 验证是否已安装Mathematica/Wolfram引擎
- 检查路径中的
wolfram_mcp_server.py与您的安装相匹配 - 确保Wolfram引擎已激活(运行
wolframscript(在终端中)
“连接测试失败”
- 确保您的Mathematica许可证处于激活状态
- 试着跑步
wolframscript -code "2+2"在你的终端中 - 检查可执行文件路径是否正确
“执行超时”
- 复杂的计算可能需要更多时间
- 使用
wolfram_execute带有自定义超时参数 - 考虑简化这个表达式
发展
项目结构
Wolfram-MCP/
├── wolfram_mcp_server.py # Main server implementation
├── requirements.txt # Python dependencies
├── README.md # Documentation
├── LICENSE # MIT License
└── venv/ # Virtual environment (not in git)运行测试
# Test the connection directly
python wolfram_mcp_server.py
# Use with Claude Desktop to test all tools做出贡献
欢迎投稿!请:
- 克隆该仓库
- 创建一个特性分支(
git checkout -b feature/amazing-feature) - 提交你的更改(
git commit -m 'Add amazing feature') - 推送到分支(
git push origin feature/amazing-feature) - 打开一个拉取请求
许可证
MIT 许可证 - 详见 许可证 文件中包含详细信息
致谢
- 使用……构建 FastMCP 由马文(Marvin)所著/创作
- 由……提供支持/驱动 Wolfram 语言
- 设计用于 Claude Desktop(可译为“Claude桌面版”或根据上下文简化为“Claude桌面”)
链接
支持
对于问题和疑问:
- 在GitHub上提交一个议题
- 检查现有问题以寻找解决方案
- 请参阅Wolfram语言文档以获取语法帮助
______________________________________________________________________
为Claude + Wolfram社区用心打造
