dolfinx-mcp
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
dolfinx-mcp
Talk to your PDE solver. An MCP server that gives AI assistants direct access to the FEniCSx/DOLFINx finite element framework. Describe a PDE in natural language and the tools handle the rest — mesh generation, function spaces, assembly, solving, and post-processing — all inside a sandboxed Docker container.
MCP Client Docker Container
(Claude, Cursor, ...) (dolfinx/dolfinx:stable)
+---------------------+ +-----------------------+
| | JSON-RPC | FastMCP Server |
| "Solve the 3D | ── stdio/http ───> | 38 Tool Handlers |
| Poisson equation" | | SessionState |
| | <───────────────── | /workspace output |
+---------------------+ +-----------------------+Quick Start
1. Build
git clone https://github.com/ekstanley/ccFenics-plugin.git
cd ccFenics-plugin
docker build -t dolfinx-mcp .2. Configure Your MCP Client
Add to your client configuration (Claude Desktop, Cursor, VS Code, etc.).
Set /path/to/workspace to the directory for simulation output (VTK, XDMF):
{
"mcpServers": {
"dolfinx": {
"command": "docker",
"args": [
"run", "--rm", "-i", "--network", "none",
"-v", "/path/to/workspace:/workspace",
"dolfinx-mcp"
]
}
}
}This repo includes .mcp.json for automatic MCP server discovery:
docker build -t dolfinx-mcp .claude(from the repo root)Start asking FEM questions — the server auto-connects
For the full FEM-aware experience (37 skills, 6 agents, 6 commands):
claude --plugin-dir ./ccfenicsBuild the Docker image:
docker build -t dolfinx-mcp .Zip the
dolfinx-assistant/folderIn Claude Desktop, go to Customize > Add Plugin > upload the zip
The 38 MCP tools become available in your Cowork session.
3. Use
Ask your AI assistant to solve a PDE:
"Create a 16x16 unit square mesh and solve the Poisson equation with f = 2pi^2 sin(pi x) sin(pi y), then compute the L2 error."
Related MCP server: openfoam-mcp
Example: 3D Poisson on Unit Cube
A Jupyter notebook demonstrating a full 3D workflow is at
examples/3d_poisson_demo.ipynb.
Problem: $-\nabla^2 u = 3\pi^2 \sin(\pi x)\sin(\pi y)\sin(\pi z)$ on $[0,1]^3$, $u=0$ on boundary.
Metric | Result |
Mesh | 16x16x16 tetrahedra (24,576 cells, 4,913 vertices) |
Space | P2 Lagrange (35,937 DOFs) |
Solver | CG + Hypre AMG |
max(u_h) | 1.000056 (expected 1.0) |
L2 error | 1.21e-05 |
H1 error | 1.15e-03 |
Orthogonal slices through the solution field at x=0.5, y=0.5, z=0.5:

Iso-surfaces at u = 0.2, 0.5, 0.8 (nested concentric level sets):

Supported Problems
Category | PDE Types |
Elliptic | Poisson, Helmholtz, mixed Poisson (RT elements), singular Poisson (nullspace), complex-valued |
Parabolic | Heat equation, Cahn-Hilliard, Allen-Cahn |
Flow | Stokes (Taylor-Hood), Navier-Stokes (IPCS) |
Solid Mechanics | Linear elasticity, hyperelasticity (neo-Hookean), membrane deflection |
Electromagnetics | H(curl) formulations with Nedelec edge elements |
Special | Biharmonic (C/IP-DG), discontinuous Galerkin, eigenvalue (SLEPc), axisymmetric |
Boundary conditions: Dirichlet, Neumann, Robin, Nitsche (weak), component-wise, multi-region. Elements: Lagrange (P1-P5), DG, Nedelec, Raviart-Thomas, BDM, Crouzeix-Raviart, mixed. Solvers: Direct (LU, MUMPS), iterative (CG, GMRES, BiCGSTAB) with preconditioners (ILU, Hypre AMG, Jacobi), Newton (SNES), time-stepping (Euler, Crank-Nicolson).
Tools (38)
Mesh Operations (9)
Tool | Description |
| Unit square mesh with triangular or quadrilateral elements |
| Rectangle or box meshes with custom dimensions |
| Import mesh from Gmsh (.msh) file |
| Inspect mesh properties (cells, vertices, bounding box) |
| Mesh quality metrics (aspect ratio, volume) |
| Tag boundary facets using coordinate expressions |
| Create and manage cell/facet region markers |
| Uniformly refine an existing mesh |
| Extract submesh from tagged regions |
Function Spaces (2)
Tool | Description |
| Lagrange, DG, Nedelec, RT, BDM, or CR elements (degree 1-5) |
| Mixed function space from component subspaces |
Problem Definition (3)
Tool | Description |
| Define material coefficients and source terms |
| Bilinear and linear forms via UFL expressions |
| Dirichlet boundary conditions (value + locator) |
Solvers (5)
Tool | Description |
| Direct (LU, MUMPS) or iterative (CG, GMRES) with preconditioners |
| Time stepping: backward/forward Euler, Crank-Nicolson |
| Newton solver (SNES) for nonlinear PDEs |
| Generalized eigenvalue problems via SLEPc |
| Convergence info, iterations, residual norms |
Post-processing (6)
Tool | Description |
| L2 or H1 error against an exact solution |
| Evaluate solution at specified coordinates |
| Point queries with geometric cell info |
| Integrate UFL expressions over the domain |
| Export to XDMF or VTK format |
| Contour or warp plots (PNG via PyVista) |
Interpolation (4)
Tool | Description |
| Create a function in a space, optionally initialized with an expression |
| Interpolate UFL expression into a function space |
| L2-project an expression onto a function space |
| Build a discrete operator matrix |
Session Management (9)
Tool | Description |
| List all registered meshes, spaces, functions, solutions |
| Clear all session state |
| Execute Python code with persistent namespace across calls |
| Assemble UFL forms into scalars, vectors, or matrices |
| Remove an object with cascade deletion of dependents |
| Read files from /workspace/ as base64 (images) or text (VTK, CSV) |
| List files in /workspace/ matching glob patterns |
| Package workspace files into a ZIP archive |
| Generate an HTML simulation report with plots and diagnostics |
Claude Code Plugin
The ccfenics/ directory adds FEM domain intelligence on top of the 38 MCP tools.
Load it with claude --plugin-dir ./ccfenics.
Agents (6)
Agent | What it does |
| End-to-end PDE solve pipeline (mesh to post-processing) |
| Automated mesh refinement with convergence rate fitting |
| Newton method with load stepping and convergence diagnostics |
| Transient PDE workflows (initial conditions, time stepping, output) |
| Complex BC configuration (Dirichlet, Neumann, Robin, Nitsche) |
| Mesh quality analysis and refinement recommendations |
Skills (37)
Guided workflows for every supported PDE type, plus solver selection, element selection, and debugging. Triggered automatically when you describe a problem:
"Solve a Stokes flow problem" →
fem-workflow-stokes"My solver diverged" →fem-debugging
Commands (6)
Command | Description |
| End-to-end Poisson solve with manufactured solution |
| Walk through a DOLFINx tutorial chapter step-by-step |
| Run the test suite with coverage |
| Audit Design-by-Contract compliance |
| Scaffold a new MCP tool |
| Check Docker, container, and server status |
MCP Protocol
Prompt Templates (6)
Prompt | Description |
| Guided Poisson equation setup |
| Linear elasticity problem workflow |
| Stokes flow with mixed elements |
| Navier-Stokes with time stepping |
| Diagnose solver convergence failures |
| h-refinement convergence rate study |
Resources (6)
URI | Content |
| Element families, solvers, export formats |
| JSON schema for mesh objects |
| JSON schema for function space objects |
| JSON schema for solution objects |
| Current session state summary |
| Available solver and preconditioner options |
Transport Modes
Mode | Command | Use Case |
stdio (default) |
| CLI clients, Claude Desktop |
streamable-http |
| Web clients, JupyterLab |
sse |
| Legacy SSE clients |
JupyterLab Integration
Start with Docker Compose:
docker-compose -f docker-compose.lab.yml up --build
# Open http://localhost:8888Or install directly:
pip install dolfinx-mcp[jupyter]Use IPython magics inside JupyterLab:
%load_ext dolfinx_mcp_jupyter
%mcp_config url=http://localhost:8000/mcp
%mcp create_unit_square name=mesh nx=16 ny=16
%mcp create_function_space name=V family=Lagrange degree=1
%mcp solve solver_type=direct
%mcp compute_error exact="sin(pi*x[0])*sin(pi*x[1])" norm_type=L2Design-by-Contract
All 38 tools enforce runtime contracts:
Preconditions: Input validation (parameter types, ranges, existence checks)
Postconditions: Output validation (return structure, value constraints)
Invariants: 9 referential integrity invariants on SessionState
Contract violations return structured error responses:
{
"error": "PRECONDITION_VIOLATED",
"message": "Mesh 'box' not found in session",
"suggestion": "Create a mesh first with create_unit_square or create_mesh"
}Error codes: NO_ACTIVE_MESH, MESH_NOT_FOUND, FUNCTION_SPACE_NOT_FOUND,
FUNCTION_NOT_FOUND, INVALID_UFL_EXPRESSION, SOLVER_ERROR, DUPLICATE_NAME,
DOLFINX_API_ERROR, FILE_IO_ERROR, PRECONDITION_VIOLATED,
POSTCONDITION_VIOLATED, INVARIANT_VIOLATED.
Formal Verification (Lean 4)
8 of the 9 referential integrity invariants are formally verified in Lean 4
with machine-checked proofs. INV-9 (FormInfo.trial_space_name) is specified
in Quint and enforced at runtime.
20 theorems, 4 helper lemmas, zero sorry placeholders.
Theorem | What it proves |
| Empty session satisfies all 8 invariants |
| Adding a mesh preserves invariants |
| Adding a function space preserves invariants |
| Cascade deletion of mesh + dependents preserves invariants |
| Removing space dependents preserves invariants |
| Session reset produces a valid state |
| Output path validation is a containment check |
| All 13 error codes are pairwise distinct |
Verify locally (requires Lean 4):
cd .outline/proofs/DolfinxProofs
lake build # exits 0, zero warningsSecurity
Three-layer defense for UFL expression evaluation:
Token blocklist —
_check_forbidden()rejectsimport,__,exec,eval,open,os.,subprocess, and 12 more tokens at parse timeEmpty
__builtins__— expression namespaces have no access to Python internalsDocker isolation — container runs with
--network none, non-root user,--rm
run_custom_code intentionally bypasses the blocklist (full __builtins__).
Docker isolation is the sole boundary for custom code execution.
See SECURITY.md for vulnerability reporting.
Development
pip install -e ".[dev]"# Unit tests (no Docker, ~417 tests)
pytest tests/ \
--ignore=tests/test_runtime_contracts.py \
--ignore=tests/test_tutorial_workflows.py \
--ignore=tests/test_edge_case_contracts.py \
--ignore=tests/test_poisson_workflow.py
# Docker integration tests (514 tests across 6 suites)
docker build -t dolfinx-mcp .
./scripts/run-docker-tests.sh
# Lint & type check
ruff check src/
pyright src/dolfinx_mcp/Project Structure
src/dolfinx_mcp/
server.py Entry point
_app.py FastMCP instance + lifespan
session.py SessionState (8 registries, 9 invariants)
errors.py 13 error classes + decorator
ufl_context.py Restricted UFL expression evaluation
tools/
mesh.py 9 mesh tools
spaces.py 2 function space tools
problem.py 3 problem definition tools
solver.py 5 solver tools
postprocess.py 6 post-processing tools
interpolation.py 4 interpolation tools
session_mgmt.py 9 session management tools
prompts/templates.py 6 workflow prompts
resources/providers.py 6 URI resources
src/dolfinx_mcp_jupyter/ JupyterLab extension (5 IPython magics)
tests/ 18 test files, ~514 tests (417 unit + 97 Docker-only)
examples/ 3D Poisson notebook + production readiness suite
.outline/proofs/ Lean 4 formal verification (20 theorems)
ccfenics/ Claude Code plugin (37 skills, 6 agents, 6 commands)Contributing
See CONTRIBUTING.md for development setup, code style, and the new tool checklist.
License
MIT
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Run FDS, OpenFOAM, CalculiX and other engineering simulations on cloudHPC from your AI assistant.
AI-callable calculators and engineering models with real formulas. No hallucinated math.
Build, validate, and deploy multi-agent AI solutions from any AI environment.
Parametric 3D CAD for AI agents: build print-ready parts, check them, export STL, 3MF or STEP.
Related MCP Servers
- AlicenseBqualityBmaintenanceEnables AI assistants to drive Kratos Multiphysics finite element simulations end to end, including introspection, scaffolding, execution, and post-processing.1132MIT
- AlicenseNot gradedqualityCmaintenanceTurns an AI assistant into an OpenFOAM setup and debugging co-pilot, enabling case scaffolding, dictionary edits, mesh sizing, turbulence calculations, and solver log analysis through natural language.MIT
- AlicenseAqualityBmaintenanceThe official MCP interface for AgentFEM, giving AI agents seven typed tools to create, validate, run, inspect, and verify finite-element simulations while preserving scientific evidence.744 PyPI1Apache 2.0
- AlicenseNot gradedqualityCmaintenanceEnables coding agents to run bounded COMSOL simulations with contract validation, model inspection, provenance tracking, and deterministic verifier feedback.2MIT