-
Notifications
You must be signed in to change notification settings - Fork 0
Installation
- Python 3.10+ (3.12 recommended)
- MATLAB R2022b+ with the MATLAB Engine API for Python installed
- For Windows without admin: Port 1024+ (default 8765 is OK)
- For Docker deployments: Docker 20.10+ and docker-compose 2.0+
The MATLAB Engine API allows Python to call MATLAB. This is required and separate from MATLAB itself.
graph LR
A["MATLAB<br/>Installation"] -->|contains| B["extern/engines/python"]
B -->|pip install| C["MATLAB Engine<br/>for Python"]
C -->|imported by| D["matlab_mcp server"]
D -->|controls| E["MATLAB processes"]
cd /Applications/MATLAB_R2024a.app/extern/engines/python
pip install .Adjust version in path:
R2023b,R2024a,R2024b, etc.
cd "C:\Program Files\MATLAB\R2024a\extern\engines\python"
pip install .cd /usr/local/MATLAB/R2024a/extern/engines/python
pip install .import matlab.engine
eng = matlab.engine.start_matlab()
result = eng.eval("2 + 2", nargout=1)
print(result) # Should print 4.0
eng.quit()If this works, you're ready for the next step.
pip install matlab-mcp-pythonVerify:
matlab-mcp --helpgit clone https://github.com/HanSur94/matlab-mcp-server-python.git
cd matlab-mcp-server-python
pip install -e ".[dev]"The [dev] extra includes pytest, ruff, and coverage tools for testing. For a minimal install without dev dependencies, use pip install -e . instead. To include only monitoring support (dashboard, health endpoint), use pip install -e ".[monitoring]".
# Create environment from conda file
conda env create -f environment.yml
# Or create and install manually
conda create -y -n matlab-mcp python=3.12
conda activate matlab-mcp
pip install matlab-engine
pip install matlab-mcp-pythongit clone https://github.com/HanSur94/matlab-mcp-server-python.git
cd matlab-mcp-server-python
# Build image
docker build -t matlab-mcp .
# Run with mounted MATLAB installation
docker run -it -p 8765:8765 \
-v /path/to/MATLAB:/opt/matlab:ro \
-e MATLAB_ROOT=/opt/matlab \
matlab-mcpOr with Docker Compose (edit docker-compose.yml to set your MATLAB path):
docker-compose upNote: The Docker image does not include MATLAB. You must provide your own MATLAB installation as a mount point.
git clone https://github.com/HanSur94/matlab-mcp-server-python.git
cd matlab-mcp-server-python
install.batThe install.bat script:
- Auto-detects Python and MATLAB installations
- Installs MATLAB Engine API
- Creates a Python virtual environment
- Installs the server and all dependencies
- Works fully offline from bundled wheels
- Requires no admin rights on Windows 10/11
# Start server in inspect mode (no MATLAB needed for this test)
matlab-mcp --inspect
# In another terminal, test via Python
python -c "
from matlab_mcp.server import MatlabMCPServer
from matlab_mcp.config import load_config
config = load_config()
print(f'Config loaded: {config.server.transport}')
print('✓ Server core working')
"If using HTTP transport with authentication:
matlab-mcp --generate-token
# Output:
# Bearer token (copy to env var):
# export MATLAB_MCP_AUTH_TOKEN=a1b2c3d4e5f6...
#
# For Windows (cmd):
# set MATLAB_MCP_AUTH_TOKEN=a1b2c3d4e5f6...
#
# For PowerShell:
# $env:MATLAB_MCP_AUTH_TOKEN='a1b2c3d4e5f6...'Simplest setup — no network, perfect for Claude Desktop:
matlab-mcpOutput:
Starting MATLAB MCP Server (v2.0)
Transport: stdio
Config: (defaults)
MATLAB engine pool: 2-4 engines
✓ Startup complete
Then configure your AI agent (see step 5).
For shared server access (being phased out in favor of streamable HTTP):
matlab-mcp --transport sse --host 127.0.0.1 --port 8765Output:
Starting MATLAB MCP Server (v2.0)
Transport: SSE (deprecated, use streamable HTTP)
Server: http://127.0.0.1:8765/sse
Monitor: http://127.0.0.1:8766
Pool: 2-10 engines (auto-scaling)
✓ Startup complete
Recommended for remote agents and CI/CD:
# Generate a token first (optional but recommended)
MATLAB_MCP_AUTH_TOKEN=$(matlab-mcp --generate-token | grep "^[a-f0-9]" | head -1)
export MATLAB_MCP_AUTH_TOKEN
# Start server
matlab-mcp --transport streamablehttp --host 127.0.0.1 --port 8765Output:
Starting MATLAB MCP Server (v2.0)
Transport: streamable HTTP
Endpoint: http://127.0.0.1:8765/mcp
Auth: Bearer token required (MATLAB_MCP_AUTH_TOKEN)
Monitor: http://127.0.0.1:8766
Pool: 2-10 engines (auto-scaling)
✓ Startup complete
Configuration via environment variables:
export MATLAB_MCP_SERVER_HOST=127.0.0.1
export MATLAB_MCP_SERVER_PORT=8765
export MATLAB_MCP_SERVER_TRANSPORT=streamablehttp
export MATLAB_MCP_POOL_MIN_ENGINES=2
export MATLAB_MCP_POOL_MAX_ENGINES=10
matlab-mcp-
Open Claude Desktop config:
-
macOS:
~/Library/Application Support/Claude/claude_desktop_config.json -
Windows:
%APPDATA%\Claude\claude_desktop_config.json
-
macOS:
-
Add the MATLAB server:
{
"mcpServers": {
"matlab": {
"command": "matlab-mcp"
}
}
}- Restart Claude Desktop — MATLAB tools will appear in the tool picker.
# Install or update the server in Claude Code
claude mcp add matlabOr manually:
# Edit your Claude Code config
claude config edit
# Add under mcpServers:
# {
# "matlab": {
# "command": "matlab-mcp"
# }
# }- Open Cursor settings → MCP
- Click Add MCP and fill:
-
Name:
matlab -
Command:
matlab-mcp -
Type:
command
-
Name:
- Save and restart Cursor
Or edit .cursor/mcp.json directly:
{
"mcpServers": {
"matlab": {
"command": "matlab-mcp"
}
}
}# Start the server with auth token
export MATLAB_MCP_AUTH_TOKEN=$(matlab-mcp --generate-token | grep "^[a-f0-9]" | head -1)
matlab-mcp --transport streamablehttp
# In another terminal, connect Codex
codex connect http://127.0.0.1:8765/mcp \
--header "Authorization: Bearer $MATLAB_MCP_AUTH_TOKEN"import httpx
import json
# Start server with bearer token
# matlab-mcp --transport streamablehttp
# export MATLAB_MCP_AUTH_TOKEN=<token>
token = "YOUR_TOKEN_HERE"
url = "http://127.0.0.1:8765/mcp"
headers = {
"Authorization": f"Bearer {token}",
"Content-Type": "application/json"
}
# Initialize session
payload = {
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2024-11-05",
"capabilities": {},
"clientInfo": {"name": "my-client", "version": "1.0"}
}
}
async with httpx.AsyncClient() as client:
response = await client.post(url, json=payload, headers=headers)
print(response.json())Once your agent is configured, run a test:
- Open a conversation
- Click the tools icon (hammer)
- Look for MATLAB tools:
execute_code,get_workspace,list_toolboxes, etc. - Ask Claude: "Can you run MATLAB code? Try computing 2+2."
Expected response: Claude will use the execute_code tool and return 4.
- Open a new file
- Use Ctrl+K (Mac: Cmd+K) to open the command palette
- Type "MATLAB" — you should see available MATLAB tools
- Ask: "Run MATLAB code that computes factorial(5)"
codex --mcp matlab "Generate MATLAB code that plots sin(x) from 0 to 2π"graph TB
subgraph Runtime
A["Python 3.10+"]
B["MATLAB R2022b+"]
end
subgraph Python Packages
C["fastmcp ≥3.2.0"]
D["pydantic ≥2.11.7"]
E["matlab-engine"]
end
subgraph Optional
F["Docker 20.10+"]
G["Conda"]
H["psutil for monitoring"]
end
A --> C
B --> E
C --> D
F -.-> A
G -.-> A
H -.-> A
| Component | Minimum | Recommended | Notes |
|---|---|---|---|
| Python | 3.10 | 3.12 | 3.12 has best MATLAB compatibility |
| MATLAB | R2022b | R2024a+ | Engine API required; Simulink optional |
| Disk Space | 500 MB | 2 GB | Server + dependencies; MATLAB installation separate |
| Memory | 2 GB | 4+ GB | Per MATLAB engine instance; scales with pool size |
| Network | N/A | Gigabit | For remote HTTP transport (SSE/streamable) |
| Admin Rights | No | No | Windows: port binding requires UAC elevation only for ports <1024 |
Cause: MATLAB Engine API for Python not installed.
Fix:
cd /Applications/MATLAB_R2024a.app/extern/engines/python # macOS
pip install .Or re-run install.bat on Windows.
Cause: Server can't find MATLAB installation.
Fix:
# macOS/Linux
export MATLAB_ROOT=/Applications/MATLAB_R2024a.app
# Windows (cmd)
set MATLAB_ROOT=C:\Program Files\MATLAB\R2024a
# Windows (PowerShell)
$env:MATLAB_ROOT = "C:\Program Files\MATLAB\R2024a"
matlab-mcpOr set in config.yaml:
pool:
matlab_root: /Applications/MATLAB_R2024a.appCause: Another server is already running on that port.
Fix:
# Use a different port
matlab-mcp --port 9000
# Or kill existing process
lsof -ti:8765 | xargs kill -9 # macOS/Linux
netstat -ano | findstr :8765 # Windows (find PID)
taskkill /PID <PID> /F # Windows (kill process)Cause: Agent not configured correctly.
Fix:
- Verify config file location:
~/Library/Application Support/Claude/claude_desktop_config.json - Ensure command path is correct:
which matlab-mcp(should be in PATH) - Check for typos in JSON syntax (use a JSON validator)
- Restart the agent application completely (close and reopen)
Cause: Firewall or network routing issue.
Fix:
# Test local connectivity
curl http://127.0.0.1:8765/health
# Test with bearer token
export TOKEN=<your-token>
curl -H "Authorization: Bearer $TOKEN" http://127.0.0.1:8765/health
# Check firewall
sudo lsof -i :8765 # macOS/Linux
netsh advfirewall firewall add rule name="MATLAB MCP" dir=in action=allow program="python.exe" localport=8765 protocol=tcp # WindowsCause: MATLAB mount path doesn't exist in container.
Fix:
# Verify your MATLAB installation path exists
ls /opt/matlab/bin/matlab
# Update docker-compose.yml with correct path
# volumes:
# - /Users/you/MATLAB/R2024a:/opt/matlab:roCause: Reverse proxy timeout or network configuration.
Fix:
# For nginx
proxy_read_timeout 300s;
proxy_connect_timeout 300s;
# For Apache
Timeout 300
ProxyTimeout 300
# Or increase timeout in config.yaml
execution:
sync_timeout: 120 # secondsOnce installed and verified:
- Configuration — Customize pool size, blocked functions, monitoring
- Tools Reference — All available tools and their parameters
- Examples — Ready-to-run MATLAB code examples
- Security — Auth, blocklists, workspace isolation
- Custom Tools — Expose your own MATLAB functions as tools
| MATLAB | Engine API | Python 3.10 | Python 3.11 | Python 3.12 | Status |
|---|---|---|---|---|---|
| R2022b | ✓ | ✓ | ✓ | ⚠ | Supported (oldest) |
| R2023a | ✓ | ✓ | ✓ | ⚠ | Supported |
| R2023b | ✓ | ✓ | ✓ | ✓ | Recommended |
| R2024a | ✓ | ✓ | ✓ | ✓ | Recommended |
| R2024b | ✓ | ✓ | ✓ | ✓ | Latest |
⚠ = Requires workaround; ✓ = Fully tested; ❌ = Not supported
- FAQ — Common questions
- Troubleshooting — Detailed issue diagnosis
- GitHub Issues — Bug reports and feature requests
- Security Advisories — Authentication and authorization