comsol-mcp
Server Configuration
Describes the environment variables required to run the server.
| Name | Required | Description | Default |
|---|---|---|---|
| COMSOL_PORT | No | Default server port. Default: 2036. | |
| COMSOL_ROOT | No | COMSOL installation root. Default: auto-detected. | |
| COMSOL_MCP_HOME | No | Where logs/ and out/ are written. Default: current directory. | |
| COMSOL_MCP_CLUSTER | No | 0 disables the HPC cluster tools. Default: 1. | |
| COMSOL_MCP_LOG_BACKUPS | No | Number of rotated log files to keep. Default: 3. | |
| COMSOL_MCP_MAX_PENDING | No | Maximum queued worker tasks; further calls fail fast with WORKER_OVERLOADED. Default: 32. | |
| COMSOL_MCP_IDLE_TIMEOUT | No | Exit after this many idle seconds; 0 disables. Prevents stale processes piling up when a client disconnects. Default: 1800. | |
| COMSOL_MCP_LOG_MAX_BYTES | No | Rotate logs/comsol-mcp.log at this size. Default: 5242880. |
Instructions
Guidance the server publishes about itself, which clients place ahead of the tool catalog so the model reads it before choosing anything.
驱动本机 COMSOL Multiphysics。典型流程:comsol_start -> comsol_open -> comsol_inspect -> comsol_params/comsol_python 改模型 -> comsol_mesh -> comsol_solve -> comsol_eval/comsol_plot。
Capabilities
Features and capabilities supported by this server
Protocol revision2025-11-25
| Capability | Details |
|---|---|
| tools | {
"listChanged": false
} |
| prompts | {
"listChanged": false
} |
| resources | {
"subscribe": false,
"listChanged": false
} |
Tools
Functions exposed to the LLM to take actions
| Name | Description |
|---|---|
| comsol_statusA | 查看 COMSOL 连接状态:是否已连接、端口、COMSOL 版本、已加载模型、当前模型、是否正在后台求解、上次错误。不会启动任何东西。 |
| comsol_startA | 连接或启动 COMSOL 后端。默认端口 2036:如果该端口已有 server 就连接它(例如 Desktop 已连上的 server),否则启动一个新的 server。cores 为 0 表示使用全部核心。首次启动约 10-20 秒。 |
| comsol_stopA | 断开并停止 COMSOL 后端。默认只断开当前客户端;stop_server=true 时同时关闭由本工具启动的 server 进程。Desktop 若正连着该 server 会被断开。 |
| comsol_openA | 打开一个 .mph 模型,或新建空模型(new=true)。path 支持中文和相对路径(相对 comsol-bridge 目录)。打开后该模型成为当前操作对象。对于大模型(>50MB)加载可能需要几十秒。 |
| comsol_useA | 切换当前操作的模型。model 传模型名或 tag(见 comsol_status 的 models 列表)。一个后端可以同时加载多个 .mph,用这个工具指定后续操作作用于哪一个。 |
| comsol_saveA | 保存当前模型。path 为空时存回原文件;提供 path 时另存为。backup=true 时先把旧文件复制为 .bak-时间戳(不移动原文件),保存失败不会破坏原文件。返回 ok/error_code;SAVE_LOCKED 表示文件可能被 Desktop 打开。 |
| comsol_inspectA | 查看当前模型的完整结构:参数、组件与维度、几何特征、物理场及其边界条件、材料、网格、研究、求解结果与数据集。做任何修改前先用它确认标签。 |
| comsol_geometryA | 通用几何工具。action=list 列出现有几何和特征;create 新建特征(feature_type 如 Block/Cylinder/Sphere/Rectangle/Circle/Import/Union/Difference);update 改属性;delete 删除特征;run 重建几何。properties 是属性字典,如 {"size": ["0.1","0.1","0.1"], "pos": ["0","0","0"]}。模型没有组件/几何时会自动创建(dimension 指定 2 或 3)。 |
| comsol_physicsA | 通用物理场工具。action=list 列出接口和特征;add_interface 新建接口(physics_type 如 HeatTransfer/SolidMechanics/LaminarFlow/Electrostatics);add_feature 给接口加特征(feature_type 如 TemperatureBoundary/HeatFluxBoundary/InletBoundary);update_feature 设置选择或属性;remove_feature/remove_interface 删除。selection 传实体编号列表,或 named_selection 传命名选择的 tag。dimension 为特征维度,0 表示按几何自动推断(3D 边界=2,2D 边界=1)。 |
| comsol_selectionA | 命名选择工具(对应 COMSOL 的 Box/Ball/Explicit Selection)。action=list 列出选择及其实体;create 创建选择;remove 删除。selection_type=Box 时用 box=[xmin,xmax,ymin,ymax,zmin,zmax](2D 可只给 4 个数);Ball 时用 center=[x,y,z] + radius;Explicit 时用 entities=[...]。entity_dim 为选择的实体维度:3=域、2=面(3D 边界)、1=边、0=自动取几何维度。condition 默认 intersects(与选择区域相交即选中),需要完全包含时传 inside。创建后可在 comsol_physics 里用 named_selection 把选择绑到边界条件上。 |
| comsol_diagnoseA | 模型体检:列出 COMSOL 报告的问题(未定义变量、空选择、几何/网格问题),并检查是否缺几何、物理场、材料、网格、研究或解。求解失败后先跑这个。 |
| comsol_helpA | COMSOL 建模速查,不访问 COMSOL。topic 可选 geometry/heat/solid/flow/electrostatics/selection/mesh/study/sweep。写模型前先查,能少踩属性名和单位的坑。 |
| comsol_materialA | 材料工具。action=list 列出材料和当前物性;create 新建材料,preset 可选 copper/aluminum/steel/silicon/water/air,或用 properties 传自定义物性;update 改属性;remove 删除。属性名如 thermalconductivity、density、heatcapacity、youngsmodulus、poissonsratio、electricconductivity、relpermittivity、dynamicviscosity,值可带单位。 |
| comsol_sweepA | 参数扫描工具。action=list 查看现有研究及扫描配置;add 给研究加 Parametric 特征(parameters 是参数名列表,values 是每个参数的取值串,空格分隔,长度需与 parameters 一致);remove 删除扫描。加完后正常 comsol_solve 就会对所有组合求解。 |
| comsol_modelA | 模型管理。action=list 列出当前后端所有模型;remove 把模型从内存卸载(不删文件);rename 改模型显示名。切换当前模型用 comsol_use。 |
| comsol_paramsA | 读取或设置全局参数。values 为 {名称: 值} 字典时设置参数(值可带单位,如 '200[A]'、'1.5[mm]'),并返回设置后的全部参数;values 为空时只读取。evaluate=true 时返回数值(带单位换算到 SI)。 |
| comsol_meshA | 网格工具。action=list 查看特征树和统计;build 生成网格;size 设置全局尺寸(level 1-9,1 最细 9 最粗;或用 properties 自定义 hmax/hmin/hgrad/hcurve);add 添加网格特征(FreeTri/FreeQuad/Map/Sweep/BndLayer/Size/Distribution/Refine/Import);update 改属性或选择;remove 删除;stats 只看统计和质量。局部细化:add feature_type=Size,selection 传实体编号,entity_dim 传维度;边界层:先 add BndLayer,再 add BndLayerProp 且 parent 指向 BndLayer 的 tag。Sweep 的源面要传 selection_name='sourceface' 和 entity_dim=2(3D),层数用 parent=swe 的 Distribution 特征设置 numelem。Size/Distribution 会自动排到网格操作之前。结果含单元数、顶点数、最小/平均质量。 |
| comsol_studyA | 研究(study)工具。action=list 列出研究和求解步骤;create 新建研究(study_type: Stationary/Transient/Eigenfrequency/Frequency,properties 写 step 属性,如 {'tlist':'range(0,1,10)'});add_step 给已有研究加步骤;set 修改 study 或 step 属性;remove 删除研究。创建后用 comsol_solve 运行。 |
| comsol_solveA | 运行研究(求解)。study 为空时用第一个研究。background=true 时立即返回 job_id,求解在后台进行,之后用 comsol_status 查看 job_status/耗时/结果;只有 status 可以在求解期间调用,其他修改类工具会快速返回 MODEL_BUSY。 |
| comsol_evalA | 对表达式求值并给出统计量(min/max/mean/size)。expression 例如 'T'、'es.normE'、'solid.mises';unit 可选,如 'degC'。dataset 为空时用默认数据集。 |
| comsol_plotB | 画结果图并导出 PNG。expression 例如 'T';unit 如 'degC';title 为图标题。自动按模型维度创建 2D/3D 表面图,file 为空时输出到 out/ 目录。返回图片路径。 |
| comsol_exportB | 把表达式在网格上的取值导出为 CSV(含索引与数值)。expression 如 'T',file 为输出路径(相对 comsol-bridge 目录)。适合后续用 Python/Excel 分析。 |
| comsol_pythonB | 在当前 COMSOL 会话里执行 Python 代码(COMSOL Java API 逃生舱)。可用变量:model(mph Model)、java(model.java,com.comsol.model.Model)、client、mph、np、json。最后一行若是表达式会作为返回值。示例:java.modelNode('comp1').physics().create('ht','HeatTransfer','geom1') |
| comsol_desktopA | 启动 COMSOL Desktop 并连接当前后端 server(client-server 模式),让用户能在图形界面里实时看到同一模型。open_file 可选,启动后打开该 .mph。注意:会弹出 Connect to Server 窗口,需要用户点一下 Connect。 |
| comsol_screenshotA | 截取 COMSOL Desktop 窗口为 PNG,让 AI 看到用户当前的界面和模型。file 为空时输出到 out/ 目录。窗口未找到时返回错误。 |
| comsol_cluster_configB | Cluster (Slurm/SCC): Einstellungen anzeigen oder ändern. Ohne values: anzeigen. values z. B. {'user': 'ka_ab1234', 'host': 'uc3.scc.kit.edu', 'partition': 'cpu', 'cores': 32, 'time': '04:00:00', 'comsol_module': 'cae/comsol/6.3', 'remote_dir': '/hkfs/work/workspace/scratch/'}. Gespeichert in cluster.json. |
| comsol_cluster_checkA | Cluster: Verbindung prüfen (SSH ohne Rückfrage), Slurm-Partitionen und verfügbare COMSOL-Module auflisten. Vor dem ersten Submit aufrufen. Rechnet nichts auf dem Login-Knoten. |
| comsol_cluster_submitA | Cluster: COMSOL-Modell als Slurm-Batchjob rechnen. mph_file leer = aktuell lokal geöffnetes Modell in seiner gespeicherten Fassung (vorher comsol_save!). study: Studien-Tag (z. B. std1), leer = alle. params: {'name': 'wert'} überschreibt Parameter (comsol batch -pname/-plist). partition/time/nodes/cores/mem überschreiben cluster.json für diesen Job. Gibt job_id zurück; danach comsol_cluster_status und comsol_cluster_fetch. |
| comsol_cluster_statusA | Cluster: Status eines Jobs (Slurm-Zustand, Laufzeit, Ende von batch.log). job_id leer = alle bekannten Jobs mit Slurm-Zustand auflisten. |
| comsol_cluster_fetchA | Cluster: Ergebnisse eines Jobs herunterladen (output.mph, batch.log, slurm-*.out) nach /cluster/runs//. Danach mit comsol_open(path=...) lokal öffnen und mit comsol_eval/comsol_plot auswerten. include_mph=false holt nur Logs. |
| comsol_cluster_cancelC | Cluster: Slurm-Job abbrechen (scancel). |
Prompts
Interactive templates invoked by user choice
| Name | Description |
|---|---|
No prompts | |
Resources
Contextual data attached and managed by the client
| Name | Description |
|---|---|
No resources | |
TDQS
Scored across 31 tools
Most tools target a clearly distinct resource+action (geometry, mesh, physics, study, selection, material each own one domain; solve/eval/plot/export/save/open are distinct lifecycle steps). Minor overlap exists between comsol_status, comsol_model, and comsol_use (all touch loaded-model listing/switching) and between comsol_inspect and comsol_diagnose, but descriptions give clear routing cues.
All tools share a comsol_ prefix plus snake_case, giving a predictable namespace. The only deviation is stylistic: several tools are noun-based action-multiplexers (comsol_material, comsol_mesh, comsol_physics) while others are verb-based singletons (comsol_solve, comsol_plot, comsol_open), which is readable but not one pure verb_noun pattern.
31 tools is heavy for a single server and effectively merges two surfaces: local modeling (~25 tools) and Slurm cluster orchestration (6 tools). Each tool does earn its place in a complex COMSOL workflow, but the breadth suggests it could be split into local and cluster servers.
Lifecycle coverage is strong: geometry, physics, mesh, study, material, and selection all have list/create/update/remove plus build/run, and the cluster flow is end-to-end (config, check, submit, status, fetch, cancel). Missing pieces are minor: no dataset/solution management tool, no file delete, and no multi-expression batch export.