Skip to main content
Glama

Launch test clients

instances_launch

Starts 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

NameRequiredDescriptionDefault
mapNoMap to load on each, e.g. gm_construct. Default: stay at the main menu.
keepNoKeep them running after this session ends (default false).
countNoHow many clients (default 1).
ownerNoLabel 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.
soundNoKeep sound on (default true). false saves CPU when sound does not matter.
presetNoDefault light.
fps_maxNoFrame 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.
commandsNoConsole 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_dirNoGame folder (holding gmod_win64.exe or bin/win64/gmod.exe), if Steam does not know it.
lua_mountNoAbsolute 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_sNoMax wait for all of them, map included (default 180).
maxplayersNoFor map_load (default 1: singleplayer).
launch_argsNoExtra 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_shadowNoWith 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_nofocusNoFrame cap when the window has no focus (fps_max_nofocus): 0 = no cap, or 10 to 1000. Default: the same as fps_max.
ignore_unhealthyNoStart 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_memoryNoStart 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.

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.3.7

TDQS

A4.9/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

The annotations only declare readOnlyHint=false, destructiveHint=false and openWorldHint=false; the description adds substantial context beyond them: job-object lifetime, memory/commit checks that refuse with low_memory and start nothing, peer_unhealthy and port_conflict refusals before anything starts, serialized map loads with a 15 s settle delay across sessions, crash reporting with minidumps, and the fact that shared cfg/data/cookies mean tests can alter the user's own game. The disclosed engine-bug risk (a launch forces other games to release GPU resources and a map load in that window can crash them) is also material behavioral context not covered by the annotations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The purpose is front-loaded and major sections are labeled (Presets, Pass-through options, Result, Order), which helps navigation. However, it is a dense wall of text with real redundancy: the keep/close-on-session-end behavior is explained twice in the opening paragraph, and "-nosound is the same as sound: false" repeats the schema. The length is largely justified by 17 parameters and many refusal paths, but trimming the repeated lifetime explanation would improve it.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a 17-parameter launcher with no output schema, the description covers the return shape (instances, game_dir, found_by, preset, keep, fps, lua_mount), error codes and partial-failure semantics (launch_incomplete, timeout with silent_pids, client_crashed with still_running), resource costs, and concurrency interactions with other sessions. Nothing an agent needs to call it safely and interpret results is missing.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so the baseline would be 3, but the description adds genuine meaning beyond the schema: preset fps values (light 20, normal 30), the fps_max/fps_max_nofocus fallback relationship, which commands and launch_args are refused and why, owner routing across bridge sessions including keep:true clients of earlier sessions, lua_mount verification before any map loads, and the sound:false effect on reported SoundDuration. It also ties parameters to failure modes (ignore_low_memory, ignore_unhealthy) rather than merely restating field descriptions.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Opens with a specific verb and resource: "Starts 1 to 8 extra Garry's Mod clients for tests", plus scope ("works while no game runs"). It also differentiates from siblings by naming the correct alternatives ("close them earlier with instances_close (not game_quit...)", "use `map`", "never {all: true}"), so an agent can pick this tool over instances_close or map_load without opening another schema.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Gives explicit when-to-use guidance: preset selection (light for most tests, normal for rendering/frame-time checks), sound on/off conditions, keep semantics for outliving a session, and owner labeling for sub-agents. It also states ordering rules ("launch all the clients you need in ONE call... Do not interleave launches with map loads") and names the correct closing tool, leaving little to inference.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.