matlab-mcp-server
- Type
- MCP server
- Scanned
- Nov 12, 2026
- Version
- 2a3ed9144ced
- Files read
- 2046
This official MathWorks server lets AI assistants start or connect to MATLAB on your computer to check scripts for issues and run code or tests. The biggest risk is that it can run any command or change any file under your account through MATLAB, and even its read-only tools can silently run untrusted startup scripts from a project folder without asking you.
What it can reach
- Files
- Reads configuration and session files in your home folder, writes logs and temporary files, and can read, change, or delete any file you have access to when running MATLAB code.
- Shell commands
- Starts local MATLAB programs and can run any operating system command under your user account through MATLAB scripts.
- Network
- Talks locally to MATLAB, sends anonymous usage data to MathWorks over the internet unless turned off, and allows MATLAB scripts to make any outbound network connection.
- System
- Reads environment variables and system settings to find installed MATLAB versions, changes open-file limits, and runs a background helper to close MATLAB sessions.
Findings
-
MediumRead-only tools launch MATLAB in the workspace root and execute untrusted startup.m or shadowed .m files
internal/adaptors/matlabmanager/matlabservices/services/localmatlabsession/localmatlabsession.go:76
By default, when --initial-working-folder is not set, the server sets MATLAB's starting working directory to the MCP client's first workspace root. Both check_matlab_code and detect_matlab_toolboxes are annotated with ReadOnlyHint=true (so MCP clients skip user confirmation), and check_matlab_code states that it analyzes scripts without executing code. However, invoking either tool starts MATLAB in the workspace folder (if not already attached to a shared session) and runs MATLAB functions while pwd is that folder. Because MATLAB automatically executes startup.m/startup.p from its starting folder on launch and gives files in pwd higher precedence than addpath() and built-in toolbox functions (such as +matlab_mcp/initializeMCP.m, +matlab_mcp/mcpEval.m, codeIssues.m, checkcode.m, and ver.m), opening an untrusted repository and running a read-only check—or merely connecting when --initialize-matlab-on-startup=true is enabled—executes arbitrary MATLAB code from the workspace.
Fix: Start local MATLAB sessions in the private 0700 session directory rather than the untrusted workspace root, avoid running startup.m from untrusted folders, and ensure read-only tools invoke built-in analysis functions from a clean working directory before changing folders.
-
Lowstart_matlab_session is marked read-only and executes unvalidated matlab_root binaries
internal/adaptors/mcp/tools/multisession/startmatlabsession/tool.go:35
When multi-session mode is enabled (--use-single-matlab-session=false), the start_matlab_session tool is registered with NewReadOnlyAnnotations() (ReadOnlyHint=true, DestructiveHint=false), signaling to MCP hosts that it can be auto-approved without user confirmation. However, the tool accepts an arbitrary matlab_root path from the agent and passes it directly to the process launcher without checking that it matches a discovered MATLAB installation or even contains VersionInfo.xml, executing <matlab_root>/bin/matlab on Unix or <matlab_root>/bin/win64/MATLAB.exe on Windows. Prompt injection in content read by the agent can therefore launch an attacker-controlled binary from a workspace or downloaded folder without triggering destructive-tool confirmation.
Fix: Mark start_matlab_session with destructive annotations (NewDestructiveAnnotations) and validate matlab_root against discovered MATLAB environments or verified MATLAB installations before starting a process.
-
LowWatchdog Unix socket lacks permission restrictions and falls back to world-writable /tmp on macOS
internal/watchdog/transport/socket/socket.go:90
The watchdog process runs an unauthenticated HTTP server over a Unix domain socket exposing POST /process (registering a PID to SIGKILL on exit) and POST /shutdown. In udsserver.go, net.Listen("unix", socketPath) relies on the process umask without restricting socket permissions to 0600 or checking peer credentials. Furthermore, on macOS, when socketPath exceeds 105 characters (for example, when --log-folder or Claude Desktop's BaseDir points inside ~/Library/Application Support/...), newSocket places the socket directly in world-writable /tmp/watchdog-<id>.sock while passing <id> on the watchdog command line (visible to local users via ps). On a multi-user machine, another local user can race socket creation in /tmp or connect under a permissive umask to hijack watchdog IPC or cause the watchdog to kill processes owned by the user.
Fix: Place fallback sockets inside a private 0700 directory created with os.MkdirTemp, restrict the Unix socket file mode to 0600, and authenticate requests or verify peer credentials on the socket.
