Skip to main content
Glama

COMSOL MCP

A Model Context Protocol (MCP) server for COMSOL Multiphysics that lets AI agents (such as Claude Desktop / Codex):

  • Read and write .mph model files

  • Control the COMSOL desktop GUI in real time (embedded GUI bridge; operations are visible live on the desktop)

  • Complete the full modeling → definition → computation → post-processing pipeline

  • Work from any working directory (independent of cwd; automatically detects the COMSOL installation path)

  • Run in dry-run mode when COMSOL is not available, for development and testing


Architecture

AI Agent ──MCP(stdio)──► comsol_mcp (Python) ──HTTP/JSON──► ComsolBridge (Java, 在 COMSOL JVM 内)
                                                    │
                                                    └──comsolbatch (无头回退)
  • Embedded GUI bridge (real-time control): launch_gui starts the COMSOL desktop and loads ComsolBridge inside its JVM; the bridge runs a local HTTP service and holds the Model object. The MCP server invokes the COMSOL Java API through it in real time, so you can watch geometry/physics/solver progress update live on the desktop.

  • Headless batch (fallback/batch): when no GUI session exists, operations are accumulated into a Java program and run with comsolcompile + comsolbatch. The same modeling logic works in both modes.

  • dry-run: enabled automatically when COMSOL is not installed on the local machine; all tools remain callable (returning simulated results), which is convenient for onboarding and testing.

Related MCP server: COMSOL MCP Server

Requirements

  • COMSOL Multiphysics 5.x / 6.x (the standard desktop license includes the Java API)

  • Python 3.10+

  • (Optional) No Node required — the dashboard is plain static HTML

Installation

cd comsol-mcp
pip install .

⚠️ Configure the COMSOL path (required for non-default installations)

The program locates COMSOL in the following order, but automatic detection only covers standard locations:

  1. The COMSOL_HOME environment variable (most reliable; recommended to set explicitly when configuring MCP)

  2. Windows registry (COMSOLROOT)

  3. Standard directories: C:\Program Files\COMSOL\COMSOLxx, D:/..., E:/..., and their WSL / Linux / macOS equivalents

If COMSOL is installed on a non-default drive or in a custom directory (for example C:\D\Program Files\COMSOL\COMSOL62\Multiphysics), automatic detection will not find it and you must set COMSOL_HOME. All users are strongly advised to write COMSOL_HOME into env when configuring MCP rather than relying on automatic detection — otherwise the agent may mistakenly conclude COMSOL is not installed and fall back to dry-run.

# Windows 示例:指向 Multiphysics 目录最简明(也兼容版本目录 .../COMSOL62 或根目录 .../COMSOL)
export COMSOL_HOME="C:\Program Files\COMSOL\COMSOL62\Multiphysics"

Compile the Java bridge (requires COMSOL to be on PATH or in COMSOL_HOME):

comsol-mcp compile-bridge

Quick Start

Add it to your MCP client configuration (OpenCode: in the mcp block of ~/.config/opencode/opencode.json; Claude Desktop: in the mcpServers block of claude_desktop_config.json):

Key point: COMSOL_HOME must be written into env. Do not let the AI probe/guess a fixed default path (such as C:\Program Files\COMSOL) — it cannot find custom installation directories, will misjudge COMSOL as "not installed", and fall back to dry-run. Machines without COMSOL installed can still dry-run (generate_model_java and other tools that do not need COMSOL work as usual).

{
  "mcp": {
    "comsol": {
      "type": "local",
      "command": ["C:\\path\\to\\comsol-mcp.exe"],
      "args": [],
      "env": { "COMSOL_HOME": "C:\\D\\Program Files\\COMSOL\\COMSOL62\\Multiphysics" }
    }
  }
}

Then have the AI work like this:

  1. launch_gui() — open the COMSOL desktop and load the bridge (visible in real time).

  2. new_model() / load_model("x.mph")

  3. add_block("geom1", 3, [1,1,1], [0,0,0])

  4. add_physics("ht", "ht") (heat transfer)

  5. build_mesh() → add_study("std1", "Stationary") → run_solver("std1")

  6. evaluate("T") to retrieve results, save_model("out.mph") to save.

MCP Tool List

类别

工具

会话 / GUI

launch_gui, connect_gui, gui_status, shutdown_gui

模型读写

load_model, save_model, new_model, model_info

几何

add_block, add_cylinder, add_sphere, boolean_op, import_geometry

物理 / 材料

add_physics(ht/spf/tds/es/solid/…), add_material

网格 / 研究 / 求解

build_mesh, add_study(Stationary/TimeDependent/Parametric/Eigenfrequency), run_solver, solver_status

后处理

evaluate, export_results

通用

exec_model_api(直接运行任意 COMSOL Java API 代码)

无 COMSOL 准备

generate_model_java(生成可编译的 Java 模型源码,无需 COMSOL,用于拷到 COMSOL 机器编译成 .mph)

See USAGE.md for details.

Dry-Run Mode

When COMSOL cannot be detected, the package automatically enters dry-run: tools return simulated data and the MCP server can still be imported and tested. Set COMSOL_MCP_DRYRUN=1 to force it on.

Machines without COMSOL can also use generate_model_java to produce standalone compilable Java model source code, then compile it to .mph with comsolcompile + comsolbatch on a machine that has COMSOL. See "Two Run Modes" in USAGE.md.

Verification Status

  • ✅ In the local build environment: py_compile passes for the whole package, the MCP server starts, and the dry-run logic chain is exercisable.

  • ⚠️ Real COMSOL execution must be verified on a machine with COMSOL installed: run comsol-mcp compile-bridge and actually run a model. The Java bridge is written to the COMSOL Java API specification, but interfaces may need minor adjustments across versions (see the note at the top of comsol_mcp/bridge/ComsolBridge.java).

License

MIT — see LICENSE.

Available Tools

23 tools
add_blockC

Add a block (box) to a geometry sequence.

Inputs: pos (required), dims (required), size (required), geom_tag (required), +1 more. Returns: result

add_cylinderC

Add a cylinder to a geometry sequence.

Inputs: h (required), r (required), pos (required), dims (required), +3 more. Returns: result

add_materialC

Add a material to the model.

Inputs: tag (required), material (required), selection. Returns: result

add_physicsB

Add a physics interface (ht, spf, tds, es, solid, ...).

Inputs: tag (required), interface (required), settings. Returns: result

add_sphereC

Add a sphere to a geometry sequence.

Inputs: r (required), pos (required), dims (required), geom_tag (required), +1 more. Returns: result

add_studyB

Add a study (Stationary|TimeDependent|Parametric|Eigenfrequency).

Inputs: tag (required), study_type (required), settings. Returns: result

boolean_opC

Boolean combine geometry features (union|intersect|difference).

Inputs: inputs (required), geom_tag (required), operation (required). Returns: result

build_meshD

Build the mesh.

Inputs: mesh_tag. Returns: result

connect_guiB

Connect to an already-running COMSOL GUI bridge.

Inputs: host, port. Returns: result

evaluateC

Evaluate an expression (or global evaluation) and return data.

Inputs: expr (required), dataset. Returns: result

exec_model_apiA

Run arbitrary COMSOL Java API code.

Provide either a full class with public static String run(Model model), or a Java snippet body; it will be wrapped automatically and executed in the COMSOL JVM (best-effort in live mode, always via compile+run in batch mode).

Inputs: code (required). Returns: result

export_resultsC

Export results (plot/data) to a file.

Inputs: filename (required), export_type (required), settings. Returns: result

generate_model_javaA

Generate a standalone, compilable COMSOL Java model source file.

Works WITHOUT COMSOL installed. Use it on a COMSOL-less machine to prepare a Java model, then move the file to a COMSOL machine and compile it: comsolcompile .java comsolbatch -java spec may carry geometries/physics/materials/studies/save to shape the code. The produced file still needs COMSOL to actually compile into a .mph.

Inputs: filepath (required), spec, class_name, model_version. Returns: result

gui_statusA

Report the current GUI/bridge session state.

Inputs: no named parameters. Returns: result

import_geometryC

Import a geometry from a CAD/file format.

Inputs: filename (required), geom_tag (required), type. Returns: result

launch_guiA

Launch the COMSOL desktop GUI with the live bridge loaded.

Operations issued afterwards drive the visible GUI in real time.

Inputs: port, model_path. Returns: result

load_modelC

Load a .mph model from disk.

Inputs: path (required). Returns: result

model_infoA

Return the structure of the current model.

Inputs: no named parameters. Returns: result

new_modelB

Create a new empty model.

Inputs: version. Returns: result

run_solverC

Run the solver for a study.

Inputs: study_tag (required). Returns: result

save_modelB

Save the current model to a .mph file.

Inputs: path. Returns: result

shutdown_guiA

Stop the COMSOL GUI bridge session.

Inputs: no named parameters. Returns: result

solver_statusB

Report whether a study has been solved.

Inputs: study_tag (required). Returns: result

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    C2.8/5.0

    Scored across 23 tools

    Disambiguation5/5

    Each tool targets a distinct stage or resource: geometry primitives, physics/material, mesh/study/solver, results, model files, GUI bridge, and code generation. Even similar lifecycle tools such as launch_gui vs connect_gui and solver_status vs gui_status are clearly separated. exec_model_api is intentionally broad but explicitly labeled as arbitrary Java API, so it does not create real ambiguity.

    Naming Consistency3/5

    Many tools follow a verb_noun pattern, but the set is mixed: add_* dominates creation, while solver_status, gui_status, and model_info use noun-first naming, and boolean_op lacks a verb entirely. The names are readable and all lowercase with underscores, but the conventions are not consistent enough for a strong score.

    Tool Count3/5

    With 23 tools, this sits in the 16-25 'heavy' band. The breadth is somewhat justified by COMSOL's wide scope spanning geometry, physics, meshing, solving, GUI, file I/O, and code generation, but the count feels slightly large for an MCP tool surface.

    Completeness4/5

    The set covers the core COMSOL workflow end-to-end: new/load/save models, geometry creation, physics and materials, meshing, studies, solving, evaluation, export, and GUI bridging. Fine-grained editing of existing features, material properties, or mesh settings is missing, but exec_model_api and generate_model_java provide workarounds for those gaps.

    Maintenance

    ActivityStale
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      B
      quality
      B
      maintenance
      Enables AI agents to automate multiphysics simulations in COMSOL Multiphysics, covering model management, geometry building, physics configuration, and results visualization. It supports complex simulation workflows through the MCP protocol and includes integrated knowledge retrieval for documentation and troubleshooting.
      93
      989
      MIT
    • A
      license
      B
      quality
      C
      maintenance
      Enables AI agents to automate COMSOL Multiphysics simulations, including model management, geometry building, physics configuration, meshing, solving, and results visualization through the MCP protocol.
      78
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables AI agents to automate COMSOL Multiphysics simulations, including model management, geometry building, physics configuration, meshing, solving, and results visualization via the MCP protocol.
      MIT