-
Notifications
You must be signed in to change notification settings - Fork 0
Installation
- Python 3.10+ (3.12 recommended for best compatibility)
- MATLAB R2022b+ installed locally (MATLAB Engine API for Python required)
- Operating Systems: Linux, macOS, or Windows 10+
- For Windows 10 no-admin deployment: No administrator rights required (the server binds to localhost by default)
Note: The MATLAB Engine API for Python comes bundled with MATLAB but requires a separate installation step. See Step 1 below.
Install the pre-built package from PyPI:
pip install matlab-mcp-pythonVerify the installation:
matlab-mcp --helpClone the repository and install in editable mode:
git clone https://github.com/HanSur94/matlab-mcp-server-python.git
cd matlab-mcp-server-python
pip install -e ".[dev]"The [dev] extras include:
- pytest, ruff (testing and code quality)
- Plotly, aiosqlite (monitoring dashboard)
For minimal install without dev/monitoring:
pip install -e .For monitoring support only (dashboard, health endpoints):
pip install -e ".[monitoring]"Create and activate a conda environment:
# Create from environment.yml (for users)
conda env create -f environment.yml
conda activate matlab-mcp
# Or create from environment-dev.yml (for developers)
conda env create -f environment-dev.yml
conda activate matlab-mcp-dev# Build the image
docker build -t matlab-mcp .
# Run with MATLAB mounted
docker run -p 8765:8765 \
-v /path/to/MATLAB:/opt/matlab:ro \
-v ./config.yaml:/etc/matlab-mcp/config.yaml:ro \
-e MATLAB_MCP_POOL_MATLAB_ROOT=/opt/matlab \
matlab-mcp
# Or use docker-compose
docker compose upImportant: The Docker image does not include MATLAB. You must mount a local MATLAB installation inside the container, or the server will run in
--inspectmode (MATLAB Engine disabled).
The MATLAB Engine API is bundled with MATLAB but requires a manual installation into your Python environment.
Locate your MATLAB installation and install the Engine API:
cd /Applications/MATLAB_R2024a.app/extern/engines/python
pip install .Tip: Replace
R2024awith your MATLAB version (e.g.,R2023b,R2022b).
cd "C:\Program Files\MATLAB\R2024a\extern\engines\python"
pip install .For Windows 10 without admin rights: Use the provided
install.batscript to automate this process:.\install.batThis script detects your Python and MATLAB installations, creates a virtual environment, and installs the Engine API with all necessary workarounds.
cd /opt/MATLAB/R2024a/extern/engines/python
pip install .python -c "import matlab.engine; print('MATLAB Engine API installed successfully')"If successful, you should see the message without errors.
Follow one of the installation methods above (PyPI, Source, Conda, or Docker).
The server uses sensible defaults. To customize, create or edit a config.yaml file:
server:
host: 127.0.0.1 # Bind to localhost (avoid firewall issues on Windows)
port: 8765
transport: stdio # stdio (single-user) or sse/streamablehttp (multi-user)
log_level: INFO
pool:
min_engines: 2
max_engines: 8
health_check_interval_s: 5
execution:
sync_timeout: 30 # Promote to async jobs after 30 seconds
security:
blocked_functions_enabled: true
monitoring:
enabled: true # Enable health/metrics dashboard at /health, /metricsSee Configuration for all available options.
matlab-mcpThe server connects to your local MATLAB via stdio. One MCP client (Claude Desktop, Cursor, etc.) can connect at a time.
matlab-mcp --transport streamablehttpThe server listens on http://127.0.0.1:8765 and supports multiple concurrent clients. Remote agents connect to the /mcp endpoint.
Generate a token:
matlab-mcp --generate-token
# Output: Bearer token: abc123def456...
# Set env var: export MATLAB_MCP_AUTH_TOKEN=abc123def456...Start the server:
export MATLAB_MCP_AUTH_TOKEN=abc123def456...
matlab-mcp --transport streamablehttpAgents must include the token in requests:
Authorization: Bearer abc123def456...
matlab-mcp --config /path/to/config.yamlEnvironment variables override config file settings (prefix MATLAB_MCP_):
export MATLAB_MCP_POOL_MIN_ENGINES=4
export MATLAB_MCP_POOL_MAX_ENGINES=16
matlab-mcpmacOS:
mkdir -p "~/Library/Application Support/Claude"
cat > "~/Library/Application Support/Claude/claude_desktop_config.json" << 'EOF'
{
"mcpServers": {
"matlab": {
"command": "matlab-mcp"
}
}
}
EOFWindows:
Create %APPDATA%\Claude\claude_desktop_config.json:
{
"mcpServers": {
"matlab": {
"command": "matlab-mcp"
}
}
}claude mcp add matlab -- matlab-mcp# Terminal 1: Start the server
matlab-mcp --transport streamablehttp
# Terminal 2: Connect Codex
codex -m http://127.0.0.1:8765/mcp \
--bearer-token YOUR_TOKEN_HERE \
--context matlabAdd to .cursor/mcp.json:
{
"mcpServers": {
"matlab": {
"command": "matlab-mcp"
}
}
}See Agent Onboarding for detailed configuration examples for each agent.
# If using streamablehttp or sse:
curl http://127.0.0.1:8765/health
# Expected response:
# {
# "status": "healthy",
# "uptime_seconds": 45,
# "engines": {"total": 2, "available": 2, "busy": 0},
# "active_jobs": 0,
# "active_sessions": 0
# }Open http://127.0.0.1:8765/dashboard in a browser (if monitoring is enabled and using HTTP transport).
import matlab.engine
eng = matlab.engine.start_matlab()
result = eng.eval("2 + 2", nargout=1)
print(result) # Should print 4.0
eng.quit()Error: ModuleNotFoundError: No module named 'matlab'
Solution:
- Verify MATLAB is installed:
ls /Applications/MATLAB_*.app(macOS) - Reinstall the Engine API:
cd .../extern/engines/python && pip install . - Check Python version:
python --version(must be 3.10+)
Error: Address already in use: ('127.0.0.1', 8765)
Solution:
# Use a different port
matlab-mcp --port 8766
# Or kill the existing process
lsof -ti:8765 | xargs kill -9 # macOS/Linux
netstat -ano | findstr :8765 # WindowsError: Agent cannot connect to http://127.0.0.1:8765
Solution:
- The default bind address is
127.0.0.1(localhost-only) to avoid firewall popups on Windows 10 - For remote access, bind to
0.0.0.0and add a Windows Firewall exception (requires admin):# config.yaml server: host: 0.0.0.0 # Allow remote connections
Error: Server appears to hang on startup
Solution:
- Start with fewer engines:
--pool-min-engines 1 - Check MATLAB license: Open MATLAB GUI to verify the license is valid
- Try inspect mode (no MATLAB):
matlab-mcp --inspect
Error: 401 Unauthorized when connecting agents
Solution:
# Verify token is set
echo $MATLAB_MCP_AUTH_TOKEN
# Generate a new token
matlab-mcp --generate-token
# Export in current shell
export MATLAB_MCP_AUTH_TOKEN="your_token_here"
matlab-mcp --transport streamablehttpFor large workloads, adjust configuration:
pool:
min_engines: 4 # Start with more engines
max_engines: 16 # Scale up to this many
health_check_interval_s: 10 # Less frequent checks = lower overhead
execution:
sync_timeout: 60 # Allow longer sync execution before async promotion
monitoring:
enabled: false # Disable metrics collection if CPU-bound# Create isolated Python environment
python -m venv .venv
source .venv/bin/activate # macOS/Linux
# .venv\Scripts\activate # Windows
# Install MATLAB Engine API into venv
cd /Applications/MATLAB_R2024a.app/extern/engines/python
pip install .
# Install server
pip install matlab-mcp-python
# or from source
git clone https://github.com/HanSur94/matlab-mcp-server-python.git
cd matlab-mcp-server-python
pip install -e ".[dev]"- Configuration — Detailed config reference
- Agent Onboarding — Connect Claude Code, Codex CLI, Cursor
- Examples — Ready-to-run MATLAB examples
- Custom Tools — Expose your own MATLAB functions
- Windows Deployment — No-admin Windows 10 setup