Run backend script
run_backend_scriptRuns multi-line scripts (bash, Python, Perl, PowerShell) on a remote backend host to handle looped or multi-step tasks, returning exit code, stdout, and stderr.
Instructions
Run a multi-line script on a remote host: sh, bash, python3 or perl on POSIX, PowerShell on WinRM. Use when: the job needs loops or a scripting language there. Instead: run_backend_command for one command; run_script on this machine. Requires: --mcp-tools exec and --mcp-allow-exec; not in paranoid mode; a backend that list_backends gives commands (not null). Behavior: destructive - runs with the profile user's rights. The script goes to the interpreter's stdin, so it cannot read stdin itself. Refused on production profiles and Cisco. Time limit: timeout; past it the call fails and no output returns. Returns: {returncode, stdout, stderr, truncated_stdout, truncated_stderr} (text, UTF-8 with undecodable bytes replaced).
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"script": "<script>",
"backend": "<backend>"
},
"name": "run_backend_script"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| env | No | Environment variables for the script as {NAME: value}, e.g. {"LANG": "C"}. On POSIX shells they are exported in the command line, so other users of the host may see the values: pass no secrets this way. | |
| args | No | Arguments passed to the script ($1... / sys.argv[1:]) as raw strings; the server shell-quotes each one. POSIX hosts only. Default: none. | |
| script | Yes | The script text, e.g. 'for f in /var/log/*.log; do wc -l "$f"; done'. | |
| backend | Yes | Backend id from list_backends (can_run_commands=true), e.g. 'profile:web1'. | |
| timeout | No | Seconds the script may run (at most 1740, below the call's 30 min); longer fails with a timeout error and returns no output. | |
| max_output | No | Most bytes of stdout kept; stderr keeps min(max_output, 1 MiB). truncated_stdout / truncated_stderr tell when output was cut. | |
| interpreter | No | What runs the script. powershell: WinRM only (its default); bash, perl, python3, sh (the POSIX default): POSIX only; a mismatch fails. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| stderr | Yes | ||
| stdout | Yes | ||
| returncode | Yes | ||
| truncated_stderr | Yes | ||
| truncated_stdout | Yes |