-
Notifications
You must be signed in to change notification settings - Fork 0
Troubleshooting
Welcome to the MATLAB MCP Server troubleshooting guide. This page helps you diagnose and resolve common issues.
- Installation & Setup
- Runtime Errors
- Connection Issues
- Configuration Problems
- Networking & Security
- Debugging & Diagnostics
- Still Stuck?
Symptoms:
ModuleNotFoundError: No module named 'matlab'ImportError: matlab.engine not found- Server fails to start with message about MATLAB installation
Likely Causes:
- MATLAB Engine API for Python is not installed
- Wrong MATLAB version (server requires R2022b or later)
- Python path doesn't include MATLAB installation
Solutions:
-
Verify MATLAB is installed:
which matlab # macOS/Linux where matlab # Windows
-
Install the MATLAB Engine API:
macOS:
cd /Applications/MATLAB_R2024a.app/extern/engines/python pip install .
Windows:
cd "C:\Program Files\MATLAB\R2024a\extern\engines\python" pip install .
Linux:
cd /usr/local/MATLAB/R2024a/extern/engines/python pip install .
-
Verify installation succeeded:
python -c "import matlab.engine; print('✓ MATLAB Engine API installed')" -
Check MATLAB version:
matlab -r "version; exit"Must be R2022b or later.
-
Set MATLAB root explicitly (if auto-detection fails):
# config.yaml pool: matlab_root: "/Applications/MATLAB_R2024a.app" # macOS # matlab_root: "C:\\Program Files\\MATLAB\\R2024a" # Windows
Or via environment variable:
export MATLAB_MCP_POOL_MATLAB_ROOT=/Applications/MATLAB_R2024a.app
Symptoms:
ERROR: Package requires Python >=3.10- Cryptic import errors or syntax errors on startup
Solutions:
-
Check your Python version:
python --version
-
Install Python 3.10 or later:
- Official Python.org downloads
- macOS:
brew install python@3.12 - Ubuntu:
sudo apt-get install python3.12 - Windows: Use the official installer (don't forget to add to PATH)
-
Use a virtual environment with the correct version:
python3.12 -m venv venv source venv/bin/activate # macOS/Linux # or: venv\Scripts\activate # Windows pip install matlab-mcp-python
Symptoms:
-
pip install matlab-mcp-pythonfails with network or compilation errors - Wheel build fails with C extension errors
Likely Causes:
- Network connectivity issues
- Missing build tools (on Windows or Linux)
- Conflicting dependency versions
Solutions:
-
Retry with verbose output:
pip install -v matlab-mcp-python
-
Upgrade pip, setuptools, and wheel:
pip install --upgrade pip setuptools wheel pip install matlab-mcp-python
-
Install from source (offline):
git clone https://github.com/HanSur94/matlab-mcp-server-python.git cd matlab-mcp-server-python pip install -e .
-
Use conda (often more reliable for dependencies):
conda env create -f environment.yml conda activate matlab-mcp
Symptoms:
Engine start timeout after Xs- Server starts but hangs indefinitely
- Only affects first request
Likely Causes:
- MATLAB is slow to initialize (especially on older hardware)
- MATLAB license server is unreachable
- MATLAB is hung or locked by another process
Solutions:
-
Increase the startup timeout:
# config.yaml pool: engine_start_timeout: 300 # 5 minutes (default is 60)
Or via environment variable:
export MATLAB_MCP_POOL_ENGINE_START_TIMEOUT=300 -
Verify MATLAB can start manually:
matlab -r "disp('MATLAB started'); exit" -
Check MATLAB license:
matlab -r "license('test','Symbolic_Math_Toolbox'); exit" -
Kill hung MATLAB processes:
pkill -f "MATLAB" # macOS/Linux taskkill /F /IM MATLAB.exe # Windows
-
Check disk space:
df -h # macOS/Linux # Windows: Right-click drive → Properties
MATLAB needs free space for temp files.
Symptoms:
- Warning:
Too many MATLAB engines requested. macOS limit is ~4 concurrent - Jobs fail with "insufficient engines available"
Explanation:
- macOS has a hard limit of ~4 simultaneous MATLAB engines due to OS constraints
- This is a platform limitation, not a bug
Solutions:
-
Set max engines to 4:
# config.yaml pool: min_engines: 2 max_engines: 4 # macOS limit
-
Reduce concurrent load:
- Encourage long-running jobs to use async execution (
mcp_progress()) - Configure session timeouts to free resources:
sessions.idle_timeout: 300
- Encourage long-running jobs to use async execution (
-
Consider Linux deployment for higher parallelism
Symptoms:
-
MemoryErrororJava heap out of memory -
Killed: 9(OOM killer on Linux) - Performance suddenly drops
Likely Causes:
- Large variable assignments in MATLAB workspace
- Memory leak in long-running jobs
- Too many concurrent engines for available RAM
Solutions:
-
Monitor memory usage:
# During server operation, in another terminal: top -p $(pgrep -f "matlab") # macOS/Linux # or Task Manager on Windows
-
Reduce max engines:
pool: max_engines: 4 # Reduce from default 10
-
Reduce max sessions:
sessions: max_sessions: 5 # Fewer concurrent users
-
Enable workspace clearing between jobs:
execution: clear_workspace_after_job: true
-
Increase system swap (last resort):
# Linux only sudo fallocate -l 4G /swapfile sudo chmod 600 /swapfile sudo mkswap /swapfile sudo swapon /swapfile
Symptoms:
- Client says "connection refused" or "no server running"
-
matlab-mcpstarts but client sees nothing - Claude Desktop says "Tool use requires connection"
Likely Causes:
- Server crashed silently (no MATLAB engine)
- Server started but not in stdio mode
- Another process using stdio
Solutions:
-
Verify server is running:
matlab-mcp & # Should print banner and wait for input
-
Check MATLAB Engine API:
python -c "import matlab.engine; print(matlab.engine.find_matlab())" -
Run with verbose logging:
MATLAB_MCP_SERVER_LOG_LEVEL=debug matlab-mcp
-
Use SSE transport instead (if stdio fails):
matlab-mcp --transport sse # Now connect client to http://localhost:8765/sse
Symptoms:
-
Connection refusedwhen accessinghttp://localhost:8765/sse -
ERR_CONNECTION_REFUSEDin browser - Client times out
Likely Causes:
- Server not started with
--transport sse - Firewall blocking port 8765
- Wrong host/port configuration
- Server crashed on startup
Solutions:
-
Verify server is running:
matlab-mcp --transport sse # Look for "SSE endpoint available at http://localhost:8765/sse" -
Check the port is listening:
netstat -tuln | grep 8765 # macOS/Linux netstat -ano | findstr :8765 # Windows
-
Try localhost vs 127.0.0.1:
curl -i http://127.0.0.1:8765/health # Should return 200 OK -
Disable firewall temporarily to test:
# macOS sudo /usr/libexec/ApplicationFirewall/socketfilterfw -setglobalstate off # Linux (ufw) sudo ufw disable # Windows: Disable Windows Defender Firewall temporarily
-
Check logs:
tail -f server.log # If logging to file
Symptoms:
-
HTTP 401 Unauthorizedon every request WWW-Authenticate: Bearer realm="MATLAB MCP Server"- Client says "Invalid token"
Likely Causes:
- Token not set in environment variable
- Token format incorrect
- Typo in bearer token header
- Server restarted with different token
Solutions:
-
Generate a valid token:
matlab-mcp --generate-token # Outputs: 64-char hex token + env var snippets -
Set the token before starting server:
export MATLAB_MCP_AUTH_TOKEN="<64-char-hex-token-from-above>" matlab-mcp --transport sse
-
Verify token is set:
echo $MATLAB_MCP_AUTH_TOKEN # Should print the token
-
Test with curl:
curl -H "Authorization: Bearer $MATLAB_MCP_AUTH_TOKEN" \ http://localhost:8765/health # Should return 200 OK, not 401
-
Check token has not changed:
- If server was restarted, the token must match the client's environment
- Tokens don't persist across sessions; store in
.envfile or GitHub secret
Symptoms:
- Client can reach server (IP/port is open)
- Connection starts but hangs or times out
- No error message, just waits forever
Likely Causes:
- Network latency or packet loss
- Firewall blocking MCP handshake
- Server is overloaded
- Wrong transport or endpoint
Solutions:
-
Test basic connectivity:
ping <server-ip> # Should see replies
-
Test HTTP endpoint:
curl -v http://<server-ip>:8765/health # Should return 200 OK quickly
-
Check network MTU (if very slow):
# Linux/macOS ping -D -s 1472 <server-ip> # Test MTU
-
Reduce request timeout on client:
- Some agents have connection timeouts (30-60s default)
- Ensure server responds within client timeout
Symptoms:
- Warning:
Config file not found: ./config.yaml, using defaults - Server starts with defaults instead of custom config
Likely Causes:
- File not in current working directory
- Typo in filename
- File permissions issue
Solutions:
-
Create config file:
cp examples/config_minimal.yaml config.yaml # or matlab-mcp --help # Shows default config
-
Specify config path:
matlab-mcp --config /path/to/config.yaml
-
Check current directory:
pwd # Print working directory ls -la config.yaml # Verify file exists and is readable
-
Check file permissions:
chmod 644 config.yaml # Make readable by server process
Symptoms:
yaml.YAMLError: mapping values are not allowed hereyaml.scanner.ScannerError: expected <block end>- Invalid YAML syntax error with line number
Likely Causes:
- Tabs instead of spaces (YAML requires spaces)
- Quote mismatch
- Invalid indentation
- Special characters not escaped
Solutions:
-
Validate YAML syntax:
python -c "import yaml; yaml.safe_load(open('config.yaml'))" # If no error, YAML is valid
-
Use an online validator:
- yamllint.com
- Paste your config.yaml to check syntax
-
Fix common issues:
- Replace tabs with spaces (Python style)
- Quote strings with special characters:
"value: 123" - Check indentation is consistent (2 or 4 spaces)
-
Example valid config:
server: transport: "stdio" log_level: "info" pool: min_engines: 2 max_engines: 10
Symptoms:
- Set
MATLAB_MCP_POOL_MAX_ENGINES=5but server uses default (10) - Environment variables seem to be ignored
Likely Causes:
- Variable name typo
- Variable not exported
- Config file override takes precedence
Solutions:
-
Verify variable is set:
echo $MATLAB_MCP_POOL_MAX_ENGINES # Should print: 5
-
Export the variable (if not already exported):
export MATLAB_MCP_POOL_MAX_ENGINES=5 matlab-mcp -
Check the prefix: Must be
MATLAB_MCP_followed by section and key in uppercase with underscores:# Correct: export MATLAB_MCP_POOL_MAX_ENGINES=5 export MATLAB_MCP_SERVER_HOST=127.0.0.1 # Incorrect: export MAX_ENGINES=5 # Missing prefix export POOL_MAX_ENGINES=5 # Missing prefix
-
Verify config file isn't overriding:
- If
config.yamlhas explicit values, env vars may not override - Delete
config.yamlto use env vars only
- If
Symptoms:
- Want to block a function (e.g.,
eval) but it's not in default blocklist - Or a legitimate function (e.g.,
system) is blocked and you need to remove it
Likely Causes:
- Blocklist configuration is incomplete
- Default blocklist too strict for your use case
Solutions:
-
Add to blocklist:
# config.yaml security: blocked_functions: - system - eval - disp # New addition
-
Remove from blocklist:
# config.yaml security: blocked_functions: - system - eval # - disp # Removed (commented out)
-
Disable blocklist entirely (not recommended):
security: blocked_functions_enabled: false
-
View current blocklist:
matlab-mcp --help # Shows default config with blocked functions
Symptoms:
- Server runs on
http://localhost:8765 - Remote client can't connect: "Connection refused"
-
netstatshows port is listening but unreachable
Likely Causes:
- Windows Firewall or macOS firewall blocking inbound
- Corporate firewall or proxy
- Port < 1024 requires admin rights (Windows)
Solutions:
-
Allow port through Windows Firewall:
# Run as Administrator: New-NetFirewallRule -DisplayName "MATLAB MCP" -Direction Inbound ` -Action Allow -LocalPort 8765 -Protocol TCP
-
Allow through macOS firewall:
- System Preferences → Security & Privacy → Firewall Options
- Add
pythonto the allowed list
-
Use port 80 or 443 (requires admin):
sudo matlab-mcp --port 80 --transport sse
-
Use reverse proxy (nginx/Apache) to forward traffic:
server { listen 443 ssl; location / { proxy_pass http://127.0.0.1:8765; } }
Symptoms:
- Warning:
Possible sensitive key 'token' in config section 'server' - Token appears in git history or logs
- Security audit flags hardcoded credentials
Likely Causes:
- Token stored directly in
config.yamlinstead of env var - Config file committed to version control
- Token logged at startup
Solutions:
-
Use environment variables, not config files:
export MATLAB_MCP_AUTH_TOKEN="<your-token>" matlab-mcp # Don't put token in config.yaml
-
Generate a new token:
matlab-mcp --generate-token # Output: use in MATLAB_MCP_AUTH_TOKEN env var -
Add config.yaml to .gitignore:
echo "config.yaml" >> .gitignore git rm --cached config.yaml # Remove from history
-
Rotate token if compromised:
matlab-mcp --generate-token # New token export MATLAB_MCP_AUTH_TOKEN="<new-token>" # Restart server with new token
Symptoms:
- Server binding to
0.0.0.0(all interfaces) - Anyone on the network can access
/healthand execute MATLAB code - No authentication in place
Likely Causes:
-
server.hostset to0.0.0.0(broadcast) - No bearer token configured
- SSE endpoint accessible without auth
Solutions:
-
Bind to localhost only:
# config.yaml server: host: "127.0.0.1" # Localhost only
Or via env var:
export MATLAB_MCP_SERVER_HOST=127.0.0.1 -
Enable bearer token authentication:
matlab-mcp --generate-token # Copy token to MATLAB_MCP_AUTH_TOKEN env var matlab-mcp --transport sse -
Use a reverse proxy with authentication:
# nginx.conf location / { auth_basic "MATLAB MCP"; auth_basic_user_file /etc/nginx/.htpasswd; proxy_pass http://127.0.0.1:8765; }
To see detailed operation logs:
-
Set log level in config:
# config.yaml server: log_level: "debug" log_file: "./logs/server.log" # Optional: write to file
-
Or use environment variable:
export MATLAB_MCP_SERVER_LOG_LEVEL=debug matlab-mcp --transport sse -
Monitor logs in real-time:
tail -f logs/server.log # If writing to file -
Log levels (in order of verbosity):
-
debug— Very detailed, includes all decisions -
info— Normal operation, key events -
warning— Potential issues, security warnings -
error— Failures and exceptions -
critical— Fatal errors only
-
When reporting a bug, collect this information:
# 1. Server version
pip show matlab-mcp-python | grep Version
# 2. Python version
python --version
# 3. MATLAB version
matlab -r "version; exit"
# 4. MATLAB Engine API verification
python -c "import matlab.engine; print(matlab.engine.find_matlab())"
# 5. Config validation
python -c "from matlab_mcp.config import load_config; load_config()"
# 6. Last 50 lines of logs
tail -50 logs/server.log > /tmp/server_logs.txt
# 7. System info
uname -a # macOS/Linux
wmic os get osversion # Windows
# 8. Available disk space
df -h # macOS/Linux
# Windows: dir C: (check free space)While server is running:
-
Check health endpoint:
curl http://127.0.0.1:8765/health | python -m json.tool # Shows: uptime, engine count, active jobs, sessions
-
View metrics dashboard:
- Open browser to
http://127.0.0.1:8766(if monitoring enabled) - Shows pool utilization, job history, error rate
- Open browser to
-
Check job status:
% Inside Claude conversation, ask: % "Show me the pool status" % Server will return current engine availability
graph TD
A["Test Checklist"] --> B["Can Python import matlab.engine?"]
B -->|Yes| C["Can server start?"]
B -->|No| D["Fix MATLAB Engine API installation"]
C -->|Yes| E["Can client connect?"]
C -->|No| F["Check logs for startup error"]
E -->|Yes| G["✓ Server working"]
E -->|No| H["Check firewall, host/port config"]
H --> I["Enable debug logging"]
I --> J["Check logs for connection error"]
If you've tried everything above:
-
Check the project wiki for more detailed docs:
-
Search existing GitHub issues:
- github.com/HanSur94/matlab-mcp-server-python/issues
- Your error may have been reported and resolved
-
Open a new issue with:
- Error message and symptoms
- Your platform (Windows/macOS/Linux) and versions
- Config file (redact any tokens)
- Debug logs (see "Collect Diagnostic Information" above)
- Steps to reproduce
-
Join community discussions:
-
Contact maintainer:
- Email: hannes.suhr@example.com
- GitHub discussions tab for non-urgent questions
Last updated: 2026-04-03 (v2.0 release)