tmodloader-mcp
v0.8.0Drive a running tModLoader (Terraria) instance from an agent: launch, query, screenshot, read state.
These tools were reported by the server itself during our smoke test (tools/list), not copied from the README.
build_mod Build the mod
Compile the configured mod source into a .tmod. Args: timeout: Seconds to wait for the compile. A large mod on a slow machine can outlast the default, and a build that runs out of time says so rather than reporting a compile failure with no errors in it. tModLoader REFUSES to build while the game is open, and says so with an error that otherwise reads like a compile failure. That case is reported as itself, with the fix, rather than as a broken build — which is the difference between closing the game and hunting a syntax error that is not there. Success is read from th…
| Parameter | Type | Description |
|---|---|---|
timeout | number |
launch Launch a game session
Start tModLoader and wait until it can actually answer. Args: mode: "server_client" — a server plus one joined client. It is the only mode there is, and the only way to observe what a CLIENT sees, which is where most sync bugs live. The other two are refused because the engine cannot satisfy them: "singleplayer" has no headless entry point, and "server" alone never ticks, so the mod never polls and never answers. port: Server port. Change it only if something else holds the default. player: Character name for the client. Must already exist…
| Parameter | Type | Description |
|---|---|---|
mode | string | |
player | string | |
port | integer | |
timeout | number | |
world |
join Join a second client to the running session
Bring another character into the session that is already running. Args: player: Character name. Must already exist — `-player` does not create one — and must not be one this session already has, in any casing. timeout: Seconds to wait for that client to report a live, world-ready heartbeat of its own. The protocol has supported several clients since answers became per-player; the LIFECYCLE supported one, so the arrangement that work exists to make safe could only be reached by spawning a game by hand. This is that, with the waiting done properly. It waits for THI…
| Parameter | Type | Description |
|---|---|---|
player * | string | |
timeout | number |
trigger Send a dev trigger to the game
Ask the running game to do something, and return what it said. Args: command: One of the dev commands THIS mod serves — call `commands` to see them, since they are the running mod's rather than a list kept here. A word it does not serve is refused before anything is written to disk: a game that does not recognise one does nothing, and from outside that is indistinguishable from a hang. target: Address the request to one player by name. Every request is already addressed to this session's own player by default, so pass this only to ask…
| Parameter | Type | Description |
|---|---|---|
command * | string | |
argument | ||
server | boolean | |
target | ||
timeout | number |
commands What the running mod serves
What this side's mod says it serves, read from the mod itself. The list is published by the responder when it loads, not assembled here. This harness used to carry its own copy of one mod's twelve commands and its own belief about which read an argument — facts that belonged to running C# and drifted the moment either side changed alone. `responder` IS THE USEFUL FIELD when something is wrong. False means no list was published: the mod is not loaded, or is a build with the dev bridge compiled out. That is a different answer from a game still starting, and it used to arrive as a readiness t…
| Parameter | Type | Description |
|---|---|---|
server | boolean |
diag Read the game's state
Ask one side of the session what it currently sees, parsed. Args: server: Read the dedicated server's view instead of the client's. target: Address a specific client by name. timeout: Seconds for the WHOLE call — the reply and then the dump it promises, out of one budget rather than one each. A large world takes longer. Returns counters as integers and the mod's absence markers as null, so a reading of 0 — a real measurement — cannot be confused with "no data". Asking both sides at the same moment is the only way to answer "the client reports no NPC", which…
| Parameter | Type | Description |
|---|---|---|
server | boolean | |
target | ||
timeout | number |
wait_until Wait until the game reaches a state
Poll `diag` until one of its fields satisfies a comparison. Args: field: A TOP-LEVEL diag field, exactly as `diag` reports it - `vats`, `items`, `world-ready`. Not a path into one: `diag` splits `key: value` and stops, so `npcs` is the whole string `active=4 mutated=0` and there is no `npcs.active`. op: One of `==`, `!=`, `<`, `<=`, `>`, `>=`, `contains`, `changed`. value: What to compare against, as text - it is converted to whatever type the field actually reads as. Omitted for `changed`, which baselines on its first reading. server: W…
| Parameter | Type | Description |
|---|---|---|
field * | string | |
op * | string | |
poll | number | |
server | boolean | |
target | ||
timeout | number | |
value |
shot Photograph part of the frame
Capture a region of the game's own back buffer and return the PNG path. Args: region: topleft, topright, bottomleft, bottomright, or full. REQUIRED and deliberately without a default — the frame holds the player's character name, world name and any chat, so a request says which corner it wants. target: Address a specific client. timeout: Seconds for the WHOLE call — the reply and then the PNG, out of one budget rather than one each. This reads what the game rendered, not the screen, so no other window can appear in it — by construction rather…
| Parameter | Type | Description |
|---|---|---|
region * | string | |
target | ||
timeout | number |
captures List the captures on disk
Every capture in the save directory, newest last. Names, not paths — a path handed out is a path that can come back changed, and `read_capture` deliberately accepts only a name.
read_capture Read a capture back as an image
Return one capture's PNG as image content. `shot` answers with a filesystem path, which is worth nothing to an agent that is not running on this machine. This is how the picture itself gets back, and it is a SEPARATE call on purpose: a full-frame PNG is tens of kilobytes before base64, so a caller that only wanted to know the capture succeeded should not be made to pay for the pixels. Args: name: A capture filename from `captures`, e.g. `<mod>-shot-<token>-001-topleft.png`. A NAME, never a path — see `captures.read` for why the containment is structural.
| Parameter | Type | Description |
|---|---|---|
name * | string |
prune_captures Delete old captures
Delete all but the newest `keep` captures, and say which went. Captures accumulated forever. `shot` writes one per call and nothing ever removed them, so an agent photographing in a loop grew the SAVE DIRECTORY without bound — the folder holding the worlds and characters, which is not a cache and not somewhere to leave litter. Args: keep: How many of the newest captures to keep. REQUIRED and deliberately without a default, the same way `shot` requires a region: this deletes files, and a destructive tool that runs with no arguments is one that gets called by acci…
| Parameter | Type | Description |
|---|---|---|
keep * | integer |
status Is a session running?
Whether a session is running, and what it is. The only read-only way to ask. Without it an agent that lost track had to provoke an error to find out — `launch` fails when one exists, `diag` fails when one does not — so the cheapest question on the surface was the one that had to be asked by breaking something. Reports what this server BELIEVES it started. It does not re-query the process table, so it cannot tell you a game was closed from outside; `stop` is what verifies against reality.
logs Read a side's log
Tail one of tModLoader's logs, optionally filtered. Args: name: Which log — see `log_files` for what this install actually has. `client.log` and `server.log` are the game; `Launch.log` and the `environment-*.log` pair are written by the launcher, which is where a run that died BEFORE the game started says why. previous: Read the run BEFORE this one. tModLoader zips the previous run's logs into `Old/` when a new run starts, so after a failed launch and a retry the failure is in an archive and the live log belongs to the retry. conta…
| Parameter | Type | Description |
|---|---|---|
contains | ||
lines | integer | |
name | string | |
previous | boolean |
log_files List the logs this install has
Which logs exist right now, and how many earlier runs are archived. Read off disk rather than listed as a constant: which logs exist depends on what was run, and a server-only session writes no `client.log` at all.
inventory What this install has
The worlds, characters and mods on this machine. `launch` states two preconditions and could check neither. `player` must already exist — it does not create one, and a duplicate is kicked — and `world` wants a WINDOWS path the caller had to know in advance. Both are facts about directories sitting right there, and until now the only way to learn either was to launch and read the failure: a kick for the wrong character, and a readiness timeout blaming the heartbeat for the wrong world. Each world's `path_win` is the exact string `launch(world=...)` wants, and each player's `name` is the ex…
save_snapshot Copy the save aside
Copy this world and its characters aside, so a run can be undone. Args: label: The snapshot's name: letters, digits, dot, dash, underscore. world: WINDOWS path to the `.wld` to copy, as passed to `launch`. Defaults to TMODLOADER_WORLD_WIN. Refused without it when the last session from this server loaded a different world, rather than copying a world the run never touched. WHAT THIS IS FOR. The mutating verbs write to a real install and none of that FAILS — it accumulates. Enemy NPCs do not survive a reload, so `spawn` looks harmless, but `give` writes the ch…
| Parameter | Type | Description |
|---|---|---|
label * | string | |
world |
save_restore Put a saved copy back
Overwrite the world and characters with a snapshot. Args: label: The snapshot to put back. world: WINDOWS path to the `.wld`. Defaults to the world the snapshot holds, and must be that world when given. Refused without it when the last session from this server loaded a different world: the restore would leave the world that run changed as it is. This DESTROYS what is on disk now, so it saves that first: the state being overwritten is copied to `auto-before-restore` and returned as `undo`, which `save_restore` accepts like any other label. A restore aimed at th…
| Parameter | Type | Description |
|---|---|---|
label * | string | |
world |
save_snapshots List the saved copies
Every snapshot on this machine, newest first, with its age in seconds. A snapshot whose manifest cannot be read is omitted rather than listed as empty, because `save_restore` refuses it for the same reason: putting back nothing and reporting success is the worst available outcome. `restore_state` says what the last restore left: "mixed" means it failed partway and the save on disk is half-restored.
heartbeat Read the mod's heartbeat
Why the game is not answering, for both sides at once. `launch` already reads this file to decide readiness and keeps one bit of it. When a launch SUCCEEDS that is all anyone needs. When it fails, the discarded detail is the entire answer, and what comes back instead is `no live heartbeat within 300s` — which names the symptom and none of the four causes: - **absent** — nothing ever wrote one. The mod is not loaded, is not enabled in this install, or was built without the dev bridge. For clients this is an EMPTY `clients` list, not an entry saying so. - **stale** — a game ran and i…
log_since Read what a log has gained
Only what a log has gained since you last looked. Args: name: A log filename from `log_files`. offset: The `next_offset` from your previous call, or 0 to start at the beginning. BYTES, not lines — a line count is not a resume point, because the number of lines you have read is not where the file continues. contains: Case-insensitive filter, applied to the new lines only. fingerprint: The previous call's `fingerprint`, or omit on the first. It is how a rotation is detected when the NEW log has already outgrown your offset — without it…
| Parameter | Type | Description |
|---|---|---|
name * | string | |
contains | ||
fingerprint | ||
offset | integer |
api_search Search the tModLoader API surface
Find a type, field, property or method in the INSTALLED tModLoader. Args: query: Part of a name, or a type. `cloudAlpha`, `rain`, `QuickSpawnItem`, `IEntitySource`. Case-insensitive. kind: Narrow to one of type, field, property, method. limit: How many matches to return, best first. ANSWERS THE QUESTION YOU HAVE BEFORE YOU WRITE ANYTHING. A compile tells you exactly whether the call you already wrote is right; it cannot tell you what is there. `Main.maxRaining` is only findable if you already suspect the name. READ FROM THE ASSEMBLY'S OWN METADATA, so it cannot drift fro…
| Parameter | Type | Description |
|---|---|---|
query * | string | |
kind | ||
limit | integer |
log_watch Wait for a line to appear in a log
Block until a log line matches, instead of polling `log_since` by hand. Args: name: A log filename from `log_files`. contains: Case-insensitive text to wait for. REQUIRED — without one this matches the first line written and is `log_since` wearing a longer name. offset: Where to start reading. 0 includes the log's HISTORY, which is usually what you want ("did the mod load" is a question about a line that is already there). Pass a previous call's `next_offset` to watch only what comes after it. fingerprint: The `fingerprint` from an ear…
| Parameter | Type | Description |
|---|---|---|
contains * | string | |
name * | string | |
fingerprint | ||
offset | integer | |
poll | number | |
timeout | number |
restart Rebuild and relaunch the session
Stop, rebuild, and start again with the session's own settings. Args: build: Compile the mod between stopping and starting. On by default, because picking up a code change is the reason this loop exists. timeout: Seconds to wait for readiness on the relaunch. build_timeout: Seconds to allow the compile. THE ORDER IS THE POINT. tModLoader REFUSES to build while the game is open and reports it with an error that reads like a compile failure, so stop-then-build-then-launch is not a preference — building first sends you hunting a syntax error that is not there. Three separa…
| Parameter | Type | Description |
|---|---|---|
build | boolean | |
build_timeout | number | |
timeout | number |
stop Stop the game session
Kill only the processes this session started, and confirm they are gone. Args: settle: Seconds a killed process may take to leave the process table before it counts as a survivor. `/F` returns before Windows has caught up, so verifying too eagerly reports a successful teardown as a refused one — raise this on a loaded machine rather than lower it. Surgical on purpose: a developer usually has their own game open, and a teardown that killed every tModLoader it could find would take it with them. `killed_pids` are pids VERIFIED to have left the process table, not…
| Parameter | Type | Description |
|---|---|---|
settle | number |