Run a console command
console_execRuns console command lines in menu, client, or server realms, returns the printed output, and reports read-back convar values or unknown-command errors.
Instructions
Runs a console command line from a realm (menu: RunConsoleCommand; server: game.ConsoleCommand; client: RunConsoleCommand, with automatic fallback to the engine if the command is blocked from Lua). Like the engine console, ';' and line breaks outside quotes separate commands: 'a 1; b 2' runs a then b (statements lists them). Waits a few frames then returns the console lines printed meanwhile (gmod-mcp's own log lines left out; the console is shared, so filter with regex). An unknown command or convar is an error (unknown_command), not a silent no-op. For every convar it set or named, convars gives the value read back (value, number, and a warning for FCVAR_ARCHIVE convars, which land in the user's config and are shared by every instance). killserver on a game that hosts a map first leaves it like disconnect (left_game_first: true): run in game it can crash the engine. Example: {"cmd": "sv_gravity 600"}. convar_set refuses archived convars unless persist: true.
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": {
"cmd": "<cmd>"
},
"name": "console_exec"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cmd | Yes | Command line, e.g. 'echo hello' or 'sv_gravity 600'. | |
| realm | No | Execution realm (default: menu in client mode, server on srcds). | |
| regex | No | Keep only the output lines matching this (ECMAScript, case-insensitive). | |
| instance | No | Optional. Instance identifier (see instances_list). If present and different from the local instance, the call is relayed by the coordinator to that instance. | |
| wait_frames | No | Frames to wait before reading the output (default 5). | |
| connect_timeout_s | No | For `connect`: how long to wait for the outcome, reported in connect_result (default 20). |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cmd | Yes | ||
| via | Yes | ||
| next | No | ||
| note | No | ||
| realm | Yes | ||
| output | Yes | ||
| convars | No | ||
| warning | No | ||
| next_call | No | ||
| statements | No | ||
| answered_by | No | ||
| next_cursor | Yes | ||
| output_note | No | ||
| blocked_in_lua | No | ||
| connect_result | No | ||
| truncated_note | No | ||
| left_game_first | No | ||
| version_warning | No |