Skip to main content
Glama
comsol-mph-mcp

comsol-mph-mcp

by ai55798-oss

comsol-mph-mcp

An MCP server that lets an AI assistant drive COMSOL Multiphysics through the MPh Python library. Aimed at COMSOL 6.2 and 6.4 on Windows, but nothing in the code is Windows-only.

What it solves

Repeating a transient heat-transfer study over several materials, thicknesses and loads means a lot of clicking, or a pile of one-off scripts. This project puts the common steps behind a small set of tools: load a model, change parameters, solve, check whether the solver converged, evaluate expressions, export data, and run a whole parameter grid with a manifest that records what happened. It also has helpers for the usual comsolmphserver problems (port not open, missing login file, memory or convergence errors in the log).

It has no runtime dependencies besides mph, which is optional: an offline mock backend ships with the package so tests and CI run without a license.

Related MCP server: COMSOL MCP Server

Architecture

MCP client (Claude Desktop, ...)  --stdio JSON-RPC-->  server.py (ToolRegistry)
                                                          |
                          sweep.py   diagnostics.py       |
                                  \        |             /
                                   backend.py: ComsolBackend
                                     |-- MphBackend  (real COMSOL via mph)
                                     `-- MockComsolBackend (offline, deterministic)

The server speaks MCP's JSON-RPC 2.0 over stdio directly, so it does not depend on a particular version of the mcp SDK.

Installation

git clone https://github.com/ai55798-oss/comsol-mph-mcp.git
cd comsol-mph-mcp
python -m venv .venv && . .venv/bin/activate     # Windows: .venv\Scripts\activate
pip install -e ".[comsol]"                        # add ,dev for pytest

Try it without COMSOL: comsol-mph-mcp --backend mock.

Claude Desktop configuration

{
  "mcpServers": {
    "comsol": {
      "command": "C:\\path\\to\\comsol-mph-mcp\\.venv\\Scripts\\comsol-mph-mcp.exe",
      "args": []
    }
  }
}

Use "args": ["--backend", "mock"] to test the wiring first.

Windows setup for COMSOL 6.2 / 6.4

  1. Install COMSOL with a license that allows client-server mode, and install mph (pip install "mph>=1.2") in the same environment as this package.

  2. Run comsolmphserver once by hand so it creates your login credentials (%USERPROFILE%\.comsol\v62 or v64\login.properties).

  3. Either let the tools start a local session (comsol_connect without a host), or start a server and connect to it:

    .\scripts\start_comsol_mphserver.ps1 -Port 2036
    .\scripts\start_comsol_mphserver.ps1 -Port 2036 -TestOnly

    The script keeps preferences, temp files and logs in .comsol_runtime\ inside the repo (git-ignored). Then call comsol_connect with host: "localhost", port: 2036.

  4. comsol_status with check_runtime: true reports whether the port is open and the login file looks sane.

Tools

Tool

Purpose

comsol_status

Backend, connection and model state; optional runtime check

comsol_connect

Start a local session or connect to comsolmphserver

comsol_disconnect

Close the session

model_load

Load a .mph file

model_inspect

Parameters, studies, datasets (and physics/materials on the real backend)

model_save

Save, optionally to a new path

set_parameters

Set global parameters, e.g. {"q": "8000[W/m^2]"}

run_parametric_sweep

Grid sweep with convergence tracking; writes manifest.json and results.csv

check_convergence

Solve a study and report status, and/or parse a solver log

export_results

Evaluate expressions to CSV or JSON

A sweep config looks like examples/heat_transfer_sweep.json: variants (for example materials), a parameters grid, and outputs expressions. The offline example needs no license:

python examples/run_example_sweep.py sweep_output

The mock backend uses a closed-form semi-infinite-solid heat estimate. It is there to exercise the plumbing, not to produce engineering numbers.

Running tests

pip install -e ".[dev]"
pytest

Roadmap

  • Verify MphBackend against more 6.2 and 6.4 models and report what breaks.

  • Mesh-convergence study tool (refine, re-solve, compare an output).

  • Plot export and selection-based evaluation.

  • Optional adapter for the official mcp SDK once its API settles.

License

MIT

Tool Schema Changelog

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

Loading tool schema changelog…

    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
      1,036
      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
      Not graded
      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
    • A
      license
      C
      quality
      D
      maintenance
      Enables AI agents to read and write .mph model files, control the COMSOL desktop GUI in real time, and run complete modeling, meshing, solving, and post-processing workflows.
      23
      1
      MIT