MCP Server for COMSOL Multiphysics simulation automation via AI agents.
COMSOL MCP Server
MCP Server for COMSOL Multiphysics simulation automation via AI agents.
English | 中文
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/wjc9011/comsol-mcp.git
cd comsol-mcp
# Install dependencies
python -m pip install -e .
# Test server
python -m src.server
Building PDF Knowledge Base
# 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 --status
Usage
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 tests
Available Tools (80+ total)
Session (4)
| Tool | Description |
|---|---|
comsol_start |
Start local COMSOL client |
comsol_connect |
Connect to remote server |
comsol_disconnect |
Clear session |
comsol_status |
Get session info |
Model (9)
| Tool | Description |
|---|---|
model_load |
Load .mph file |
model_create |
Create empty model |
model_save |
Save to file |
model_save_version |
Save with timestamp |
model_list |
List loaded models |
model_set_current |
Set active model |
model_clone |
Clone model |
model_remove |
Remove from memory |
model_inspect |
Get model structure |
Parameters (5)
| Tool | Description |
|---|---|
param_get |
Get parameter value |
| `p |
Tools (14)
comsol_startStart local COMSOL clientcomsol_connectConnect to remote servercomsol_disconnectClear sessioncomsol_statusGet session infomodel_loadLoad .mph filemodel_createCreate empty modelmodel_saveSave to filemodel_save_versionSave with timestampmodel_listList loaded modelsmodel_set_currentSet active modelmodel_cloneClone modelmodel_removeRemove from memorymodel_inspectGet model structureparam_getGet parameter valueEnvironment Variables
HF_ENDPOINTHugging Face mirror endpoint for model downloadsConfiguration
{"mcpServers": {"comsol": {"command": "python", "args": ["-m", "src.server"], "cwd": "/path/to/comsol-mcp"}}}