使用说明
MathCAD MCP服务器
一个模型上下文协议(MCP)服务器,提供与PTC MathCAD Prime的集成,使像Claude这样的AI助手能够通过标准化接口与MathCAD工作表进行交互。
功能
- 工作表管理打开、关闭和保存MathCAD工作表
- 输入控制设置带有单位的数值、字符串和矩阵
- 输出访问获取带有适当单位的计算结果
- 计算管理暂停、继续和重新计算工作表
- 导出选项将工作表保存为PDF、RTF和XPS文件
要求
- Windows操作系统(MathCAD COM自动化所需)
- Python 3.10或更高版本
- 已安装PTC MathCAD Prime 3.0或更高版本
- 依赖项:MathcadPy、pywin32 和 MCP Python SDK(见 requirements.txt)
安装
使用Claude桌面版快速安装
-
安装所需的依赖项:
pip install -r requirements.txt -
运行安装脚本:
python install_standalone.py选项:
- 使用
--hide运行时隐藏MathCAD窗口的标志:python install_standalone.py --hide
- 使用
-
重启Claude桌面版以使更改生效。
手动配置
编辑您的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许可协议-详情请参阅LICENSE文件。
