MathCAD MCP服务器
一个模型上下文协议(MCP)服务器,提供与PTC MathCAD Prime的集成,允许像Claude这样的人工智能助手通过标准化的界面与MathCAD工作表进行交互。
特性
- 工作表管理:打开、关闭和保存MathCAD工作表
- 输入控制:设置数值、字符串和带单位的矩阵
- 输出访问:使用适当的单位检索计算结果
- 计算管理:暂停、恢复和重新计算工作表
- 导出选项:将工作表另存为PDF、RTF和XPS文件
需求
- Windows操作系统(MathCAD COM自动化所需)
- Python 3.10或更高版本
- 已安装PTC MathCAD Prime 3.0或更高版本
- 依赖关系:MathcadPy、pywin32和MCP Python SDK(请参阅requirements.txt)
安装
使用Claude Desktop快速安装
- 安装所需的依赖项:
pip install -r requirements.txt- 运行安装脚本:
python install_standalone.py选项:
- 使用 --hide 运行时隐藏MathCAD窗口的标志: python install_standalone.py --hide
- 重新启动Claude Desktop以使更改生效。
手动配置
在以下位置编辑您的Claude Desktop配置文件 ~/Library/Application Support/Claude/claude_desktop_config.json (Mac)或 %APPDATA%\Claude\claude_desktop_config.json (Windows):
{
"mcpServers": {
"mathcad": {
"command": "python",
"args": [
"path/to/mathcad-mcp/standalone.py"
],
"env": {
"MATHCAD_VISIBLE": "true"
}
}
}
}用法
工具
服务器公开了以下MCP工具:
list_mathcad_version:获取正在运行的MathCAD版本open_worksheet:从文件路径打开MathCAD工作表close_worksheet:关闭特定工作表close_all_worksheets:关闭所有打开的工作表quit_mathcad:完全退出MathCAD应用程序save_worksheet:将工作表保存到指定的路径和格式save_worksheet_inplace:将工作表保存到位activate_worksheet:将工作表放在前面set_real_input:使用可选单位设置数字输入set_string_input:设置字符串输入set_matrix_input:使用可选单位设置矩阵输入get_input:检索指定输入的当前值(实数/字符串/矩阵)get_matrix_input:检索指定矩阵输入的当前值calculate_worksheet:重新计算工作表sync_worksheet:用于计算工作表的别名pause_calculation:暂停工作表计算resume_calculation:恢复工作表计算get_output:获取指定的输出值(实数、字符串或矩阵)get_real_output:从工作表中获取数值输出值get_real_output_with_units:获取转换为指定单位的数值输出值get_matrix_output:从工作表中获取矩阵输出get_matrix_output_with_units:通过单位转换获得矩阵输出save_as_pdf:将工作表另存为PDF文件(仅限Mathcad Prime 5+)save_as_rtf:将工作表另存为RTF文件save_as_xps:将工作表另存为XPS文件is_worksheet_readonly:检查工作表是否为只读is_worksheet_modified:检查工作表是否有未保存的更改set_worksheet_modified:强制设置工作表的“已修改”状态
资源
服务器公开以下MCP资源:
mathcad://worksheets:列出所有打开的工作表mathcad://worksheets/paths:列出具有完整文件路径的工作表mathcad://worksheet/{worksheet_name}/inputs:在工作表中列出输入mathcad://worksheet/{worksheet_name}/outputs:在工作表中列出输出mathcad://worksheet/{worksheet_name}/output/{output_name}:获取特定的输出值mathcad://worksheet/{worksheet_name}/output/{output_name}/matrix:获取矩阵输出mathcad://worksheet/{worksheet_name}/output/{output_name}/with_units/{units}:通过单位转换获得输出mathcad://worksheet/{worksheet_name}/info:获取有关工作表的信息mathcad://worksheet/{worksheet_name}/status:获取工作表的状态
提示模板
服务器提供以下提示模板以协助MathCAD相关任务:
solve_equation:求解数学方程的模板plot_function:绘图函数模板analyze_engineering_problem:工程问题分析模板unit_conversion:单位转换任务模板create_worksheet_template:用于创建新工作表模板的模板
示例工作流
示例1:解决一个物理问题
1. Open an existing MathCAD worksheet:
"Can you open my physics worksheet at C:\Users\username\Documents\Physics\projectile_motion.mcdx?"
2. Set input parameters:
"Set the initial velocity to 50 m/s and the launch angle to 30 degrees."
3. Calculate the results:
"Now calculate the trajectory and show me the maximum height and distance."
4. Extract output values:
"What's the maximum height reached by the projectile?"示例2:工程分析
1. Open or create a worksheet for analysis:
"I need to analyze a beam deflection problem. Can you open the structural_analysis.mcdx worksheet?"
2. Configure the worksheet:
"Set the load P to 5000 N, beam length L to 2 m, Young's modulus E to 200 GPa, and moment of inertia I to 4×10⁻⁶ m⁴."
3. Run the calculation:
"Calculate the worksheet and tell me the maximum deflection."
4. Export the results:
"Save the worksheet as a PDF so I can include it in my report."环境变量
MATHCAD_VISIBLE:设置为“true”显示MathCAD应用程序窗口(默认),或设置为“false”隐藏它。
建筑
服务器是使用MCP Python SDK的FastMCP框架构建的。主要组件是:
standalone.py:具有MathCAD集成的自包含服务器脚本install_standalone.py:在Claude Desktop中安装服务器的实用程序脚本
故障排除
常见问题
COM自动化错误
如果遇到COM自动化错误:
- 确保MathCAD已安装并获得适当许可
- 检查您是否在Windows上运行
- 尝试重新启动MathCAD和MCP服务器
未找到工作表
如果找不到工作表:
- 使用绝对路径,而不是相对路径
- 确保文件路径已正确转义
- 验证文件是否存在以及是否有效
.mcdx文件
单位转换问题
如果单位转换失败:
- 检查单位之间的兼容性(例如,长度不能转换为质量)
- 确保使用正确的单位符号(例如,“m”表示米)
- 尝试使用标准单位格式(例如,“m/s”而不是“m\*s^(-1)”)
许可证
此项目根据MIT许可证获得许可-有关详细信息,请参阅许可证文件。

