-
Notifications
You must be signed in to change notification settings - Fork 0
Troubleshooting
# Troubleshooting
## MATLAB Engine Won't Start
**Symptom:** `Engine start timeout` or `matlab.engine not found`
**Solutions:**
1. **Verify MATLAB Engine API is installed:**
```bash
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 R2022b or later.
-
Check MATLAB is on PATH or set
matlab_rootin config:pool: matlab_root: "/Applications/MATLAB_R2024a.app" # macOS # matlab_root: "C:\\Program Files\\MATLAB\\R2024a" # Windows
-
Increase engine start timeout: If MATLAB is slow to start:
pool: engine_start_timeout: 300 # 5 minutes
-
Check engine logs: Set log level to debug to see detailed startup errors:
server: log_level: "debug" log_file: "./logs/server.log"
Symptom: MinEngines failed to initialize or engines not starting on server launch
Solutions:
-
Check minimum engines setting: Ensure
min_enginesis achievable on your system:pool: min_engines: 2 # 4 or more on macOS may exceed platform limits max_engines: 10
-
Verify MATLAB license availability: Multiple concurrent MATLAB instances require sufficient licenses:
# macOS: typical limit is ~4 concurrent engines # Windows: limit depends on your license agreement
-
Check disk space: MATLAB engine startup requires temporary files. Ensure
/tmp(Unix) or%TEMP%(Windows) has space. -
Gradual startup: The pool warms up engines over time if initial startup fails:
pool: proactive_warmup_threshold: 0.8 # starts new engine if utilization > 80%
Symptom: Failed to connect to MATLAB engine or Engine died unexpectedly
Solutions:
-
Check engine health: Monitor engine status:
# Call get_pool_status to see available/busy/max engines -
Enable health checks: Ensure health monitoring is active:
pool: health_check_interval: 60 # ping engines every 60 seconds
-
Check for workspace corruption: Reset the workspace:
execution: workspace_isolation: true # isolate each job's workspace
-
Increase queue size if backed up:
pool: queue_max_size: 50 # increase if jobs are being rejected
Symptom: Client can't connect to http://localhost:8765/sse
Solutions:
-
Check the server is running:
matlab-mcp --transport sse
-
Check port is available: Default is 8765
# macOS/Linux lsof -i :8765 # Windows netstat -ano | findstr :8765
-
Check host binding: Default is
0.0.0.0for all interfacesserver: host: "0.0.0.0" # all interfaces port: 8765
-
Firewall: Ensure port 8765 (and 8766 for monitoring) are open:
# macOS example sudo pfctl -f /etc/pf.conf # reload firewall rules
-
Docker networking: See Docker Networking Issues section
Symptom: Container runs but can't connect from host, or MATLAB engine won't start in Docker
Solutions:
-
Ensure MATLAB is properly mounted:
docker run -p 8765:8765 -p 8766:8766 \ -v /path/to/MATLAB:/opt/matlab:ro \ -e MATLAB_MCP_POOL_MATLAB_ROOT=/opt/matlab \ matlab-mcp --transport sse
-
Check MATLAB path in container:
docker exec <container_id> ls -la /opt/matlab/bin/matlab
-
Use docker-compose: Simplifies environment setup:
# Edit docker-compose.yml, then: docker compose up -
Port mapping: Ensure both SSE (8765) and monitoring (8766) ports are mapped:
docker run -p 8765:8765 -p 8766:8766 matlab-mcp
-
Volume permissions: MATLAB needs to write temp files:
# Add temp directory volume -v /tmp/matlab-temp:/tmp:rw \ -e MATLAB_MCP_EXECUTION_TEMP_DIR=/tmp/matlab-temp -
Network mode: For host access, use host network on Linux:
docker run --network host matlab-mcp --transport sse
Symptom: Fast jobs timeout, or slow jobs hang indefinitely
Solutions:
-
Sync timeout (promotion to async):
execution: sync_timeout: 30 # seconds before returning job ID instead of blocking
Increase for slower machines, or if you want fast jobs to stay synchronous:
export MATLAB_MCP_EXECUTION_SYNC_TIMEOUT=60 -
Execution hard limit:
execution: max_execution_time: 86400 # 24 hours
Safety limit to prevent jobs from running forever:
export MATLAB_MCP_EXECUTION_MAX_EXECUTION_TIME=3600 -
Engine startup timeout:
pool: engine_start_timeout: 120 # seconds to wait for MATLAB process
Increase on slow systems:
export MATLAB_MCP_POOL_ENGINE_START_TIMEOUT=300 -
Scale-down idle timeout:
pool: scale_down_idle_timeout: 900 # 15 min before shutting down idle engines
Increase to keep engines warm:
export MATLAB_MCP_POOL_SCALE_DOWN_IDLE_TIMEOUT=3600 -
Drain timeout during shutdown:
server: drain_timeout_seconds: 300 # wait for running jobs during graceful shutdown
Enable detailed logging for troubleshooting:
server:
log_level: "debug"
log_file: "./logs/server.log"Or via environment variable:
export MATLAB_MCP_SERVER_LOG_LEVEL=debug
matlab-mcp- debug: Everything — engine startup, job queuing, workspace state
- info: Normal operations, job completion, warnings
- warning: Potential issues (high utilization, slow responses)
- error: Failures and exceptions
# View server log
tail -f ./logs/server.log
# Filter for errors
grep ERROR ./logs/server.log
# Filter for a specific job
grep <job_id> ./logs/server.log# Stream container logs
docker logs -f <container_id>
# View past logs
docker logs <container_id> | tail -100Step 1: Update config.yaml:
server:
log_level: "debug"
log_file: "./logs/server.log"Step 2: Or set environment variable:
export MATLAB_MCP_SERVER_LOG_LEVEL=debugStep 3: Restart the server:
matlab-mcp --transport sseStep 4: Check logs:
tail -f ./logs/server.logDebug logs will show:
- Engine startup/shutdown
- Job queuing and dispatch
- Workspace state changes
- Code execution details
- Plot conversion steps
- Network traffic (SSE)
Symptom: Warning about max engines on macOS
Explanation: MATLAB on macOS has a practical limit of ~4 concurrent engine instances. The server warns but respects your configured max_engines.
Solution: Set max_engines: 4 on macOS:
pool:
max_engines: 4Symptom: BlockedFunctionError: Function 'system' is blocked
Explanation: The security validator blocks dangerous functions by default to prevent unintended system access.
Solutions:
-
Use MATLAB-native alternatives instead of
system():- File operations:
dir,mkdir,copyfile,movefile - Environment:
getenv,setenv - Command execution: Use MATLAB functions instead
- File operations:
-
Disable blocklist (not recommended for shared servers):
security: blocked_functions_enabled: false
-
Remove specific functions from blocklist:
security: blocked_functions: - "unix" - "dos" # system removed from list
-
Verify code before executing: Use
check_codetool first:# Checks for blocked functions and best practices
Symptom: Job never completes, progress stops updating
Solutions:
-
Check job status: Call
get_job_statuswith the job ID to see current progress and state. -
Cancel the job: Call
cancel_jobwith the job ID to force termination. -
Check max execution time:
execution: max_execution_time: 86400 # 24h hard limit
Jobs exceeding this are forcibly terminated.
-
Check MATLAB code: Is there an infinite loop? Add progress reporting to debug:
for i = 1:n % ... compute ... mcp_progress(__mcp_job_id__, i/n*100, sprintf('Iteration %d/%d', i, n)); end
-
Check for deadlock: If multiple jobs are waiting for the same resource, they may hang. Review code for synchronization issues.
Symptom: No interactive plot returned, only static PNG
Explanation: The Plotly converter (mcp_extract_props.m) supports common plot types. Some complex or custom plot types may not convert. The server always generates a static PNG fallback.
Solutions:
-
Check supported plot types:
- line, scatter, bar, area, histogram
- surface, image
- subplots (
subplot,tiledlayout) - multiple axes
-
Simplify the plot: Complex multi-axis or custom graphics objects may not convert. Try:
% Instead of complex custom rendering: plot(x, y); % basic plots convert reliably
-
Static fallback is always available: Even if Plotly fails, a PNG image is returned.
-
Disable Plotly conversion (fall back to static only):
output: plotly_conversion: false
-
Check debug logs for Plotly conversion errors:
export MATLAB_MCP_SERVER_LOG_LEVEL=debug grep -i plotly ./logs/server.log
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 saved to file to avoid overloading the agent.
Solutions:
-
Increase limits:
output: max_inline_text_length: 100000 # text output large_result_threshold: 50000 # matrix/table elements
-
Use file API to access full results:
# Agent calls: list_files # find the result file read_data # read with format: "raw" for full output
-
Summarize in MATLAB:
% Instead of returning huge matrix, compute statistics: summary_stats = struct('mean', mean(data), 'std', std(data), ... 'min', min(data), 'max', max(data)); disp(summary_stats);
Symptom: Variables from one job appear in another, or workspace clears unexpectedly
Solutions:
-
Enable workspace isolation (default):
execution: workspace_isolation: true # each job gets clean workspace
-
Persist workspace between jobs: Disable isolation for the same session:
execution: workspace_isolation: false
Note: This is riskier in multi-user environments.
-
Pin session to engine for persistent workspace:
execution: engine_affinity: true # same session always uses same engine
Symptom: check_code returns unexpected warnings, or won't run
Solutions:
-
Ensure code checker is enabled:
code_checker: enabled: true
-
Auto-check before execution:
code_checker: auto_check_before_execute: true # runs checks before execute_code
-
Filter severity levels:
code_checker: severity_levels: ["error", "warning"] # omit "info" or "fix" if noisy
-
Suppress specific warnings in your MATLAB code:
%#ok<NUSED> % suppress "variable unused" warnings %#ok<NASGU> % suppress "assigned but never used"
Symptom: Workspace variables are lost between jobs, or you need persistent state
Solutions:
-
Enable engine affinity:
execution: engine_affinity: true # same session always gets same engine
This ensures a session sticks to one engine, preserving workspace.
-
Disable workspace isolation:
execution: workspace_isolation: false # workspace persists across jobs
Combined with affinity, this gives a stateful MATLAB instance.
-
Use startup commands to initialize workspace on every engine:
workspace: startup_commands: - "addpath('/shared/custom_libs')" - "format long"
Symptom: Session disconnects unexpectedly, or old sessions linger
Solutions:
-
Check session timeout:
sessions: session_timeout: 3600 # seconds of inactivity before cleanup
-
Job retention:
sessions: job_retention_seconds: 86400 # how long to keep completed job metadata
-
Temp directory cleanup:
execution: temp_cleanup_on_disconnect: true # clean session temp files on disconnect
-
Check max sessions limit:
sessions: max_sessions: 50 # reject new sessions if limit reached
Symptom: Server appears healthy but jobs fail, or high latency
Solutions:
-
Get pool status: Call
get_pool_statusto see available/busy/max engines. -
Get server health: Call
get_server_healthto see detailed health status (healthy/degraded/unhealthy). -
Get server metrics: Call
get_server_metricsfor comprehensive pool, job, session, and system stats. -
Access monitoring dashboard:
monitoring: dashboard_enabled: true http_port: 8766 # access at http://localhost:8766
-
Check error log: Call
get_error_logto see recent errors and notable events.
Symptom: Custom tools from custom_tools.yaml don't appear in tool list
Solutions:
-
Check config path:
custom_tools: config_file: "./custom_tools.yaml"
Ensure file exists relative to working directory or use absolute path.
-
Validate YAML syntax:
python -c "import yaml; yaml.safe_load(open('custom_tools.yaml'))" -
Check function paths:
% Verify MATLAB function exists: which mylib.analyze_signal
-
Add to startup paths:
workspace: default_paths: - "/path/to/mylib"
-
Enable debug logging to see tool loading:
export MATLAB_MCP_SERVER_LOG_LEVEL=debug grep -i custom ./logs/server.log
Symptom: Server memory grows over time, or crashes with out-of-memory
Solutions:
-
Monitor metrics: Call
get_server_metricsto see memory usage trends. -
Scale down idle engines:
pool: scale_down_idle_timeout: 900 # shut down idle engines after 15 min min_engines: 2 # keep minimum running
-
Reduce max engines:
pool: max_engines: 6 # fewer concurrent instances = less memory
-
Enable temp cleanup:
execution: temp_cleanup_on_disconnect: true
-
Check for memory leaks in MATLAB code: Profile your code:
memory % check memory usage