-
Notifications
You must be signed in to change notification settings - Fork 0
Troubleshooting
Symptom: ModuleNotFoundError: No module named 'matlab' or ImportError: No module named matlab.engine
Likely causes:
- MATLAB Engine API for Python is not installed
- Wrong Python version (Engine API requires Python 3.8+)
- Multiple Python installations; package installed in wrong version
Solution:
-
Verify MATLAB is installed:
matlab -version
Requires MATLAB R2022b or later.
-
Install the Engine API for your MATLAB version:
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:
python -c "import matlab.engine; print('OK')"
Symptom: ImportError: Python version not supported when installing MATLAB Engine API
Likely cause: Your Python version doesn't match the MATLAB Engine API requirement (3.8–3.12 depending on MATLAB version)
Solution:
-
Check your Python version:
python --version
-
For MATLAB R2024a+, use Python 3.10–3.12
-
For MATLAB R2023a–R2023b, use Python 3.8–3.11
-
Create a virtual environment with the correct version:
python3.10 -m venv venv source venv/bin/activate # macOS/Linux # or venv\Scripts\activate # Windows
Symptom: command not found: matlab-mcp after installation
Likely causes:
- Virtual environment not activated
- Installation failed silently
- Scripts directory not on PATH
Solution:
-
If using virtual environment, activate it:
source venv/bin/activate # macOS/Linux # or venv\Scripts\activate # Windows
-
Reinstall the package:
pip install --force-reinstall matlab-mcp-python
-
Verify installation:
pip show matlab-mcp-python
-
Run with explicit Python module:
python -m matlab_mcp.server
Symptom: Engine start timeout after XXs or Failed to start MATLAB engine
Likely causes:
- MATLAB startup is slow (first-time or on network drives)
- Insufficient system resources (RAM, CPU)
- MATLAB license server is unreachable
- Path to MATLAB is wrong
Solution:
-
Increase engine start timeout:
pool: engine_start_timeout: 300 # 5 minutes instead of default 120
-
Verify MATLAB is accessible:
matlab -version
-
On macOS, check for license issues:
/Applications/MATLAB_R2024a.app/bin/matlab -nodisplay -c "exit" -
Specify explicit MATLAB root (if auto-detection fails):
pool: matlab_root: "/Applications/MATLAB_R2024a.app" # macOS # or # matlab_root: "C:\\Program Files\\MATLAB\\R2024a" # Windows
-
Check system resources:
- Each MATLAB engine uses ~500MB–1GB RAM
- Set
min_engineslower if memory-constrained:pool: min_engines: 1 max_engines: 4
Symptom: Warning message about MATLAB engine limits during pool startup
Likely cause: MATLAB on macOS has a built-in limit of ~4 concurrent engine instances
Solution:
Set max_engines to match MATLAB's limit:
pool:
max_engines: 4 # Hard limit on macOSSymptom: MATLAB engine startup hangs when config or temp directories are on network drives
Likely cause: MATLAB engine checks paths synchronously during startup
Solution:
-
Use local directories:
execution: workspace_isolation: true # Ensure temp directories are on local disk
-
Set explicit local temp root:
export MATLAB_MCP_TEMP_ROOT=/local/tmp # Local filesystem only
-
Disable workspace isolation (if appropriate):
execution: workspace_isolation: false
Symptom: Config file not found or server uses defaults silently
Likely causes:
- Path is relative; server running from different directory
- File was deleted or moved
- Wrong filename
Solution:
-
Use absolute path:
matlab-mcp --config /absolute/path/to/config.yaml
-
Or use environment variable:
export MATLAB_MCP_CONFIG=/path/to/config.yaml matlab-mcp -
Verify config file exists:
ls -la config.yaml # macOS/Linux # or dir config.yaml # Windows
Symptom: Error loading config or cryptic YAML parsing error
Likely cause: YAML syntax error (bad indentation, unclosed quotes, missing colons)
Solution:
-
Validate YAML syntax:
python -c "import yaml; yaml.safe_load(open('config.yaml'))" -
Common mistakes:
- Tabs instead of spaces (YAML requires spaces)
- Unclosed quotes:
transport: 'stdio(missing closing quote) - Wrong nesting:
pool: min_engines: 2(should be indented)
-
Use a YAML linter:
pip install yamllint yamllint config.yaml
Symptom: Setting MATLAB_MCP_* env var has no effect
Likely cause: Variable name is wrong or not prefixed correctly
Solution:
-
Use correct prefix:
MATLAB_MCP_# Correct: export MATLAB_MCP_POOL_MAX_ENGINES=20 # Wrong: export POOL_MAX_ENGINES=20 # Missing MATLAB_MCP_
-
Nested config uses underscores:
# For config.pool.max_engines: export MATLAB_MCP_POOL_MAX_ENGINES=20 # For config.server.transport: export MATLAB_MCP_SERVER_TRANSPORT=sse
-
Verify the variable is set:
env | grep MATLAB_MCP -
Check value is loaded:
matlab-mcp --help # Shows effective config
Symptom: 401 Unauthorized when connecting via HTTP/SSE with token
Likely causes:
- Token not set in environment variable
MATLAB_MCP_AUTH_TOKEN - Token value doesn't match what server is using
- Authorization header format is wrong
Solution:
-
Generate a token:
matlab-mcp --generate-token
Output shows environment variable to set.
-
Set the token in your environment:
# macOS/Linux: export MATLAB_MCP_AUTH_TOKEN=abc123... # Windows cmd: set MATLAB_MCP_AUTH_TOKEN=abc123... # Windows PowerShell: $env:MATLAB_MCP_AUTH_TOKEN='abc123...'
-
Verify server is configured for auth: Check startup logs for "HTTP endpoint" or "auth token" messages
-
Include token in HTTP client request:
curl -H "Authorization: Bearer abc123..." http://localhost:8765/health
Symptom: Client can't connect from another machine; works on localhost
Likely causes:
- Server bound to
0.0.0.0and Windows Firewall blocked inbound - Server bound to
127.0.0.1(loopback only, not accessible from other machines)
Solution:
-
For local-only (development): Default
host: 127.0.0.1is safe and works locally -
For remote access:
server: host: "0.0.0.0" # Listen on all interfaces
Then add Windows Firewall rule (no admin needed on Windows 10+):
- Settings → Privacy & Security → Windows Defender Firewall → Allow an app through firewall
- Add
python.exefor your Python installation, or port 8765
-
Or use a reverse proxy (recommended for production): Run server on
127.0.0.1:8765locally, reverse-proxy from external IP via nginx/Cloudflare
Symptom: Startup message warns "SSE transport is deprecated"
Explanation: SSE (Server-Sent Events) is older and slower than streamable HTTP. It's kept for backward compatibility but not recommended for new deployments.
Solution:
Migrate to streamablehttp transport:
server:
transport: streamablehttp # Preferred for new deploymentsOr use --transport flag:
matlab-mcp --transport streamablehttpSymptom: Code using system(), unix(), dos(), or shell escapes (!cmd) fails with BlockedFunctionError
Likely cause: Security blocker prevents shell execution to prevent code injection
Solution:
-
Use MATLAB-native alternatives:
Blocked Alternative system('mkdir foo')mkdir('foo')system('cp a.txt b.txt')copyfile('a.txt', 'b.txt')system('ls')/!dirdir/ls(MATLAB functions)system('pwd')pwd(MATLAB function) -
Disable blocker (only for trusted, isolated servers):
security: blocked_functions_enabled: false
-
Remove specific functions from blocklist:
security: blocked_functions: - eval - evalin - assignin - fopen # Remove 'system' to allow it
Symptom: get_job_status returns "running" forever or progress_percentage is null
Likely causes:
- MATLAB code has an infinite loop
- Code is blocked waiting for input
- Progress reporting not implemented in long job
- Job timeout is too large
Solution:
-
Cancel the job:
# Via agent: cancel_job(job_id=...)Or restart the server (all jobs will be lost)
-
Add progress reporting to long MATLAB code:
for i = 1:1000000 % ... computation ... if mod(i, 10000) == 0 mcp_progress(__mcp_job_id__, i/1000000*100, sprintf('Iteration %d', i)); end end
-
Reduce
max_execution_time:execution: max_execution_time: 3600 # 1 hour limit instead of default 24h
Symptom: "Truncated: result saved to file" or output ends abruptly
Likely cause: Result exceeds max_inline_text_length (default 50,000 chars) or large_result_threshold
Solution:
-
Increase inline limit:
output: max_inline_text_length: 100000 # Default 50000 large_result_threshold: 50000 # Default 10000 elements
-
Retrieve full result from file: Use
list_filesto find the file, thenread_dataorread_scriptto fetch it -
Reduce output in MATLAB code:
% Instead of: disp(large_matrix) % Prints all elements % Use summary: fprintf('Matrix size: %d x %d\n', size(large_matrix)); disp(large_matrix(1:5, 1:5)); % First 5x5 block
Symptom: Plot created but no interactive Plotly JSON returned; only static PNG
Likely causes:
- Figure type not supported by converter (custom graphics, complex overlays)
- MATLAB plotting toolbox not installed
- Pillow missing (for PNG fallback)
Solution:
-
Check supported plot types:
- ✓ Line plots, scatter, bar, histogram
- ✓ Subplots (grid layout)
- ✓ Surface, mesh, image
- ✗ Custom graphics, patches with complex properties
-
Use standard plotting functions:
plot(x, y) % Supported scatter(x, y) % Supported bar(x, y) % Supported imagesc(img) % Supported % patch, line, ... might have limited support
-
Disable Plotly conversion (use static PNG only):
output: plotly_conversion: false
-
Install Pillow for image fallback:
pip install Pillow
To diagnose issues, enable debug logging:
server:
log_level: "debug"Or via environment variable:
export MATLAB_MCP_SERVER_LOG_LEVEL=debug
matlab-mcpLog output will show:
- Engine startup/shutdown events
- Job execution details
- Code security validation steps
- Pool acquisition/release
- Session creation/cleanup
- All network requests (at DEBUG level)
Check server health in real-time:
# Via MCP tool:
get_server_health()
# Or via HTTP:
curl http://localhost:8765/health
curl http://localhost:8765/metricsHealth indicators:
-
status:healthy|degraded|unhealthy -
pool: engine utilization percentage -
jobs: active/completed/failed counts -
errors: error rate in last hour -
uptime_seconds: server uptime
# Open in browser:
open http://localhost:8766/dashboard # macOS
start http://localhost:8766/dashboard # Windows
firefox http://localhost:8766/dashboard # LinuxShows live metrics, time-series charts, event log, and error rate.
When reporting bugs, include:
-
Server version:
pip show matlab-mcp-python
-
Python version:
python --version
-
MATLAB version:
matlab -version
-
Debug logs (last 100 lines):
tail -100 logs/server.log # If log_file is configured -
Config file (sanitized):
# Remove or redact any tokens or paths server: transport: sse pool: min_engines: 2 max_engines: 10 # ... rest of config
-
Reproduction steps:
- What MCP client are you using?
- What MATLAB code triggered the error?
- Does it happen consistently?
If engine startup fails, test MATLAB directly:
# Start MATLAB
matlab
% Inside MATLAB:
py.sys.version % Should show Python version
py.matlab_mcp.pool.engine.EngineState % Check if module loadsTo see full Python tracebacks:
# Run with Python verbose flags:
python -u -m matlab_mcp.server --config config.yaml 2>&1 | tee debug.logThis captures all output including stack traces for exceptions.
-
Check the wiki:
-
Search GitHub Issues:
- matlab-mcp-server-python/issues
- Your error might already have a solution
-
Create a GitHub Issue:
- New issue
- Include diagnostic info from above
- Attach sanitized config file and debug logs
-
MCP Community:
- ModelContextProtocol Discord
- Questions about MCP protocol or agent integration
| Term | Definition |
|---|---|
| MATLAB Engine | The background MATLAB process that executes code; managed by the pool |
| Engine Pool | The set of active MATLAB engines; scales dynamically from min to max |
| Session | A user's workspace isolation layer; each session has its own temp directory and session ID |
| Job | An async task that executes MATLAB code; returns a job_id for polling |
| Transport | How agents connect: stdio (local), sse (multi-user, deprecated), or streamablehttp (multi-user, preferred) |
| Blocklist | List of dangerous MATLAB functions (e.g., system, eval) that are blocked for security |
| MCP | Model Context Protocol — the standard for AI agent integrations |