-
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: MATLAB must be on your system PATH, or set
matlab_rootin config:pool: matlab_root: "/Applications/MATLAB_R2024a.app"
-
Increase engine start timeout: If MATLAB is slow to start:
pool: engine_start_timeout: 300 # 5 minutes (default: 120s)
-
Check MATLAB licensing: Ensure your MATLAB license is valid and not in use elsewhere. The Engine API requires a valid license checkout.
Symptom: Server starts but engines fail to initialize, or "min_engines not reached" warnings
Solutions:
-
Check min_engines setting:
pool: min_engines: 2 # reduces startup load; increase gradually if needed
-
Verify MATLAB is accessible: Try starting MATLAB manually to confirm it's not blocked by antivirus or permissions.
-
Check log file for startup errors:
tail -f ./logs/server.log | grep -i "engine\|error\|failed"
-
Increase drain timeout for graceful shutdown:
server: drain_timeout_seconds: 300 # allow more time for jobs to complete
-
Monitor health checks: Engines undergo periodic health checks. If too many fail:
pool: health_check_interval: 60 # adjust interval if checks are too frequent
Symptom: Warning about max engines on macOS, or MATLAB processes not starting beyond ~4
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: 4Symptom: Jobs are promoted to async too quickly, or sync commands time out unexpectedly
Solutions:
-
Adjust sync timeout (time before auto-promoting to async):
execution: sync_timeout: 30 # default: 30s
Increase for slower commands, decrease to promote long jobs to async faster.
-
Set max execution time (hard limit per job):
execution: max_execution_time: 86400 # 24h; jobs exceeding this are terminated
-
Tune engine start timeout (how long to wait for MATLAB to initialize):
pool: engine_start_timeout: 120 # default: 120s
-
Check SSE drain timeout (graceful shutdown waits for jobs):
server: drain_timeout_seconds: 300 # allow time for running jobs
Enable debug logging to see detailed server activity and troubleshoot issues:
server:
log_level: "debug" # debug | info | warning | error
log_file: "./logs/server.log"Or via environment variable:
export MATLAB_MCP_SERVER_LOG_LEVEL=debug
matlab-mcp --transport sseLog levels:
-
debug— verbose output, MATLAB engine interactions, pool state changes -
info— important events, job start/end, engine allocation -
warning— recoverable errors, deprecated features -
error— failures, exceptions
Check logs:
# Real-time monitoring
tail -f ./logs/server.log
# Search for errors
grep ERROR ./logs/server.log
# Search for a specific job
grep "job_12345" ./logs/server.logTo enable debug logging on startup without modifying config.yaml:
export MATLAB_MCP_SERVER_LOG_LEVEL=debug
matlab-mcpOr start the server with:
MATLAB_MCP_SERVER_LOG_LEVEL=debug matlab-mcp --transport sseThe logger will output detailed information about:
- Engine pool lifecycle (startup, health checks, scaling)
- MATLAB engine connections and disconnections
- Code execution (pre-check, execution, result extraction)
- Job queuing and async promotion
- Session management
- Security validation
Symptom: Docker container can't connect to MATLAB, or client can't reach SSE endpoint
Solutions:
-
Ensure MATLAB is mounted correctly:
docker run -v /path/to/MATLAB:/opt/matlab:ro \ -e MATLAB_MCP_POOL_MATLAB_ROOT=/opt/matlab \ matlab-mcp
-
Verify MATLAB root path in container:
docker exec <container_id> ls -la /opt/matlab
-
Map ports correctly for SSE:
docker run -p 8765:8765 -p 8766:8766 \ -e MATLAB_MCP_SERVER_TRANSPORT=sse \ matlab-mcp
Port 8765 is for SSE connections, 8766 is for the monitoring dashboard.
-
Use docker-compose for simplified configuration:
# Edit docker-compose.yml to set your MATLAB path # Example: volumes: ["/Applications/MATLAB_R2024a.app:/opt/matlab:ro"] docker compose up
-
Bind to 0.0.0.0 for remote access:
server: host: "0.0.0.0" # listen on all interfaces port: 8765
Or via environment:
export MATLAB_MCP_SERVER_HOST=0.0.0.0 -
Check container logs:
docker logs <container_id> --tail 100
Symptom: Client can't connect to http://localhost:8765/sse or connection times out
Solutions:
-
Check the server is running:
matlab-mcp --transport sse
Look for:
Server listening on http://0.0.0.0:8765 -
Verify port is correct: Default is 8765
server: port: 8765
-
Check host binding: Use
0.0.0.0for remote access,127.0.0.1for local onlyserver: host: "0.0.0.0" # all interfaces
-
Firewall: Ensure port 8765 is open
# macOS sudo lsof -i :8765 # Linux sudo netstat -tlnp | grep 8765
-
Test connectivity:
curl http://localhost:8765/sse # should establish connection
Symptom: BlockedFunctionError: Function 'system' is blocked
Explanation: The security validator blocks dangerous functions by default for safety.
Solutions:
-
Use MATLAB-native alternatives instead of
system():- File operations:
dir,mkdir,copyfile,movefile,delete - Environment:
getenv,setenv - Shell commands: Use MATLAB equivalents where possible
- 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
-
Review your code: Check if you're using
eval,feval,evalin, orassignin— these are also blocked by default.
Symptom: Job never completes, progress stops updating, or job status is always "running"
Solutions:
-
Cancel the job:
# Request your agent to call cancel_job # Or use: matlab-mcp-cli cancel-job <job_id>
-
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 % Your computation here if mod(i, 1000) == 0 mcp_progress(__mcp_job_id__, i/n*100, sprintf('Iteration %d/%d', i, n)); end end
-
Monitor job status:
# Check job status periodically matlab-mcp-cli job-status <job_id>
-
Check server logs for stalled jobs:
grep "job_id\|RUNNING" ./logs/server.log | tail -20
-
Verify workspace isolation: If enabled, jobs may block on workspace access:
execution: workspace_isolation: true # ensure not causing contention
Symptom: No interactive plot returned, only text output or static image
Explanation: The Plotly converter (mcp_extract_props.m) supports common plot types. Some complex or custom plot types may not convert.
Solutions:
-
Check supported types: line, scatter, bar, area, histogram, surface, image, subplots (
subplot/tiledlayout) -
Simplify the plot: Complex multi-axis, custom graphics, or 3D plots may not convert fully
-
Static fallback: A PNG image is always generated even if Plotly conversion fails
-
Disable Plotly conversion: Fall back to static images only:
output: plotly_conversion: false
-
Check conversion logs:
grep -i "plotly\|conversion" ./logs/server.log -
Enable debug logging to see conversion details:
export MATLAB_MCP_SERVER_LOG_LEVEL=debug matlab-mcp
Symptom: Output is cut off, saved to file, or only summary is returned
Explanation: Results exceeding max_inline_text_length (50,000 chars) or large arrays (>10,000 elements) are saved to file instead of returned inline.
Solutions:
-
Increase limits:
output: max_inline_text_length: 100000 # chars large_result_threshold: 50000 # elements
-
Use
list_files+read_datato access the full output file:% In your MATLAB code large_matrix = randn(100000, 100); save('large_output.mat', 'large_matrix');
Then the agent can call
list_files()to findlarge_output.matandread_data('large_output.mat')to retrieve it. -
Stream results: For very large outputs, consider breaking into chunks.
Symptom: Variables persist between sessions, or workspace is unexpectedly cleared
Explanation: Workspace isolation can be enabled per-session to prevent variable leakage between users.
Solutions:
-
Enable workspace isolation:
execution: workspace_isolation: true
-
Verify engine affinity: If disabled, engines are reused across sessions (faster but shared state):
execution: engine_affinity: false # engines reset after each session
-
Check workspace startup commands: These run on every engine start/reset:
workspace: startup_commands: - "clear all" - "format long"
-
Monitor session cleanup:
grep "session\|cleanup" ./logs/server.log
Symptom: check_code returns warnings, or code doesn't execute as expected
Solutions:
-
Review warnings: MATLAB's
checkcode(mlint) may warn about:- Unused variables
- Potential issues with variable types
- Performance suggestions
- Code structure
-
Auto-check before execution:
code_checker: enabled: true auto_check_before_execute: true # default: false
-
Filter severity levels:
code_checker: severity_levels: ["error", "warning"] # or just ["error"]
-
Suppress specific warnings: Add MATLAB comments to your code:
%#ok<NUSED> % suppress "unused variable" warning x = some_expensive_computation();
Symptom: Custom tools don't appear in tool list, or custom_tools config is ignored
Solutions:
-
Verify config file path:
custom_tools: config_file: "./custom_tools.yaml"
File must exist and be valid YAML.
-
Check MATLAB functions exist:
% In MATLAB, verify your function is on the path which mylib.analyze_signal % should return path
-
Add paths to workspace:
workspace: default_paths: - "/path/to/mylib"
-
Validate custom_tools.yaml syntax:
python -c "import yaml; yaml.safe_load(open('./custom_tools.yaml'))" -
Check server logs for parsing errors:
grep -i "custom_tools\|yaml\|parse" ./logs/server.log
Symptom: get_server_health returns "degraded" or "unhealthy"
Solutions:
-
Check health status:
# Via API matlab-mcp-cli server-health -
Review metrics:
matlab-mcp-cli server-metrics
Look for: engine failures, queue backlog, session count, memory usage.
-
Restart the server if persistently degraded:
# Allow graceful shutdown (drain_timeout_seconds) kill -TERM <pid> matlab-mcp
-
Check system resources:
top # CPU, memory, thread count -
Review error log:
matlab-mcp-cli error-log --limit 50