ssh_exec
Run shell commands on remote servers and capture full output. Supports timeout and background tasks that survive disconnects.
Instructions
Run a shell command on the remote host and return its full stdout/stderr/exit status. Blocks until the command finishes or the wall-clock timeout expires (SIGTERM then SIGKILL).
WHEN TO USE ssh_exec:
Short commands that finish in under ~60s.
Fire-and-forget background tasks that must SURVIVE a disconnect (use nohup or screen so the process keeps running even if the MCP server restarts or Zed closes).
SURVIVING DISCONNECT — nohup pattern: ssh_exec('nohup python -u train.py > /tmp/train.log 2>&1 &')
process keeps running after disconnect; check later with:
ssh_exec('tail -n 50 /tmp/train.log') ssh_exec('ps aux | grep train.py')
SURVIVING DISCONNECT — screen pattern: ssh_exec('screen -dmS myjob bash -c "python train.py > /tmp/out.log 2>&1"')
reattach later: screen -r myjob
WARNING: ssh_spawn ties the remote process to the MCP channel — it dies on disconnect. Use ssh_exec+nohup/screen for tasks that must outlive the current session.
For real-time streaming output of a command you will watch to completion without disconnecting, use ssh_spawn + ssh_tail instead.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| command | Yes | The shell fragment to run on the remote. Passed to ``bash -c`` after a PID-capture prelude; your own shell metacharacters (``|``, ``&&``, ``$VAR``, etc.) work normally. | |
| host | No | Alias of the configured host, or its raw address. If omitted, the server's ``default_host`` is used. When only a single host is configured, this argument is optional. | |
| timeout_ms | No | Wall-clock budget. On overrun the remote process receives SIGTERM, then (after 5 s grace) SIGKILL. Set to 0 or a negative number to disable. | |
| cwd | No | Remote working directory (``cd`` before running). | |
| env | No | Additional environment variables for the remote process. Names must match ``[A-Za-z_][A-Za-z0-9_]*``. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||