Allows AI agents to automate COMSOL Multiphysics simulations, including model management, geometry building, physics configuration, meshing, solving, and results visualization.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@COMSOL MCP ServerCreate a 3D block 10x5x2 mm"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
COMSOL MCP Server
MCP Server for COMSOL Multiphysics simulation automation via AI agents.
English | δΈζ
Star History
Related MCP server: comsol-mcp
Project Goal
Build a complete COMSOL MCP Server enabling AI agents (like Claude, opencode) to perform multiphysics simulations through the MCP protocol:
Model Management - Create, load, save, version control
Geometry Building - Blocks, cylinders, spheres, boolean operations
Physics Configuration - Heat transfer, fluid flow, electrostatics, solid mechanics
Meshing & Solving - Auto mesh, stationary/time-dependent studies
Results Visualization - Evaluate expressions, export plots
Knowledge Integration - Embedded guides + PDF semantic search
Requirements
COMSOL Multiphysics (version 5.x or 6.x)
Python 3.10+ (NOT Windows Store version)
Java runtime (required by MPh/COMSOL)
Installation
# Clone repository
git clone https://github.com/Zhangyoupeng1996/Codex_MCP_Comsol.git
cd Codex_MCP_Comsol
# Install dependencies
python -m pip install -e .
# Test server
python -m src.serverCOMSOL Server Runtime Check
For Windows workstations where the default COMSOL profile directory is not
writable or has stale credentials, start comsolmphserver with workspace-local
runtime folders while keeping COMSOL authentication enabled.
.\scripts\start_comsol_mphserver.ps1 `
-ComsolBin "D:\Software\Comsol6.3\COMSOL63\Multiphysics\bin\win64" `
-Port 2036 `
-User ROG `
-SyncDefaultLoginNotes:
-SyncDefaultLogincopies the local COMSOLlogin.propertieshash into the workspace runtime directory so the Python client and server use the same authenticated CHAP login data.The script intentionally uses
-login auto, not-login never.It writes local runtime state under
.comsol_runtime/; this directory is ignored by Git.
Validate the same Python client path used by the MCP server:
python scripts/test_comsol_connection.py --host localhost --port 2036You should see the COMSOL version and the list of loaded models. A listening
TCP port alone is not sufficient; this direct mph.Client(...) check catches
authentication problems such as Wrong_username_or_password.
For Codex Desktop workspace configuration, migration notes, and safe cleanup of
stale MCP Python processes, see
docs/CODEX_WORKSPACE.md.
Example: Classic Piezoelectric Cantilever
After the COMSOL server is running and the MCP server dependencies are installed, generate a compact piezoelectric cantilever model:
python examples/piezoelectric_cantilever_classic.pyThe script creates a bonded substrate/piezo layer, electrostatic electrodes, a fixed root, a stationary study, and result plot groups for:
electric potential,
electric field norm,
equivalent piezoelectric bending shape,
true solid displacement norm when COMSOL creates the
PiezoelectricEffectcoupling successfully.
Generated .mph files are written to comsol_outputs/, which is ignored by
Git so simulation artifacts do not clutter the MCP source repository.
Building PDF Knowledge Base
The pdf/ and knowledge_base/ directories are intentionally ignored by Git.
Place your local COMSOL documentation PDFs under pdf/, then build the local
knowledge base with the commands below.
# Install additional dependencies
pip install pymupdf chromadb sentence-transformers
# Build knowledge base
python scripts/build_knowledge_base.py
# Check status
python scripts/build_knowledge_base.py --statusUsage
Option 1: With opencode
Create opencode.json in project root:
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"comsol": {
"type": "local",
"command": ["python", "-m", "src.server"],
"enabled": true,
"environment": {
"HF_ENDPOINT": "https://hf-mirror.com"
},
"timeout": 30000
}
}
}Option 2: With Claude Desktop
{
"mcpServers": {
"comsol": {
"command": "python",
"args": ["-m", "src.server"],
"cwd": "/path/to/comsol-mcp"
}
}
}Code Structure
comsol_mcp/
βββ opencode.json # MCP server config for opencode
βββ pyproject.toml # Python project config
βββ README.md # This file
β
βββ src/
β βββ server.py # MCP Server entry point
β βββ tools/
β β βββ session.py # COMSOL session management (start/stop/status)
β β βββ model.py # Model CRUD + versioning
β β βββ parameters.py # Parameter management + sweeps
β β βββ geometry.py # Geometry creation (block/cylinder/sphere)
β β βββ physics.py # Physics interfaces + boundary conditions
β β βββ mesh.py # Mesh generation
β β βββ study.py # Study creation + solving (sync/async)
β β βββ results.py # Results evaluation + export
β βββ resources/
β β βββ model_resources.py # MCP resources (model tree, parameters)
β βββ knowledge/
β β βββ embedded.py # Embedded physics guides + troubleshooting
β β βββ retriever.py # PDF vector search retriever
β β βββ pdf_processor.py # PDF chunking + embedding
β βββ async_handler/
β β βββ solver.py # Async solving with progress tracking
β βββ utils/
β βββ versioning.py # Model version path management
β
βββ scripts/
β βββ build_knowledge_base.py # Build PDF vector database
β
βββ client_script/ # Standalone modeling scripts (examples)
β βββ create_chip_tsv_final.py # Example: Chip thermal model
β βββ create_micromixer_auto.py # Example: Fluid flow simulation
β βββ create_chip_thermal*.py # Various chip thermal variants
β βββ create_micromixer*.py # Various micromixer variants
β βββ visualize_*.py # Result visualization scripts
β βββ add_visualization.py # Add plot groups to model
β βββ test_*.py # Integration tests
β
βββ comsol_models/ # Saved models (structured)
β βββ chip_tsv_thermal/
β β βββ chip_tsv_thermal_20260216_*.mph
β β βββ chip_tsv_thermal_latest.mph
β βββ micromixer/
β βββ micromixer_*.mph
β
βββ tests/
βββ test_basic.py # Unit testsAvailable Tools (80+ total)
Session (4)
Tool | Description |
| Start local COMSOL client |
| Connect to remote server |
| Clear session |
| Get session info |
Model (9)
Tool | Description |
| Load .mph file |
| Create empty model |
| Save to file |
| Save with timestamp |
| List loaded models |
| Set active model |
| Clone model |
| Remove from memory |
| Get model structure |
Parameters (5)
Tool | Description |
| Get parameter value |
| Set parameter |
| List all parameters |
| Setup parametric sweep |
| Get/set description |
Geometry (14)
Tool | Description |
| List geometry sequences |
| Create geometry sequence |
| Add generic feature |
| Add rectangular block |
| Add cylinder |
| Add sphere |
| Add 2D rectangle |
| Add 2D circle |
| Union objects |
| Subtract objects |
| Import CAD file |
| Build geometry |
| List features |
| Get boundary numbers |
Physics (16)
Tool | Description |
| List physics interfaces |
| Available physics types |
| Add generic physics |
| Add Electrostatics |
| Add Solid Mechanics |
| Add Heat Transfer |
| Add Laminar Flow |
| Configure boundary condition |
| Assign material |
| List physics features |
| Remove physics |
| Add coupling |
| Interactive heat BC setup |
| Configure heat boundaries |
| Interactive flow BC setup |
| Generic boundary setup |
Mesh (3)
Tool | Description |
| List mesh sequences |
| Generate mesh |
| Get mesh statistics |
Study & Solving (8)
Tool | Description |
| List studies |
| Solve synchronously |
| Solve in background |
| Get progress |
| Cancel solving |
| Wait for completion |
| List solutions |
| List datasets |
Results (9)
Tool | Description |
| Evaluate expression |
| Evaluate scalar |
| Get time steps |
| Get sweep values |
| Export data |
| Export plot image |
| List export nodes |
| List plot nodes |
Knowledge (8)
Tool | Description |
| Get documentation |
| List available docs |
| Physics quick guide |
| Troubleshooting help |
| Best practices |
| Search PDF docs |
| PDF search status |
| List PDF modules |
Example Cases
Case 1: Chip Thermal Model with TSV
3D thermal analysis of a silicon chip with Through-Silicon Via (TSV).
Geometry: 60Γ60Γ5 Β΅m chip, 5 Β΅m diameter TSV hole, 10Γ10 Β΅m heat source
# Key steps:
# 1. Create chip block and TSV cylinder
# 2. Boolean difference (subtract TSV from chip)
# 3. Add Silicon material (k=130 W/mΒ·K)
# 4. Add Heat Transfer physics
# 5. Set heat flux on top, temperature on bottom
# 6. Solve and evaluate temperature distributionScript: client_script/create_chip_tsv_final.py
Run:
cd /path/to/comsol-mcp
python client_script/create_chip_tsv_final.pyResults: Temperature rise from ambient with heat flux of 1 MW/mΒ²
Case 2: Micromixer Fluid Flow
3D laminar flow simulation in a microfluidic channel.
Geometry: 600Γ100Γ50 Β΅m rectangular channel
# Key steps:
# 1. Create rectangular channel block
# 2. Add water material (Ο=1000 kg/mΒ³, ΞΌ=0.001 PaΒ·s)
# 3. Add Laminar Flow physics
# 4. Set inlet velocity (1 mm/s), outlet pressure
# 5. Add Transport of Diluted Species for mixing
# 6. Solve and evaluate velocity profileScript: client_script/create_micromixer_auto.py
Run:
cd /path/to/comsol-mcp
python client_script/create_micromixer_auto.pyResults: Velocity distribution, concentration mixing profile
Model Versioning
Models are saved with structured paths:
./comsol_models/{model_name}/{model_name}_{timestamp}.mph
./comsol_models/{model_name}/{model_name}_latest.mphExample:
./comsol_models/chip_tsv_thermal/chip_tsv_thermal_20260216_140514.mph
./comsol_models/chip_tsv_thermal/chip_tsv_thermal_latest.mphKey Technical Discoveries
1. mph Library API Patterns
# Access Java model via property (not callable)
jm = model.java # NOT model.java()
# Create component with True flag
comp = jm.component().create('comp1', True)
# Create 3D geometry
geom = comp.geom().create('geom1', 3)
# Create physics with geometry reference
physics = comp.physics().create('spf', 'LaminarFlow', 'geom1')
# Boundary condition with selection
bc = physics.create('inl1', 'InletBoundary')
bc.selection().set([1, 2, 3])
bc.set('U0', '1[mm/s]')2. Boundary Condition Property Names
Physics | Condition | Property |
Heat Transfer | HeatFluxBoundary |
|
Heat Transfer | TemperatureBoundary |
|
Heat Transfer | ConvectiveHeatFlux |
|
Laminar Flow | InletBoundary |
|
Laminar Flow | OutletBoundary |
|
3. Client Session Limitation
The mph library creates a singleton COMSOL client. Only one Client can exist per Python process:
# This is handled in session.py - client is kept alive and models are cleared
client.clear() # Clear models instead of full disconnect4. Offline Embedding Model
PDF search supports offline operation with local HuggingFace cache:
# Set mirror for China
export HF_ENDPOINT=https://hf-mirror.comDevelopment Status
Phase | Description | Status |
1 | Basic framework + Session + Model | Done |
2 | Parameters + Solving + Results | Done |
3 | Geometry + Physics + Mesh | Done |
4 | Embedded knowledge + Tool docs | Done |
5 | PDF vector retrieval | Done |
6 | Integration tests | In Progress |
Next Steps
Complete Phase 6 - Full integration test with proper boundary conditions
Visualization Export - Generate PNG images from plot groups
LSP Warnings - Fix type hints in physics.py
More Examples - Add electrostatics, solid mechanics cases
Error Handling - Improve error messages and recovery
Resources
URI | Description |
| Session information |
| Model tree structure |
| Model parameters |
| Physics interfaces |
License
MIT
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/Zhangyoupeng1996/Codex_MCP_Comsol'
If you have feedback or need assistance with the MCP directory API, please join our Discord server
