使用说明
mcp gennx
域驱动的MCP服务器,通过模型上下文协议公开GEN NX结构工程REST API。
特征
- 动态工具生成 --工具在启动时从JSON模式文件生成。无代码生成步骤;在端点映射中添加一个模式文件加一行,工具就会出现。
- 域驱动的子服务器 --5个子服务器(建模、边界、负载、分析、项目)按结构工程领域组织工具。
- 数据驱动路由 --端点→子服务器/工具集/层映射和工具集预设以打包的JSON形式存在(
data/endpoint_subserver_map.json,data/toolset_definitions.json),工具加载的唯一真实来源——Python中没有硬编码的路由字典。 - 工具集筛选 --控制通过环境变量公开哪些工具:87个工具(默认)、161个工具(全部)或仅GET(只读模式)。
- 架构源描述 --工具描述、GUI功能名称和菜单路径从JSON模式文件(单一真实来源)中读取。长篇GUI使用指南作为MCP资源延迟提供(
gennx://feature/{slug})与其内联,不如保持工具列表紧凑。
建筑
Claude / GPT / Cursor
│ MCP Protocol (stdio)
▼
Main FastMCP ("gennx")
├── modeling (9 endpoints · nodes, elements, materials, sections …)
├── boundary (8 endpoints · constraints, springs, rigid links …)
├── loads (15 endpoints · load cases, nodal/beam loads, LCOM 6 sub-types …)
├── analysis (6 endpoints · eigenvalue, buckling, pushover …)
└── project (9 endpoints · open/save/close, analysis run, view capture …)
│ tool call
▼
GennxApiClient (httpx async) ──▶ GEN NX REST API (localhost:8080)
+ resource gennx://feature/{slug} ──▶ SchemaRegistry (in-memory, no GEN NX call)
动态工具管道
schemas/raw/*.json
→ SchemaRegistry (load & merge 66 schema files → 47 endpoints)
→ ToolFactory (generate closure per method)
→ FunctionTool (name, description, JSON Schema params, annotations)
→ FastMCP.add_tool()
每个端点最多生成4个工具——每个HTTP方法一个:
| 方法 | 工具前缀 | 示例 | 行为 |
|---|---|---|---|
| 职位 | post_ |
post_db_node |
创建记录 |
| 得到 | get_ |
get_db_node |
读取所有记录 |
| PUT | put_ |
put_db_node |
更新记录 |
| 删除 | delete_ |
delete_db_node |
按ID删除列表 |
工具描述组成
工具描述由每个模式文件中的字段组成,而不是硬编码。每个模式可以携带:
| 字段 | 用于 |
|---|---|
description |
每个工具描述中的功能摘要 |
feature_name |
GUI功能名称,附加到POST/PUT描述后为 (GUI: "…") |
menu_path |
GUI菜单路径,附加到POST/PUT描述后为 Menu: … |
usage |
长篇GUI使用指南-- 不 内联;通过功能资源提供服务 |
功能文档资源
为了保持始终加载的工具列表紧凑,长表单 usage 指南作为MCP资源按需公开,而不是内联到描述中:
gennx://feature/{slug} # slug = endpoint with "/" and "-" → "_", lowercased
# e.g. gennx://feature/db_node, gennx://feature/doc_new
POST/PUT工具说明,其使用指南以 Docs: gennx://feature/<slug> 指针。LLM仅在需要完整指南时才获取该资源,因此每个端点的使用文本(每个约1.5 KB)不在工具列表中。参数模式和截断示例在每个工具的输入模式中保持内联,因为它们是构造有效调用所必需的。
快速开始
1.安装
pip install -e .
2.配置
复制 .env.example 到 .env 并设置所需的环境变量:
cp .env.example .env
编辑 .env:
# GEN NX REST API base URL (required)
GENNX_API_BASE_URL=https://moa-engineers.midasit.com:443/gen
# MAPI key for GEN NX authentication (required for MIDAS cloud API)
GENNX_MAPI_KEY=your-mapi-key-here
MAPI密钥:从MIDAS用户门户发布。服务器将其作为
MAPI-Key对GEN NX REST API的每个请求的HTTP头。仅当目标是不需要身份验证的本地GEN NX实例时,才保留为空。
3.用克劳德代码注册
通过以下方式传递环境变量 -e 标记,以便生成的MCP进程继承它们:
claude mcp add gennx \
-e GENNX_API_BASE_URL=https://moa-engineers.midasit.com:443/gen \
-e GENNX_MAPI_KEY=your-mapi-key-here \
-- mcp-gennx
或者手动添加到MCP客户端配置中:
{
"mcpServers": {
"gennx": {
"command": "mcp-gennx",
"args": [],
"env": {
"GENNX_API_BASE_URL": "https://moa-engineers.midasit.com:443/gen",
"GENNX_MAPI_KEY": "your-mapi-key-here"
}
}
}
}
4.使用
You: Create a simple beam model with 3 nodes at (0,0,0), (5,0,0), (10,0,0)
AI: [calls post_db_node with Assign: {"1": {"X":0,"Y":0,"Z":0}, "2": {"X":5,...}, ...}]
Created 3 nodes successfully.
You: Connect them with beam elements
AI: [calls post_db_elem with Assign: {"1": {"TYPE":"BEAM","MATL":1,"SECT":1,"NODE":[1,2]}, ...}]
Created 2 beam elements.
配置
| 变量 | 默认值 | 描述 |
|---|---|---|
GENNX_API_BASE_URL |
http://localhost:8080 |
GEN NX REST API基本URL(例如。 https://moa-engineers.midasit.com:443/gen) |
GENNX_MAPI_KEY |
(空) | MAPI密钥以以下方式发送 MAPI-Key header-对于MIDAS云API是必需的 |
GENNX_API_TIMEOUT |
30.0 |
API请求超时(秒) |
TOOLSETS |
default |
工具集选择(见下文) |
READ_ONLY |
false |
何时 true,只公开GET工具 |
LOG_LEVEL |
INFO |
日志记录级别 |
工具集示例
TOOLSETS=default # 87 tools — core endpoints only
TOOLSETS=all # 161 tools — all endpoints
TOOLSETS=default,loads_advanced # default + advanced load types
TOOLSETS=modeling_core # only core modeling tools (20 tools)
READ_ONLY=true # expose only GET tools
项目结构
mcp-gennx/
├── pyproject.toml
├── .env.example
└── src/mcp_gennx/
├── __init__.py # Entry point (main)
├── server.py # Server assembly & toolset filtering
├── config.py # GennxSettings (pydantic-settings)
├── routing.py # Endpoint routing + toolset presets loaded from data/*.json
├── data/
│ ├── endpoint_subserver_map.json # endpoint → sub-server/toolset/tier (single source of truth)
│ └── toolset_definitions.json # default/all toolset presets
├── client/
│ └── gennx_client.py # Async HTTP client for GEN NX API
├── schemas/
│ ├── registry.py # SchemaRegistry — loads & merges JSON schemas (incl. description/usage)
│ ├── models.py # ApiSchema (+ description, feature_name, menu_path, usage), ToolDef
│ └── raw/ # 66 JSON schema files
├── servers/
│ ├── _common.py # register_routed_tools() — map-driven tool registration
│ ├── modeling.py # Nodes, elements, materials, sections
│ ├── boundary.py # Constraints, springs, rigid links
│ ├── loads.py # Load cases, forces, combinations (LCOM), response spectrum
│ ├── analysis.py # Eigenvalue, buckling, nonlinear
│ ├── project.py # File ops, analysis run, view capture
│ └── feature_docs.py # gennx://feature/{slug} resource (lazy GUI/usage docs)
├── tools/
│ └── factory.py # ToolFactory — dynamic tool generation
└── utils/
└── descriptions.py # Composes tool descriptions from schema fields
支持的API
第1层——核心(默认工具集)
| 域 | 端点 | 描述 |
|---|---|---|
| 建模 | db/NODE |
节点(절점)——几何点 |
| 建模 | db/ELEM |
元素(요498;)——梁、板、固体 |
| 建模 | db/MATL |
材料(Materials) |
| 建模 | db/SECT |
Sections(截面)-11 sub-types |
| 建模 | db/THIK |
厚度(두44760;)——板材厚度 |
| 边界 | db/CONS |
约束(分支条件)-supports |
| 边界 | db/NSPR Nodal Springs(切点弹簧) |
|
| 负载 | db/STLD 静态负载情况(静态负载) |
|
| 负载 | db/BODF |
Body Forces(自重) |
| 负载 | db/CNLD Concentrated Nodal Loads(节点载荷) |
|
| 负载 | db/BMLD |
Beam Loads(步载荷) |
| 负载 | db/LCOM-* |
载荷组合(载荷组合)-6 sub-types |
| 分析 | db/EIGV Eigenvalue Analysis(固有值分析) |
|
| 分析 | db/NMAS Nodal Masses(节点质量) |
第2级——高级
| 域 | 端点 | 描述 |
|---|---|---|
| 建模 | db/GRUP Structure Groups(结构组) |
|
| 建模 | db/BNGR |
边界组 |
| 建模 | db/SKEW Local Coordinates(倾斜坐标系) |
|
| 建模 | db/STOR Stories(楼层信息) |
|
| 边界 | db/GSPR |
通用弹簧 |
| 边界 | db/ELNK |
弹性链接(弹性链接) |
| 边界 | db/RIGD |
Rigid Links(刚体链接) |
| 边界 | db/FRLS |
楼层释放 |
| 边界 | db/OFFS |
Beam Offsets(梁偏移) |
| 边界 | db/MCON |
多点约束 |
| 负载 | db/PRES Pressure Loads(压力载荷) |
|
| 负载 | db/PSLT Pressure Load Types(压力载荷类型) |
|
| 负载 | db/ETMP 元素温度(Element Temperatures) |
|
| 负载 | db/GTMP 梯度温度梯度(Gradient Temperatures) |
|
| 负载 | db/SPLC 响应光谱负载案例(Response Spectrum Load Cases) |
|
| 分析 | db/ACTL 分析控制(Analysis Control) |
|
| 分析 | db/BUCK Buckling Analysis(左屈分析) |
|
| 分析 | db/PDEL |
P-Delta分析 |
| 分析 | db/NLCT |
非线性控制 |
| 项目 | db/UNIT |
单位制 |
| 项目 | db/STYP |
结构类型 |
项目操作(手动注册)
| 工具 | 说明 |
|---|---|
post_doc_anal |
运行分析(标准或推送式) |
post_doc_new |
创建新项目 |
post_doc_open |
打开项目文件 |
post_doc_save |
保存项目 |
post_doc_saveas |
将项目另存为新文件 |
post_doc_close |
关闭项目 |
post_view_capture |
将当前视图捕获为图像 |
发展
运行测试
pip install -e ".[dev]"
pytest
添加新的API
- 将JSON模式文件放入
src/mcp_gennx/schemas/raw/。为了丰富生成的描述,请包含可选的description,feature_name,menu_path,以及usage字段(usage文本通过gennx://feature/{slug}资源,未内联)。 - 在端点图中添加一条线
src/mcp_gennx/data/endpoint_subserver_map.json,将其路由到子服务器、工具集和层:无需Python编辑——每个子服务器在启动时通过以下方式从该映射读取其端点"db/NEW_ENDPOINT": {"sub_server": "modeling", "toolset": "modeling_advanced", "tier": 2}register_routed_tools(). (tests/test_routing.py如果模式及其映射条目不同步,则失败。) - 重新启动服务器——工具和功能资源将自动生成。
许可证
麻省理工学院