-
Notifications
You must be signed in to change notification settings - Fork 0
Installation
- Python 3.10+ (3.11 and 3.12 recommended)
- MATLAB R2022b or newer installed locally
- MATLAB Engine API for Python — included with MATLAB, requires separate installation
If you're familiar with Python and MATLAB, here's the fastest path:
# 1. Install MATLAB Engine API (macOS example)
cd /Applications/MATLAB_R2024a.app/extern/engines/python && pip install .
# 2. Install MATLAB MCP Server
pip install matlab-mcp
# 3. Run (single-user stdio transport)
matlab-mcp
# 4. Connect via Claude Desktop, Cursor, or Claude CodeThe MATLAB Engine API allows Python to call MATLAB functions. It ships with MATLAB but must be installed into your Python environment.
graph LR A["MATLAB Installation(R2022b+)"] -->|contains| B["Engine API Source
(extern/engines/python)"] B -->|pip install| C["MATLAB Engine API
(in your Python env)"] C -->|enables| D["matlab.engine
module"]
# Locate your MATLAB installation
ls /Applications/MATLAB_*.app/
# Install the Engine API (adjust version as needed)
cd /Applications/MATLAB_R2024a.app/extern/engines/python
pip install .# Locate MATLAB (typically C:\Program Files\MATLAB\)
cd "C:\Program Files\MATLAB\R2024a\extern\engines\python"
pip install .Or if Python is in your PATH:
python -c "import os; import matlab.engine; print(matlab.engine.__file__)"cd /usr/local/MATLAB/R2024a/extern/engines/python
pip install .python -c "import matlab.engine; eng = matlab.engine.start_matlab(); print('Success'); eng.quit()"If this hangs, see Troubleshooting below.
Choose your installation method based on your use case:
pip install matlab-mcpThis installs the stable released version with all required dependencies.
git clone https://github.com/HanSur94/matlab-mcp-server-python.git
cd matlab-mcp-server-python
pip install -e .Use pip install -e ".[dev]" to include development tools (testing, linting, documentation generation).
For monitoring support (health dashboard, metrics), add the monitoring extra:
pip install -e ".[monitoring]"Create a Dockerfile or use docker-compose.yml:
# Using docker-compose (edit docker-compose.yml to mount your MATLAB)
docker compose up
# Or build and run manually
docker build -t matlab-mcp:latest .
docker run -p 8765:8765 -p 8766:8766 \
-v /path/to/MATLAB:/opt/matlab:ro \
-e MATLAB_MCP_POOL_MATLAB_ROOT=/opt/matlab \
matlab-mcp --transport streamablehttpDocker Requirement: You must mount your own MATLAB installation. The container does not include MATLAB itself (it's a proprietary binary).
For most users, the defaults work out of the box. But for advanced setups (multi-user, custom security, monitoring), create ~/.matlab_mcp/config.yaml:
# config.yaml - MATLAB MCP Server Configuration
server:
transport: streamablehttp # "stdio" (single-user), "sse" (deprecated), or "streamablehttp" (multi-user HTTP)
host: 127.0.0.1 # Loopback by default (no firewall issues on Windows)
port: 8765
pool:
min_engines: 2 # Minimum idle engines
max_engines: 4 # Maximum total engines
engine_timeout: 120 # Shutdown idle engines after 120s
execution:
sync_timeout: 10 # Inline execution timeout (seconds)
async_timeout: 300 # Background job timeout (seconds)
security:
blocked_functions:
- "system"
- "eval"
- "!"
max_upload_size: 100_000_000 # 100 MBOr set via environment variables:
export MATLAB_MCP_SERVER_TRANSPORT=streamablehttp
export MATLAB_MCP_SERVER_HOST=0.0.0.0 # For remote access (requires firewall rule)
export MATLAB_MCP_POOL_MAX_ENGINES=8See Configuration for all options.
# Single-user (stdio transport - recommended for local development)
matlab-mcp
# Multi-user HTTP (recommended for teams/clusters)
matlab-mcp --transport streamablehttp
# With custom config
matlab-mcp --config ~/.matlab_mcp/config.yaml
# Generate a bearer token for authentication
matlab-mcp --generate-tokenThe server will start and display connection information:
[INFO] MATLAB MCP Server starting...
[INFO] Transport: stdio
[INFO] MATLAB pool: 1 min, 2 max engines
[INFO] Health check: http://127.0.0.1:8765/health
[INFO] Dashboard: http://127.0.0.1:8766/dashboard
-
Find your Claude config file:
-
macOS:
~/Library/Application Support/Claude/claude_desktop_config.json -
Windows:
%APPDATA%\Claude\claude_desktop_config.json
-
macOS:
-
Add the server:
{
"mcpServers": {
"matlab": {
"command": "matlab-mcp"
}
}
}- Restart Claude Desktop. The MATLAB tools will appear in the Tools panel.
Add to .cursor/mcp.json in your project:
{
"mcpServers": {
"matlab": {
"command": "matlab-mcp"
}
}
}- Generate a token:
matlab-mcp --generate-token
# Output: Token: abc123...
# export MATLAB_MCP_AUTH_TOKEN="abc123..."- Start the server with HTTP transport:
export MATLAB_MCP_AUTH_TOKEN="abc123..."
matlab-mcp --transport streamablehttp
# Output: HTTP endpoint: http://127.0.0.1:8765/mcp- In Claude Code, add server:
- Name:
matlab - URL:
http://127.0.0.1:8765/mcp - Authorization:
Bearer abc123...
- Name:
Codex CLI requires streamable HTTP transport with bearer token auth:
# Terminal 1: Start server with auth
export MATLAB_MCP_AUTH_TOKEN=$(matlab-mcp --generate-token | grep "Token:" | cut -d' ' -f2)
matlab-mcp --transport streamablehttp
# Terminal 2: Connect Codex CLI
export CODEX_MCP_AUTH_HEADER="Authorization: Bearer $MATLAB_MCP_AUTH_TOKEN"
codex --mcp http://127.0.0.1:8765/mcpSee Agent Onboarding for detailed examples.
After installation, verify everything works:
# Test 1: MATLAB Engine API
python -c "import matlab.engine; print('✓ MATLAB Engine API installed')"
# Test 2: MCP Server imports
python -c "from matlab_mcp.server import main; print('✓ MCP Server imports OK')"
# Test 3: Start server (Ctrl+C to stop)
matlab-mcp --inspect
# Expected output:
# [INFO] MATLAB MCP Server starting...
# [INFO] Inspect mode: pool disabled
# [INFO] Tools: execute_code, get_workspace, list_toolboxes, ...
# Listening on stdioIf you see errors, skip to Troubleshooting.
graph TD A["What's your use case?"] --> B{Single User?} B -->|Yes - Local Dev| C["pip install matlab-mcp
Run: matlab-mcp"] B -->|No - Team/Server| D{Network Access?} D -->|Local Only| E["pip install matlab-mcp
Run: matlab-mcp --transport streamablehttp"] D -->|Remote Access| F["pip install matlab-mcp
Generate token
Configure firewall
Run with --transport streamablehttp"] B -->|Yes - Isolated| G["Docker + docker-compose
Mount MATLAB
Run: docker compose up"]
Problem: ERROR: Could not find a version that satisfies the requirement matlab-engine
Solution: The MATLAB Engine API is not on PyPI. Install directly from your MATLAB installation:
# macOS
cd /Applications/MATLAB_R2024a.app/extern/engines/python && pip install .
# Windows (run as your normal user, no admin required)
cd "C:\Program Files\MATLAB\R2024a\extern\engines\python" && pip install .
# Linux
cd /usr/local/MATLAB/R2024a/extern/engines/python && pip install .If MATLAB is installed elsewhere, adjust the path.
Problem: Running matlab.engine.start_matlab() hangs for 30+ seconds.
Cause: MATLAB needs to initialize the JVM and engine. This is normal on first startup.
Solution:
- Set a timeout:
matlab.engine.start_matlab(background=True) - Reduce startup time on macOS by disabling certain toolboxes in your MATLAB preferences
Problem: Server starts but says "ERROR: No MATLAB installation detected"
Solution: Set the MATLAB root explicitly:
export MATLAB_MCP_POOL_MATLAB_ROOT="/Applications/MATLAB_R2024a.app" # macOS
export MATLAB_MCP_POOL_MATLAB_ROOT="C:\\Program Files\\MATLAB\\R2024a" # Windows
matlab-mcpProblem: Remote agents can't connect to http://127.0.0.1:8765/mcp
Solution: This is expected for loopback binding (127.0.0.1). For remote access:
-
Bind to
0.0.0.0:export MATLAB_MCP_SERVER_HOST=0.0.0.0 matlab-mcp --transport streamablehttp -
Windows Firewall will ask for permission. Click Allow (requires standard user interaction once).
-
Or add a firewall rule (requires admin):
netsh advfirewall firewall add rule name="MATLAB MCP" dir=in action=allow program="%ProgramFiles%\Python312\python.exe" enable=yes
Problem: Agents get 401 Unauthorized when connecting to --transport streamablehttp
Solution: Generate and use a bearer token:
# Generate token
TOKEN=$(matlab-mcp --generate-token | grep "Token:" | cut -d' ' -f2)
export MATLAB_MCP_AUTH_TOKEN="$TOKEN"
matlab-mcp --transport streamablehttp
# Client side (e.g., Claude Code)
# Set Authorization header to: Bearer $TOKENProblem: Docker container starts but MATLAB engine won't initialize
Solution: Mount MATLAB and set the path:
docker run -p 8765:8765 \
-v /path/to/MATLAB:/opt/matlab:ro \
-e MATLAB_MCP_POOL_MATLAB_ROOT=/opt/matlab \
matlab-mcp --transport streamablehttpReplace /path/to/MATLAB with your actual MATLAB installation path:
-
macOS:
/Applications/MATLAB_R2024a.app -
Windows:
C:\\Program Files\\MATLAB\\R2024a -
Linux:
/usr/local/MATLAB/R2024a
See Troubleshooting or open an issue on GitHub.
-
Configuration: Customize server behavior in
config.yaml -
Custom Tools: Expose your own MATLAB functions via
custom_tools.yaml - Examples: See ready-to-run MATLAB code in Examples
- Security: Learn about code validation and authentication in Security
- Architecture: Deep dive into the Architecture