-
Notifications
You must be signed in to change notification settings - Fork 0
Installation
- Python 3.10+ (3.12 recommended for best performance)
- MATLAB R2022b or later (R2024a or later recommended)
- MATLAB Engine API for Python — included with MATLAB, requires separate installation into Python
- Operating Systems: Linux, macOS (Intel/Apple Silicon), Windows 10+ (no admin required)
Verify your MATLAB installation:
# macOS/Linux
ls /opt/matlab/bin/matlab # or /Applications/MATLAB_R*.app/bin/matlab
# Windows
where matlab.exeThe easiest installation path for Windows, macOS, and Linux.
python -m venv .venv
source .venv/bin/activate # macOS/Linux
# or
.venv\Scripts\activate # WindowsThe MATLAB Engine API must be installed into your Python environment first.
macOS:
cd /Applications/MATLAB_R2024a.app/extern/engines/python
pip install .Replace
R2024awith your MATLAB version (e.g.,R2023b,R2024b).
Linux:
cd /opt/matlab/extern/engines/python
pip install .
# If MATLAB is in a non-standard location:
cd <MATLAB_ROOT>/extern/engines/python
pip install .Windows:
cd "C:\Program Files\MATLAB\R2024a\extern\engines\python"
pip install .Verify the installation:
import matlab.engine
print("MATLAB Engine API installed successfully")pip install matlab-mcp-pythonOptional: Install monitoring extras (for dashboard and health endpoints):
pip install 'matlab-mcp-python[monitoring]'Optional: Install dev extras (for testing and development):
pip install 'matlab-mcp-python[dev]'matlab-mcp --helpYou should see the command-line options. Continue to #Verification Steps to test connectivity.
For development, contributions, or custom configurations.
git clone https://github.com/HanSur94/matlab-mcp-server-python.git
cd matlab-mcp-server-pythonpython -m venv .venv
source .venv/bin/activate # macOS/Linux
# or
.venv\Scripts\activate # Windows
# Install MATLAB Engine API (see Method 1, Step 2 for platform-specific paths)
cd /Applications/MATLAB_R2024a.app/extern/engines/python
pip install .
cd /path/to/matlab-mcp-server-python# Minimal installation (core only)
pip install -e .
# With monitoring support
pip install -e '.[monitoring]'
# With all dev and test dependencies
pip install -e '.[dev]'pytest tests/ -vExpected: 750+ tests pass. If MATLAB is not available, mocked tests still run (marked with @pytest.mark.matlab are skipped).
A one-click installer for Windows users without admin rights.
Download install.bat from the project repository.
install.batThe installer will:
- Detect Python 3.10+ in your PATH
- Locate MATLAB R2022b or later
- Create a virtual environment
- Install the MATLAB Engine API
- Install matlab-mcp-python
- Register with Windows Task Scheduler (optional)
Notes:
- No administrator rights required
- If MATLAB is not found, you can specify the path manually
- The installer creates a
.venvdirectory in the current folder
For containerized deployments or CI/CD pipelines.
- Docker 20.10+
- MATLAB installation available on the host (must be mounted into the container)
docker build -t matlab-mcp:latest .# Single instance with stdio transport
docker run -it --rm \
-e MATLAB_MCP_POOL_MATLAB_ROOT=/opt/matlab \
matlab-mcp:latest
# Multi-user with streamable HTTP transport
docker run -d --rm \
-p 8765:8765 \
-e MATLAB_MCP_POOL_MATLAB_ROOT=/opt/matlab \
-e MATLAB_MCP_SERVER_TRANSPORT=streamablehttp \
-e MATLAB_MCP_AUTH_TOKEN=$(python -c "import secrets; print(secrets.token_hex(32))") \
matlab-mcp:latestEdit docker-compose.yml to set your MATLAB path, then:
docker compose upImportant Notes on Docker:
graph LR
A["Docker Container<br/>(matlab-mcp)"] -->|requires| B["MATLAB Installation<br/>(host mount)"]
A -->|reads| C["MATLAB_MCP_POOL_MATLAB_ROOT<br/>environment variable"]
B -->|mounted at| D["/opt/matlab"]
C -->|points to| D
- The Docker image does not include MATLAB. You must provide MATLAB via a host mount.
- Set
MATLAB_MCP_POOL_MATLAB_ROOT=/opt/matlab(or your mount path) as an environment variable. - For remote connections, use
streamablehttptransport with bearer token authentication (see #Authentication Setup below).
Example with authentication:
export MATLAB_MCP_AUTH_TOKEN=$(python -c "import secrets; print(secrets.token_hex(32))")
docker run -d \
-p 8765:8765 \
-v /opt/MATLAB/R2024a:/opt/matlab:ro \
-e MATLAB_MCP_POOL_MATLAB_ROOT=/opt/matlab \
-e MATLAB_MCP_SERVER_TRANSPORT=streamablehttp \
-e MATLAB_MCP_AUTH_TOKEN=$MATLAB_MCP_AUTH_TOKEN \
matlab-mcp:latestThe server supports three transport modes:
graph TB
subgraph Transports
A["stdio<br/>(Default)"]
B["sse<br/>(Deprecated)"]
C["streamablehttp<br/>(Recommended)"]
end
subgraph Use_Case
A --> A1["Single local agent"]
B --> B1["Multiple remote agents<br/>Legacy support"]
C --> C1["Multiple agents<br/>Load-balanced setup"]
end
Best for local development and single-user deployments.
matlab-mcp --transport stdio- No network overhead
- Simple setup (no config needed)
- Single agent per instance
- Used by Claude Desktop, Cursor, local testing
Best for team deployments and remote agents like Codex CLI.
matlab-mcp --transport streamablehttp --host 127.0.0.1 --port 8765Configuration in config.yaml:
server:
transport: streamablehttp
host: 127.0.0.1 # Loopback for no-admin on Windows; change to 0.0.0.0 for network access
port: 8765
sessions:
max_sessions: 10 # Limit concurrent agents
session_timeout: 3600 # Auto-cleanup after 1 hour idle- Multiple concurrent agents
- HTTP/WebSocket-based
- Requires authentication (see #Authentication Setup)
- Agents connect to
http://localhost:8765/mcp - Stateless mode available for load balancing (
stateless_http: true)
Server-Sent Events transport (kept for backward compatibility).
matlab-mcp --transport sse --host 0.0.0.0 --port 8765Status: Deprecated as of v2.0. Use streamablehttp for new deployments. Existing SSE clients continue to work with a deprecation warning logged at startup.
Authentication is required for streamablehttp transport. Bearer tokens sourced from environment variables only (not config files).
matlab-mcp --generate-tokenOutput example:
Generated bearer token: a3f7c2e9d1b5a8f4c6e2d9b1a3f5c7e9
# macOS/Linux: Add to your shell profile
export MATLAB_MCP_AUTH_TOKEN="a3f7c2e9d1b5a8f4c6e2d9b1a3f5c7e9"
# Windows Command Prompt
set MATLAB_MCP_AUTH_TOKEN=a3f7c2e9d1b5a8f4c6e2d9b1a3f5c7e9
# Windows PowerShell
$env:MATLAB_MCP_AUTH_TOKEN = "a3f7c2e9d1b5a8f4c6e2d9b1a3f5c7e9"
macOS/Linux:
export MATLAB_MCP_AUTH_TOKEN="a3f7c2e9d1b5a8f4c6e2d9b1a3f5c7e9"Or add to ~/.bashrc or ~/.zshrc for persistence:
echo 'export MATLAB_MCP_AUTH_TOKEN="a3f7c2e9d1b5a8f4c6e2d9b1a3f5c7e9"' >> ~/.bashrc
source ~/.bashrcWindows Command Prompt:
set MATLAB_MCP_AUTH_TOKEN=a3f7c2e9d1b5a8f4c6e2d9b1a3f5c7e9To persist, use:
setx MATLAB_MCP_AUTH_TOKEN "a3f7c2e9d1b5a8f4c6e2d9b1a3f5c7e9"Windows PowerShell:
$env:MATLAB_MCP_AUTH_TOKEN = "a3f7c2e9d1b5a8f4c6e2d9b1a3f5c7e9"To persist:
[Environment]::SetEnvironmentVariable("MATLAB_MCP_AUTH_TOKEN", "a3f7c2e9d1b5a8f4c6e2d9b1a3f5c7e9", "User")# Token is automatically read from MATLAB_MCP_AUTH_TOKEN
matlab-mcp --transport streamablehttpExpected output:
Starting MATLAB MCP Server v1.5.0...
[INFO] Loaded MATLAB Engine API
[INFO] Pool: 2 min, 10 max engines
[WARNING] Bearer token authentication enabled
[INFO] HTTP endpoint: http://127.0.0.1:8765/mcp
[INFO] Dashboard: http://127.0.0.1:8765/dashboard
See Agent-Onboarding for connection examples with bearer token headers for Claude Code, Codex CLI, and Cursor.
matlab-mcp --transport stdioIn another terminal:
import json
import subprocess
# Start server (if not already running)
proc = subprocess.Popen(['matlab-mcp', '--transport', 'stdio'],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True)
# Send MCP initialize request
request = {
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2024-11-05",
"capabilities": {},
"clientInfo": {"name": "test-client", "version": "1.0.0"}
}
}
proc.stdin.write(json.dumps(request) + '\n')
proc.stdin.flush()
# Read response (first line)
response = json.loads(proc.stdout.readline())
assert response['result']['protocolVersion'] == "2024-11-05"
assert 'tools' in response['result']
print("✓ Server initialized successfully")
print(f"✓ Available tools: {len(response['result']['tools'])}")
proc.terminate()Expected output:
✓ Server initialized successfully
✓ Available tools: 20
# Terminal 1: Start server
export MATLAB_MCP_AUTH_TOKEN="your-token-here"
matlab-mcp --transport streamablehttp --host 127.0.0.1 --port 8765
# Terminal 2: Test health endpoint
curl -H "Authorization: Bearer your-token-here" \
http://127.0.0.1:8765/health
# Expected response:
# {"status": "healthy", "uptime": 0.5, ...}# Check that tools are registered
curl -H "Authorization: Bearer your-token-here" \
http://127.0.0.1:8765/mcp/tools
# Expected: JSON with 20+ tools including execute_code, get_workspace, list_toolboxesOpen in browser: http://127.0.0.1:8765/dashboard (authentication not required for dashboard)
Expected: Real-time metrics with pool utilization, active jobs, session counts.
pytest tests/ -v --tb=shortExpected: 750+ tests pass.
If MATLAB Engine is not available, ~150 tests are skipped (marked @pytest.mark.matlab), but mocked tests still run.
Engine Limit:
MATLAB on macOS has a hard limit of 4 concurrent engines. The server will log a warning if configured higher:
[WARNING] Pool max_engines=8 exceeds macOS limit of 4. Capping to 4.
Solution: Set max_engines: 4 in config.yaml for macOS deployments.
Apple Silicon (M1/M2/M3):
MATLAB R2023b and later have native ARM64 support. Earlier versions use Rosetta translation. Verify:
matlab -nojvm -batch "arch"
# Output: arm64 (native) or x86_64 (translated)No Admin Required:
The server defaults to host: 127.0.0.1 (loopback only) to avoid Windows Firewall prompts. No elevated permissions are needed.
Firewall Access:
If you need remote access, change host: 0.0.0.0 in config.yaml. Windows Firewall will prompt once on first run; allow Python through.
Virtual Environments:
Always use a virtual environment on Windows:
python -m venv .venv
.venv\Scripts\activate
pip install matlab-mcp-pythonMATLAB Path:
If MATLAB is installed to a non-standard location, set:
export MATLAB_MCP_POOL_MATLAB_ROOT=/opt/matlab/R2024a
matlab-mcpOr in config.yaml:
pool:
matlab_root: /opt/matlab/R2024aUbuntu/Debian Specifics:
Install MATLAB Engine API dependencies:
sudo apt-get install python3-devProblem: MATLAB Engine API not installed.
Solution:
cd /Applications/MATLAB_R2024a.app/extern/engines/python
pip install .Verify:
import matlab.engine
print("OK")Problem: MATLAB executable not in system PATH.
Solution: Explicitly set the MATLAB root:
export MATLAB_MCP_POOL_MATLAB_ROOT=/opt/matlab/R2024a # Linux
export MATLAB_MCP_POOL_MATLAB_ROOT=/Applications/MATLAB_R2024a.app # macOS
set MATLAB_MCP_POOL_MATLAB_ROOT=C:\Program Files\MATLAB\R2024a # Windows
matlab-mcpProblem: Server failed to bind to port 8765.
Causes:
- Port already in use
- Firewall blocking (Windows)
- Insufficient permissions for port <1024 (Linux)
Solution:
# Find what's using port 8765
lsof -i :8765 # macOS/Linux
netstat -ano | findstr :8765 # Windows
# Use a different port
matlab-mcp --port 9000Problem: MATLAB Engine taking too long to start.
Causes:
- Network drive access (MATLAB on mounted paths)
- Slow system or high load
- First-time MATLAB activation
Solution:
# Increase timeout in config.yaml
pool:
engine_start_timeout: 300 # 5 minutes instead of default 2 minutesProblem: Tests fail with async/await issues.
Solution: Ensure pytest-asyncio is installed:
pip install pytest-asyncio
python -m pytest tests/ -v-
Quick Start: Run
matlab-mcpand connect your agent (see Agent-Onboarding) - Configuration: Customize pool size, timeout, and paths (see Configuration)
- Monitoring: Enable the dashboard for real-time metrics (see Configuration#Monitoring)
- Custom Tools: Expose your own MATLAB functions (see Custom-Tools)