-
Notifications
You must be signed in to change notification settings - Fork 0
Troubleshooting
Symptom: Engine start timeout, matlab.engine not found, or Failed to start MATLAB engine
Solutions:
-
Verify MATLAB Engine API is installed:
python -c "import matlab.engine; print('OK')" -
Install the Engine API:
cd /Applications/MATLAB_R2024a.app/extern/engines/python # macOS # cd "C:\Program Files\MATLAB\R2024a\extern\engines\python" # Windows pip install .
-
Check MATLAB version: Must be 2020b or later.
-
Check PATH and MATLAB root:
- MATLAB must be on your system PATH, or
- Set
matlab_rootexplicitly in config:
pool: matlab_root: "/Applications/MATLAB_R2024a.app" # macOS # matlab_root: "C:\\Program Files\\MATLAB\\R2024a" # Windows
-
Increase engine startup timeout: If MATLAB is slow to start:
pool: engine_start_timeout: 300 # 5 minutes
-
Check system resources: Verify you have sufficient RAM and disk space. MATLAB engines consume significant memory (~500MB–2GB each).
-
Verify no MATLAB sessions are locked: Kill any existing MATLAB processes and try again:
# macOS/Linux pkill -f matlab # Windows taskkill /IM MATLAB.exe /F
Symptom: Failed to initialize engine pool or engines repeatedly crash during startup
Solutions:
-
Check minimum engines configuration:
pool: min_engines: 2 # Start with fewer engines max_engines: 4 # Constrain maximum
If pool initialization fails, reduce
min_enginesto 1 to identify which engine is failing. -
Enable debug logging (see below) to see detailed startup sequence:
server: log_level: "debug"
-
Check for licensing issues: MATLAB concurrent license server may be unavailable:
# Test MATLAB directly matlab -r "quit"
If this hangs or fails, contact your MATLAB license administrator.
-
Platform-specific limits:
-
macOS: Hard limit of 4 concurrent engines. Set:
pool: max_engines: 4
- Windows/Linux: No hard limit, but available RAM constrains pool size.
-
macOS: Hard limit of 4 concurrent engines. Set:
-
Clean up stale processes:
# List MATLAB processes ps aux | grep matlab # macOS/Linux tasklist | findstr matlab # Windows # Kill all MATLAB processes pkill -9 -f matlab
Symptom: Jobs time out unexpectedly, or fast code is promoted to async too early
The server runs code synchronously for fast operations. If code exceeds sync_timeout, it's automatically promoted to an async job:
execution:
sync_timeout: 30 # seconds — increase for slower operationsSolutions:
-
For operations taking 30–120 seconds:
execution: sync_timeout: 120 # 2 minutes
-
For long-running jobs (hours): Use async explicitly. The job will run with a hard time limit:
execution: max_execution_time: 86400 # 24 hours
-
Per-job timeout considerations:
- Sync operations: Limited by
sync_timeout - Async operations: Limited by
max_execution_time - Large file I/O: May need extended
sync_timeout
- Sync operations: Limited by
-
Monitor actual job duration: Use
get_job_statusto track progress. Jobs inrunningstate will report estimated time remaining.
Via config file:
server:
log_level: "debug"
log_file: "./logs/server.log"
drain_timeout_seconds: 300Via environment variable:
export MATLAB_MCP_SERVER_LOG_LEVEL=debug
matlab-mcpView logs:
tail -f ./logs/server.log-
debug— Detailed information on pool operations, engine lifecycle, job scheduling -
info— Standard operational messages (default) -
warning— Non-critical issues (e.g., slow jobs) -
error— Failures that impact functionality
-
Engine startup:
[DEBUG] Engine 1: Starting matlab.engine.start_matlab() [DEBUG] Engine 1: Connected in 3.2s -
Job execution:
[DEBUG] Job abc123: Assigned to Engine 2 [DEBUG] Job abc123: Sync execution, timeout in 30s [DEBUG] Job abc123: Completed in 2.1s -
Pool scaling:
[DEBUG] Pool: Utilization 95%, warmup triggered [DEBUG] Engine 3: Starting proactive warmup -
Errors:
[ERROR] Engine 2: Connection lost [DEBUG] Engine 2: Attempting reconnect...
Symptom: Connection refused when accessing SSE endpoint from host or other containers
Solutions:
-
Check Docker port mapping:
docker run -p 8765:8765 -p 8766:8766 matlab-mcp
-
8765— MCP SSE transport -
8766— Dashboard (monitoring)
-
-
Access from host:
# Inside container, server listens on 0.0.0.0:8765 # From host, connect to localhost:8765 curl http://localhost:8765/sse
-
Access from another container:
# Use docker-compose networking docker-compose up # Other containers can reach: http://matlab-mcp:8765
-
Fix binding to 0.0.0.0: Ensure config has:
server: transport: "sse" host: "0.0.0.0" # Listen on all interfaces port: 8765
-
MATLAB path in Docker: Mount your MATLAB installation and set
matlab_root:docker run -v /opt/matlab:/opt/matlab:ro \ -e MATLAB_MCP_POOL_MATLAB_ROOT=/opt/matlab \ -p 8765:8765 matlab-mcp
-
Check network connectivity:
# Inside container docker exec <container_id> bash apt-get update && apt-get install -y curl curl http://localhost:8765/sse
-
View container logs:
docker logs -f <container_id>
Single command:
export MATLAB_MCP_SERVER_LOG_LEVEL=debug
matlab-mcpOr in config.yaml:
server:
log_level: "debug"
log_file: "./logs/server.log"-
Check for engine failures:
grep -i "error\|failed\|exception" ./logs/server.log -
Trace a specific job:
grep "job_abc123" ./logs/server.log -
Monitor pool health:
grep "Pool\|Engine" ./logs/server.log | head -50
-
Find timeout issues:
grep "timeout\|exceeded" ./logs/server.log
Symptom: BlockedFunctionError: Function 'system' is blocked
Explanation: The security validator blocks dangerous functions by default to prevent shell injection and unauthorized access.
Solutions:
-
Use MATLAB-native alternatives instead of blocked functions:
- Shell commands →
system()blocked - File operations: Use
dir,mkdir,copyfile,movefile,delete - Environment variables: Use
getenvinstead of shell access - OS operations: Use MATLAB toolbox functions
- Shell commands →
-
Disable the blocklist (not recommended for shared servers):
security: blocked_functions_enabled: false
-
Remove specific functions from blocklist:
security: blocked_functions: - "unix" - "dos" - "!" - "eval" # "system" removed — now allowed
Symptom: Warning about max engines on macOS, or insufficient engines available
Explanation: MATLAB on macOS has a system limit of approximately 4 concurrent engine instances. The server warns but respects your configured max_engines.
Solution: Set max_engines: 4 on macOS:
pool:
max_engines: 4Jobs exceeding capacity will queue with a status of pending until an engine becomes available.
Symptom: Client can't connect to http://localhost:8765/sse
Solutions:
-
Check the server is running:
matlab-mcp --transport sse
Should output:
MCP Server (SSE) listening on http://0.0.0.0:8765 -
Check port and host:
- Default is
8765on all interfaces (0.0.0.0) - For remote access, ensure firewall allows port 8765
- For local-only access, change to
127.0.0.1:
server: host: "127.0.0.1" # local only
- Default is
-
Verify no port conflict:
# macOS/Linux lsof -i :8765 # Windows netstat -ano | findstr :8765
-
Firewall and network:
- Ensure port 8765 is open in your firewall
- If behind a proxy, configure the client for proxy authentication:
security: require_proxy_auth: true
-
Test with curl:
curl -i http://localhost:8765/sse # Should respond with 200 and keep-alive headers
Symptom: Job never completes, progress stops updating, or MATLAB appears hung
Solutions:
-
Check job status and progress:
get_job_status(job_id) % shows running/pending/completed, + progress %
-
Cancel the job:
cancel_job(job_id) % sends cancel signal to MATLAB
-
Check max execution time: If a job exceeds this, it's forcefully terminated:
execution: max_execution_time: 86400 # 24 hours
-
Debug MATLAB code:
- Is there an infinite loop?
- Is the code waiting for user input?
- Add progress reporting to debug:
for i = 1:n % do work if mod(i, 100) == 0 mcp_progress(__mcp_job_id__, i/n*100, sprintf('Iteration %d/%d', i, n)); end end
-
Check engine health:
# View pool status get_pool_status()
If an engine is
stuck, it will be marked unhealthy and a new one will start. -
Increase sync timeout if promoting too early:
execution: sync_timeout: 60 # give longer for sync operations
Symptom: No interactive plot returned, only text output or static PNG
Explanation: The Plotly converter (mcp_extract_props.m) supports common plot types. Some complex or custom plot types may not convert.
Solutions:
-
Check supported plot types:
-
line,scatter,bar,area -
histogram,surface,image -
subplotandtiledlayoutlayouts - Multiple axes with shared/independent scales
-
-
Simplify the plot:
- Complex multi-axis or custom graphics may not convert fully
- Remove custom renderers or uipanel elements
- Use standard MATLAB plot functions
-
Static fallback:
- A PNG image is always generated even if Plotly conversion fails
- A thumbnail (400px width) is also created
- Check
list_filesfor_plot.pngand_thumb.png
-
Disable Plotly conversion: Fall back to static images only:
output: plotly_conversion: false
-
Adjust static image quality:
output: static_image_format: "png" # png | jpg | svg static_image_dpi: 150 # increase for higher quality thumbnail_enabled: true thumbnail_max_width: 400
Symptom: Output is cut off or saved to file instead of returned inline
Explanation: Results exceeding max_inline_text_length (50,000 chars) or large_result_threshold (10,000 elements) are automatically saved to file instead of returned inline.
Solutions:
-
Increase limits:
output: max_inline_text_length: 100000 # chars large_result_threshold: 50000 # matrix/table elements
-
Use file-based retrieval:
list_files() % find output files read_data("result.csv", "raw") % read full data
-
Reduce result size:
- Summarize large matrices:
disp(summary(data)) - Save only needed columns:
disp(data(:, [1 2 5])) - Downsample large datasets before display
- Summarize large matrices:
Symptom: Need to check overall server health or debug performance issues
Solutions:
-
Check server health:
get_server_health() % returns: healthy | degraded | unhealthy -
View server metrics:
get_server_metrics() % pool utilization, jobs, sessions, system load -
View recent errors:
get_error_log(limit=20) % last 20 errors/events
-
Check pool status:
get_pool_status() % available/busy/max engines -
Dashboard (SSE transport only): Open
http://localhost:8766to view real-time metrics and health status.