内容
<p align="center">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/ansys/pymechanical-mcp/main/doc/source/_static/pymechanical-mcp-dark.png">
<source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/ansys/pymechanical-mcp/main/doc/source/_static/pymechanical-mcp-light.png">
<img alt="PyMechanical-MCP" src="https://raw.githubusercontent.com/ansys/pymechanical-mcp/main/doc/source/_static/pymechanical-mcp-light.png" width="900">
</picture>
</p>
[](https://docs.pyansys.com/)
[](https://www.python.org/)
[](https://opensource.org/licenses/Apache-2.0)
PyMechanical-MCP 提供 [模型上下文协议(MCP)](https://modelcontextprotocol.io/) 服务器,使 AI 助手能够通过 [PyMechanical](https://mechanical.docs.pyansys.com/) 与 Ansys Mechanical 进行交互。使用自然语言设置、求解和后处理结构、热和多物理仿真。
## 概述
主要功能:
- 通过启动新实例或连接到现有实例来管理 Mechanical 会话
- 通过 Mechanical API 运行 Mechanical 脚本工作流
- 在持久会话中执行自定义 Python 和 PyMechanical 代码
- 导出结果、捕获屏幕截图和创建自定义图表
- 检索内置的常见 Mechanical 工作流步骤的指导
- 使用本地、远程或容器化的 Mechanical 部署
<!-- 演示视频将在可用时添加 -->
## 工具列表
您可以使用服务器公开的 21 种工具,分为以下几组:
| 组 | 工具 |
|-------|-------|
| 连接和生命周期 | `check_mechanical_status`, `check_mechanical_installed`, `launch_mechanical`, `connect_to_mechanical`, `disconnect_from_mechanical`, `list_mechanical_instances` |
| 文件和项目管理 | `list_files`, `upload_file`, `download_file`, `clear_mechanical`, `save_project`, `open_project` |
| Mechanical 脚本和求解 | `run_python_script`, `solve_analysis`, `get_model_info`, `export_results` |
| 可视化和诊断 | `screenshot`, `create_custom_plot`, `get_mechanical_logs` |
| 持久 Python 执行 | `run_python_code` |
| 工作流指导 | `get_guidelines_for` |
服务器还公开了一个 MCP 资源,`files://mechanical/working_directory`,该资源返回连接的 Mechanical 实例的工作目录。
## 安装
### 对于用户
使用以下命令安装最新版本:
```bash
pip install ansys-mechanical-mcp
```
或使用 [`uvx`](https://docs.astral.sh/uv/) 直接运行而无需安装:
```bash
uvx --index-strategy unsafe-best-match --from git+https://github.com/ansys/pymechanical-mcp ansys-mechanical-mcp
```
### 对于开发者
```bash
git clone https://github.com/ansys/pymechanical-mcp.git
cd pymechanical-mcp
pip install -e ".[dev]"
```
## 使用
有关 VS Code、Claude Code、Claude Desktop 和其他 MCP 兼容客户端的分步设置说明,请参阅文档中的 [IDE 和客户端配置](https://mechanical-mcp.docs.pyansys.com/version/stable/getting_started/ide_configuration.html)。
## 配置
对于本地 MCP 客户端,请使用 STDIO。对于远程访问,请在受信任的网络中使用 HTTP 传输,或在提供身份验证和 TLS 的基础设施后面。
使用默认 STDIO 传输运行:
```bash
ansys-mechanical-mcp
```
使用 HTTP 传输运行:
```bash
ansys-mechanical-mcp --transport http --http-host 127.0.0.1 --http-port 8080
```
常见配置选项:
| 选项 | 描述 |
|--------|-------------|
| `--transport` | MCP 传输类型:`stdio` 或 `http` |
| `--ip`, `--port` | 用于 `connect_on_startup` 或默认值的 Mechanical 连接目标 |
| `--connect-on-startup` | 在 MCP 服务器启动时连接到 Mechanical |
| `--transport-mode` | gRPC 模式:`auto`、`insecure`、`mtls`、`wnua` |
| `--certs-dir` | 包含 mTLS 证书的目录(`ca.crt`、`client.crt`、`client.key`) |
| `--cors-origins` | HTTP 传输的以逗号分隔的允许来源 |
环境变量:
| 变量 | 描述 |
|----------|-------------|
| `PYMECHANICAL_TRANSPORT_MODE` | 当未设置 `--transport-mode` 时,默认的 gRPC 传输模式 |
| `ANSYS_GRPC_CERTIFICATES` | 当未设置 `--certs-dir` 时,默认的证书目录 |
| `PYMECHANICAL_IP`, `PYMECHANICAL_PORT` | 连接和发现工具使用的 Docker 连接默认值 |
## 许可证
该项目根据 Apache 2.0 许可协议许可。有关详细信息,请参见 [LICENSE](./LICENSE) 文件。
## 资源
- [PyMechanical-MCP 文档](https://mechanical-mcp.docs.pyansys.com)
- [PyMechanical 文档](https://mechanical.docs.pyansys.com/)
- [模型上下文协议](https://modelcontextprotocol.io/)
- [仓库问题](https://github.com/ansys/pymechanical-mcp/issues)
- [仓库讨论](https://github.com/ansys/pymechanical-mcp/discussions)