-
Notifications
You must be signed in to change notification settings - Fork 0
Installation
- Python 3.10+ (3.12 recommended for best performance)
- MATLAB R2020b+ installed locally
- MATLAB Engine API for Python — comes with MATLAB, requires separate installation
- Operating System: macOS, Windows, or Linux with MATLAB support
macOS note: The MATLAB Engine API supports a maximum of 4 concurrent engines due to licensing restrictions. Configure
max_engines: 4in your settings.
graph LR
A["MATLAB Installation<br/>R2020b+"] -->|Engine API| B["Python Environment<br/>3.10+"]
B -->|Install matlab-mcp-python| C["MCP Server"]
C -->|stdio/SSE| D["Claude Desktop<br/>Cursor/Code"]
E["config.yaml"] -->|Configure| C
F["Docker Optional"] -.->|Alt Deploy| C
The MATLAB Engine API allows Python to call MATLAB. It's included with MATLAB but must be installed separately into your Python environment.
# Find your MATLAB installation
ls /Applications/MATLAB*.app
# Install Engine API (adjust version as needed)
cd /Applications/MATLAB_R2024a.app/extern/engines/python
pip install .
# Verify
python -c "import matlab.engine; print('✓ MATLAB Engine API installed')"# Find your MATLAB installation
dir "C:\Program Files\MATLAB"
# Open Command Prompt as Administrator and run:
cd "C:\Program Files\MATLAB\R2024a\extern\engines\python"
pip install .
# Verify
python -c "import matlab.engine; print('✓ MATLAB Engine API installed')"# Install Engine API (adjust version as needed)
cd /opt/MATLAB/R2024a/extern/engines/python
pip install .
# Verify
python -c "import matlab.engine; print('✓ MATLAB Engine API installed')"python << 'EOF'
import matlab.engine
eng = matlab.engine.start_matlab()
result = eng.eval("2 + 2", nargout=1)
print(f"2 + 2 = {result}")
eng.quit()
EOFExpected output: 2 + 2 = 4
Isolate the server's dependencies from your system Python:
# Create virtual environment
python3.10 -m venv matlab-mcp-env
source matlab-mcp-env/bin/activate # macOS/Linux
# matlab-mcp-env\Scripts\activate # Windows
# Upgrade pip
pip install --upgrade pipImportant: Install the MATLAB Engine API into this virtual environment after activation.
# Minimal install (core only)
pip install matlab-mcp-python
# With monitoring dashboard
pip install "matlab-mcp-python[monitoring]"
# With all development tools
pip install "matlab-mcp-python[dev]"git clone https://github.com/HanSur94/matlab-mcp-server-python.git
cd matlab-mcp-server-python
# Minimal install
pip install -e .
# With monitoring
pip install -e ".[monitoring]"
# With dev dependencies (tests, docs)
pip install -e ".[dev]"For systems without internet access:
# On a connected machine:
python update_vendor.bat
# Transfer the vendor/ directory to the offline machine
# On the offline machine:
install.batThe batch script installs Python 3.10+ and dependencies from local wheels without requiring admin rights.
Build and run the server in a container:
# Build the image
docker build -t matlab-mcp:latest .
# Run with MATLAB mounted
docker run -d \
--name matlab-mcp \
-p 8765:8765 \
-p 8766:8766 \
-v /path/to/MATLAB:/opt/matlab:ro \
-e MATLAB_MCP_POOL_MATLAB_ROOT=/opt/matlab \
matlab-mcp:latest
# Or using docker-compose
docker compose up -dNote: Docker image does not include MATLAB. You must mount your local MATLAB installation. See
docker-compose.ymlfor volume configuration.
Create a config.yaml for your deployment:
server:
name: "matlab-mcp-dev"
transport: stdio
log_level: info
pool:
min_engines: 1
max_engines: 2
execution:
sync_timeout: 30
workspace_isolation: true
security:
blocked_functions_enabled: trueserver:
name: "matlab-mcp-prod"
transport: sse
host: "127.0.0.1"
port: 8765
log_level: info
pool:
min_engines: 4
max_engines: 16
health_check_interval: 60
execution:
sync_timeout: 60
workspace_isolation: true
sessions:
max_sessions: 100
session_timeout: 7200
security:
blocked_functions_enabled: true
require_proxy_auth: true
max_upload_size_mb: 200
monitoring:
enabled: true
sample_interval: 10See Configuration for all available options.
# Single user with default config
matlab-mcp
# With custom config
matlab-mcp --config config.yaml
# Debug mode (verbose logging)
MATLAB_MCP_SERVER_LOG_LEVEL=debug matlab-mcp# Start with SSE transport
matlab-mcp --transport sse
# Accessible at http://localhost:8765/sse
# Place behind a reverse proxy (nginx, Caddy) with authentication# Test stdio connection (should hang, waiting for client)
echo "exit" | matlab-mcp
# Test SSE health endpoint
curl http://localhost:8765/health
# Returns: {"status": "healthy", "uptime_seconds": 1.23, ...}
# View monitoring dashboard (if monitoring enabled)
# Open http://localhost:8766/dashboard in your browser-
Locate config file:
-
macOS:
~/Library/Application Support/Claude/claude_desktop_config.json -
Windows:
%APPDATA%\Claude\claude_desktop_config.json
-
macOS:
-
Add MATLAB MCP server:
{
"mcpServers": {
"matlab": {
"command": "matlab-mcp",
"args": ["--config", "/path/to/config.yaml"]
}
}
}-
Restart Claude Desktop
-
Open a conversation and verify MATLAB tools are available
# Add via CLI
claude mcp add matlab -- matlab-mcp
# Or edit .claude/mcp.json:{
"mcpServers": {
"matlab": {
"command": "matlab-mcp"
}
}
}- Edit
.cursor/mcp.jsonin your project root:
{
"mcpServers": {
"matlab": {
"command": "matlab-mcp",
"args": ["--config", "./config.yaml"]
}
}
}- Reload Cursor
import json
from subprocess import Popen, PIPE
# Start server
proc = Popen(["matlab-mcp"], stdin=PIPE, stdout=PIPE, stderr=PIPE, text=True)
# Send MCP initialization message
init_msg = {
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2024-11-05",
"capabilities": {},
"clientInfo": {"name": "test-client", "version": "1.0"}
}
}
proc.stdin.write(json.dumps(init_msg) + "\n")
proc.stdin.flush()
# Read response
response = json.loads(proc.stdout.readline())
print(response)Deploy behind a reverse proxy with authentication:
Nginx Example:
server {
listen 443 ssl http2;
server_name matlab.company.com;
ssl_certificate /etc/ssl/certs/cert.pem;
ssl_certificate_key /etc/ssl/private/key.pem;
# Basic authentication
auth_basic "MATLAB MCP";
auth_basic_user_file /etc/nginx/.htpasswd;
location /sse {
proxy_pass http://localhost:8765/sse;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_read_timeout 600s;
}
location /health {
proxy_pass http://localhost:8765/health;
}
}Test your installation end-to-end:
# Test MATLAB execution
python << 'EOF'
import asyncio
from matlab_mcp.server import create_server
from matlab_mcp.config import load_config
async def test():
config = load_config()
server = await create_server(config)
# Execute simple code
result = await server.execute_code(
code="x = [1 2 3]; sum(x)",
session_id="test"
)
print(result)
await server.shutdown()
asyncio.run(test())
EOF- Start a conversation in Claude Desktop
- Type:
"What is 2+2 in MATLAB?" - Verify Claude uses the
execute_codetool - Confirm result is
4
# Start server
matlab-mcp --transport sse &
# Test health endpoint
curl -i http://localhost:8765/health
# Returns 200 OK
# Test metrics endpoint
curl http://localhost:8765/metrics | jq .
# View dashboard
open http://localhost:8766/dashboard # macOS
# xdg-open http://localhost:8766/dashboard # Linux| Issue | Solution |
|---|---|
ModuleNotFoundError: No module named 'matlab' |
Install MATLAB Engine API: cd /Applications/MATLAB_R2024a.app/extern/engines/python && pip install .
|
Connection refused when connecting agent |
Ensure server is running with matlab-mcp, check firewall |
Engine startup timeout |
Increase engine_start_timeout in config (default 120s) |
Max 4 engines on macOS |
This is a MATLAB licensing limit; set max_engines: 4 in config |
Docker: MATLAB not found |
Mount MATLAB: -v /path/to/MATLAB:/opt/matlab:ro and set MATLAB_MCP_POOL_MATLAB_ROOT=/opt/matlab
|
| Slow first execution | MATLAB engines take time to start; initial requests may take 30+ seconds |
For more help, see Troubleshooting or open a GitHub issue.
- Configure: See Configuration for all server options
- Learn tools: Review MCP Tools Reference for available functions
- Custom tools: Add your MATLAB functions via Custom Tools
- Examples: Run Examples to understand capabilities
- Architecture: Read Architecture for system design details
- Async jobs: Learn about Async Jobs for long-running code
- Security: Review Security before production deployment