Launch test clients
instances_launchStarts 1–8 extra Garry's Mod test clients, optionally loads a map, and returns instance IDs and PIDs for parallel testing.
Instructions
Starts 1 to 8 extra Garry's Mod clients for tests, and works while no game runs (the first one then becomes the main instance). Each starts with -multirun, gmod-mcp on, a small window and a frame cap, waits until it answers, then loads map through map_load (never +map: a game loading a map in the background can grab the mouse). Returns their instance ids and pids: pass an id as instance on every call. Without keep: true they end with this bridge session (when it ends, the clients it started are closed, also when the bridge is killed: they run in a job object that dies with it); with keep: true they outlive it, and a later session closes them by owner (below) or by pid / game_terminate. They close when this session ends unless keep is true; close them earlier with instances_close (not game_quit: it keeps their exit short; a clean quit is safe too, see the convar note below). Sub-agents of one Claude Code session share this bridge: give each one's clients an owner label and close them with instances_close {owner}, never {all: true}, which would close the other sub-agents' clients too. The owner label goes to the game (-mcp_owner) and back in its heartbeat: instances_list shows owner on every instance whichever bridge session launched it, and instances_close {owner} also closes keep: true test clients of an EARLIER session that carry that label (only test clients started by instances_launch, never the user's own game or an instance without the tag). The game is found through Steam; pass game_dir (the folder holding gmod_win64.exe or bin/win64/gmod.exe) if it is elsewhere. Windows only for now.
Presets: 'light' (default: 640x360, 20 fps; for most tests, NOT for performance measurements: the 20 fps cap hides per-frame cost) and 'normal' (640x360, 30 fps; for rendering checks, screenshots and frame-time sensitive tests). sound: false (-nosound) changes what the engine reports about sounds: SoundDuration of compressed (ADPCM) WAV files differs (0.49 s instead of 1.24 s seen); keep sound on for sound tests.
Pass-through options (checked before anything starts; a refused one is invalid_params naming it): fps_max and fps_max_nofocus (integers: 0 = no cap, or 10 to 1000) replace the preset's frame cap (fps_max_nofocus follows fps_max when only that one is given): timing-sensitive tests give different verdicts at 20, 45 and 300 fps, and perf measurements need more than 30. commands: console commands run on each client once it answers, before map loads, one at a time in order, e.g. ["fps_max 300", "snd_mute_losefocus 0"] (a ; splits a line as in the console); refused: quit and exit (close with instances_close), connect, retry, redirect and connect_lobby (gmod-mcp never connects to a server) and map changes (map, changelevel, load: use map). Each result is in instances[i].commands [{cmd, ok, error?}]; a command that fails makes the call isError, the others still run. launch_args: extra engine command-line tokens, one per array element (a printable ASCII word without spaces, quotes or ;), e.g. ["-noborder", "+cl_showfps", "1"]; a +name value token runs a console command at startup. Refused: what gmod-mcp sets itself (-multirun, -mcp*, -w, -h, -width, -height and the window-mode options, -dxlevel, -condebug, -game), +connect and the other connecting or map-loading commands. -nosound is the same as sound: false. Archived convars changed this way (fps_max, a +convar token, a command such as cl_showfps 1 or toggle snd_mute_losefocus) are given back to the user's value before a clean quit like the frame cap (needs the module of this release in the game folder: an older module restores only fps_max, fps_max_nofocus, engine_no_focus_sleep and snd_mute_losefocus; a convar changed by exec of a cfg file is not tracked). Where the options are listed: command-line options, Valve Developer Community "Command line options" (https://developer.valvesoftware.com/wiki/Command_line_options) and, for the GMod-specific ones, the Garry's Mod wiki (wiki_search "command line"); console commands and convars: api_search and concommand_list on a running client.
All clients share the game folder with the user's own game: same addons, cfg, data/ and cookies (sv.db/cl.db). A test that writes cookies, data files or archived convars changes the user's game too: clean up after it. The frame cap and the focus options these clients start with (fps_max, fps_max_nofocus, snd_mute_losefocus) are archived convars: the module gives each one the user's value from cfg/config.cfg (its default when the file has no line) before the client quits cleanly (game_quit, console quit, the Quit button, the window's close button; not a quit the user types by hand in that client's console), so none of them leaks into the user's config. Closing with instances_close kills the process and writes nothing.
Video settings: the clients start with -dxlevel 95, so the engine neither reads nor writes the user's stored video mode (resolution, anti-aliasing): the user's own game keeps its resolution.
Measured cost per client on gm_construct (16-core PC, the game and its 4 browser subprocesses): light about 19% of one core, 1.55 GB of commit (virtual memory) and 1.2 GB of RAM; normal 24% and the same memory. Eight clients: about 1.5 cores and 12 GB. Memory is the limit, not CPU: a machine out of commit makes every game crash (0xC000041D, no dump), so before starting anything this call checks the free commit and free RAM and refuses with the error low_memory {details: free_commit_mb, free_ram_mb, running_clients (all sessions: the registered instances, this bridge's clients and every process of the game's executable, so clients another session started that have not registered yet count), registered_clients, game_processes, per_client_mb, count, needed_commit_mb, needed_ram_mb} when they do not cover the clients asked for (1.6 GB of commit each plus 1 GB for the rest of the machine, 1.2 GB of RAM each); nothing is started then. Close clients you no longer use (instances_close), start fewer, or pass ignore_low_memory: true to start anyway. The frame cap is what saves CPU (30 to 20 fps: -20%); sound: false saves about 12% more. Window size barely matters, and a client narrower than 640 pixels crashes while loading a map (integer division by zero in client.dll at client Lua startup: seen at 480x270 and 320x240; it only survived with the HUD turned off). -textmode and lower graphics settings were measured: no real gain (and graphics settings would be saved into the user's own), so neither is offered.
Result: {instances: [{instance, pid, port, owner?, commands? [{cmd, ok, error?}], map? (or map: null + map_error)}], game_dir, found_by, preset, keep, fps_max, fps_max_nofocus, fps_note, launch_args?, lua_mount}. If they do not all answer within timeout_s: error timeout with silent_pids (started but never answered: close them with instances_close {pids}) and answered [{instance, pid}]. A client that crashed during startup or its map load is reported as client_crashed (startup: the whole call's error; map load: that client's map_error), with the minidump file name in details.dump (for a human) and exit_code: launch a replacement. With count > 1 the other clients of the call are not closed when one dies at startup: the error lists the ones still running in details.still_running [{pid, state: answering or still starting, instance?}] and a top-level warning; close them (instances_close) or use them. When the clients started but a map, a startup command or the lua_mount did not work, the call is isError with the whole result above plus error {code: launch_incomplete, message}. Example: {"count": 2, "map": "gm_construct", "owner": "fork-a"}, then pass each returned instance id as instance.
Starting a game makes every other running Garry's Mod release its GPU resources for 2-10 s, and a map load that ends in that window crashes that game (engine bug, Facepunch garrysmod-issues #7137). So the bridge serialises the launches and map loads that go through it, from any session: this call first waits while any game loads a map, and with map the maps load after a 15 s settle delay, 2 at a time across every session (a map_load of another session counts). "Any game" includes loads the bridge did not start (console map, changelevel, Lua RunConsoleCommand, a script talking to the game): every game reports when it is loading a map (instances_list loading), and waited_reason then starts with map_load_outside_bridge. A call that waited reports waited_s and waited_reason (and progress when your client sent a progress token). If the wait would exceed timeout_s it fails with error map_load_in_progress and starts nothing: retry later, or with a larger timeout_s. Not covered: a game started by hand (not by this call) and a load that begins while a launch is already creating its processes (only launches and map_load calls of the bridge wait, a load started by other means is never held back).
A client that is frozen (instances_list state unresponsive or hung: suspended, crash dialog, a load that never ends) keeps a new client from registering (engine FP7137 handshake), so a launch beside it ends with 0 of N clients answered: before starting anything this call refuses with peer_unhealthy {details.unhealthy: [{instance, pid, state}]}, naming the way out (instances_close {pids} for a client this session started, game_terminate {instance} for any), unless ignore_unhealthy: true; a timeout also names the stuck peers it saw meanwhile (details.unhealthy_peers).
When a program that is not gmod-mcp holds the base port (port_conflict, see status), the launch is refused up front with the fix (GMOD_MCP_PORT) and nothing is started: the clients would register on the next port, where this bridge cannot see them.
Right after a game starts, the other games can be unreachable for 15-18 s (instance_unreachable or timeouts): expected, wait and retry; it is not a dead game (client_crashed is the signal for a dead one).
Order: launch all the clients you need in ONE call (with map, they load 2 at a time after the settle delay), then work. Do not interleave launches with map loads, yours or another session's.
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "instances_launch"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| map | No | Map to load on each, e.g. gm_construct. Default: stay at the main menu. | |
| keep | No | Keep them running after this session ends (default false). | |
| count | No | How many clients (default 1). | |
| owner | No | Label recorded with these clients (e.g. your sub-agent's name or task), also on their command line and in instances_list; instances_close {owner} then closes only them, even from a later bridge session when keep is true. | |
| sound | No | Keep sound on (default true). false saves CPU when sound does not matter. | |
| preset | No | Default light. | |
| fps_max | No | Frame cap of these clients (fps_max): 0 = no cap, or 10 to 1000. Default: the preset's (light 20, normal 30). Given back to the user's value on a clean quit. | |
| commands | No | Console commands run on each client once it answers, before `map` loads, e.g. ["fps_max 300", "snd_mute_losefocus 0"]. quit, exit, connect and map changes are refused. Archived convars they change are given back on a clean quit. | |
| game_dir | No | Game folder (holding gmod_win64.exe or bin/win64/gmod.exe), if Steam does not know it. | |
| lua_mount | No | Absolute folder whose Lua these clients load before every addon's (e.g. your git worktree of the addon: its root or its lua/ folder). Applies from their first map load; see lua_mount. Each engine is asked what it really has BEFORE any map loads (instances[i].lua_mount.active); a missing mount is applied again, and a client that still has none gets no map (map_error lua_mount_not_active, isError, warning). Windows only. | |
| timeout_s | No | Max wait for all of them, map included (default 180). | |
| maxplayers | No | For map_load (default 1: singleplayer). | |
| launch_args | No | Extra engine command-line tokens, one per element, e.g. ["-noborder", "+cl_showfps", "1"]. Refused: what gmod-mcp sets itself (-multirun, -mcp*, -w, -h, window mode, -dxlevel, -condebug, -game), +connect, +map. Options: https://developer.valvesoftware.com/wiki/Command_line_options | |
| allow_shadow | No | With lua_mount: accept a folder that replaces files of the game's own base Lua (lua/includes/init.lua...). Refused by default (shadows_base_lua): such a client hangs in its load. | |
| fps_max_nofocus | No | Frame cap when the window has no focus (fps_max_nofocus): 0 = no cap, or 10 to 1000. Default: the same as fps_max. | |
| ignore_unhealthy | No | Start even when a running client is unresponsive or hung (error peer_unhealthy otherwise: a frozen client keeps a new one from registering, so the launch would time out). Default false. | |
| ignore_low_memory | No | Start even when the free memory does not cover the clients asked for (error low_memory otherwise). Default false: a machine out of memory crashes every game on it. |