MCP tools (Melange 0.18)
An MCP tool is something a model may list and call: Melange.exe’s MCP server, an external Claude Code and the in-game AI all go through one registry in the game. Client mods declare their tools in a manifest and implement them in Lua; core modules add theirs from C++.
Everything here is local configuration and presentation: a tool runs on the main thread of the machine that owns the
game, in the client Lua sandbox (no wum.sim, no wum.unsafe).
Declaring tools
Section titled “Declaring tools”spice.json:
"mcp": { "tools": "mcp/tools.json", "instructions": "mcp/instructions.md" }instructions is optional: Markdown of at most 4 KB, served to the model with the tools of this mod.
mcp/tools.json:
{ "format": "melange-mcp-tools-1", "tools": [ { "name": "get_config", "title": "Read the lobby rules", "description": "Returns the rules the lobby is using, or the host's draft.", "inputSchema": { "type": "object", "additionalProperties": false, "properties": { "which": { "enum": ["applied", "draft"] } } }, "mutating": false, "phases": ["menu", "lobby", "match"] } ] }| Field | Rule |
|---|---|
name |
[a-z][a-z0-9_]{0,40}, unique in the file. The MCP name is <modid>_<name> with - and . in the id turned into _ (landsraad_get_config), at most 64 characters, and unique across mods. |
title |
Optional, at most 80 bytes (default: the name). |
description |
Required, at most 2 KB. Say what the tool does and what it returns. |
inputSchema |
Required, an object schema ("type": "object"), at most 32 KB. For no arguments use {"type": "object", "additionalProperties": false}. |
mutating |
Default false. A mutating tool is refused over Oasis when [Oasis] ReadOnly=1. |
destructive, idempotent |
Optional hints (destructive needs mutating). |
phases |
Any of menu, lobby, match (default all). Outside them the tool is listed as unavailable (“not in a lobby”). |
At most 64 tools per file. Unknown keys are errors, so the whole AI surface of a plugin can be reviewed in one file.
A bad file (JSON error, a rule above, a missing file, a name taken by another mod or by a core tool) is shown on the
Mods page as “AI tools off: …”. The mod still loads, its tools are not listed, and wum.web.tool does nothing for it.
Schema subset
Section titled “Schema subset”type (a name or a list of names), properties, required, enum, const, minimum, maximum, minLength,
maxLength, minItems, maxItems, items, additionalProperties (false or a schema), oneOf, and the annotation
keywords description, title, default, examples, $comment, $schema. Anything else ($ref, anyOf,
pattern, …) is an error that names the keyword and its path.
Binding handlers
Section titled “Binding handlers”wum.web.tool("get_config", function(args, ctx) return { which = args.which or "applied", rules = wum.rules.lobby() }end)argsis the arguments table. The core has already checked it againstinputSchema(the same messages as the erg-mcp tools, including “did you mean” for a misspelled key), so the handler only sees valid arguments.ctx = {client = "mcp" | "ai", caller = "external" | "lobby-prompt", job = <id or nil>}.- Return a table (sent as
structuredContentand as compact JSON text; encoded withwum.json, so usewum.json.array{}for an empty array), a string (text), ornil, message/error(message)(anisErrorresult the model sees; not a fault). - A name the manifest does not declare raises an error that lists the declared names. A name can be bound once.
- Handlers run on the main thread under the instruction budget. A runaway handler is stopped and the call answers
isError. - Handlers are revoked on hot reload and disable and rebound by the new version.
What a client sees
Section titled “What a client sees”Over Oasis (see oasis.md): mcp.tools, mcp.call and the mcp channel. A tool is listed with
available: false and a why when
- its
phasesexclude the current phase, - its mod is not in
[AI] ToolMods(defaultlandsraad; ids separated by commas,*for every mod), - it is a core test tool and
[Testing] Enabled=0, - the mod has not bound a handler for it.
Calling an unavailable tool is an isError result with the same reason.
Core tools (C++)
Section titled “Core tools (C++)”src/sdk/melange/mcp.h:
int melange::mcp::AddTool(name, title, description, inputSchemaJson, fn, user, flags); // any thread; 0 on refusalvoid melange::mcp::RemoveTool(handle);void melange::mcp::CallAsync(name, argsJson, done, {caller, job}); // runs on the main thread, within the frame budgetA core tool name starts with test_ or melange_. Flags: kToolReadOnly, kToolMutating, kToolDestructive,
kToolIdempotent, kToolTesting (listed and callable only with [Testing] Enabled=1). fn(argsJson, ToolResult&, user) gets arguments already checked against the schema. CallAsync is for the in-game AI’s API backend: it queues the
call, the main thread runs it on the next frame, and done is called there.
Melange.exe –mcp (for Claude Code and other MCP clients)
Section titled “Melange.exe –mcp (for Claude Code and other MCP clients)”Melange.exe --mcp is an MCP server on stdio. It finds the running game’s Oasis server, forwards the tool list and the
tool calls, and nothing else. Register it once; it does not need the game to be running at that moment.
claude mcp add --scope user melange -- "C:\Program Files (x86)\Steam\steamapps\common\WormsXHD\Melange.exe" --mcp(use the folder your game is in). The command line has no token in it: the server reads the launch URL from the game each time it connects, so a game restart (new token) is picked up by the next call.
Melange.exe --mcp [--url <launch url>] [--url-file <path>] [--game <dir>] [--list-tools]Finding the game, first that works:
--url <launch url>;- the
MELANGE_OASIS_URLenvironment variable; --url-file <path>;<game folder>\Melange\oasis_url.txt, which each game writes beside its own files:--game <dir>, else the folderMelange.exeis in;Documents\Melange\oasis_url.txt, which the last game to start wrote (skipped when--gameis given, because it may belong to another game).
The first three are explicit: when one is given, nothing else is tried. With several games running, give each server its
own --game, and each reaches its own game.
Behaviour
- The connection is made on the first
tools/listortools/call(and tried briefly atinitializeto pick up the mods’ instructions), and again on every later call if the game went away. When the game’s tool list changes (a mod loaded, a phase change) and after a reconnect, the server sendsnotifications/tools/list_changed. - With no game running,
tools/listis one tool,melange_status, which says to start the game. tools/listshows the available tools and the ones that fail only by phase (“not in a lobby”; their description says so). It never shows a tool of a mod outside[AI] ToolMods, a disabledtest_*tool, or anything that is not a registered tool: the server’s only game verbs aremcp.tools,mcp.calland themcpsubscription, solua.eval,ini.*,mods.*,input.*andrender.*are out of reach, and every other MCP method (resources, prompts, …) is “method not found”.- Oasis errors become
isErrorresults with the reason:-32001not available here,-32003Oasis is read-only,-32000the game’s own policy text. Image results ({type: "image"}) are forwarded unchanged. notifications/cancelleddrops the pending call’s answer (the game still finishes the tool). A call that gets no answer for 120 s ends with an error result.--list-toolsprints whattools/listwould return (JSON) and exits, for checking the setup by hand.--job <id>is what the in-game prompt’s own Claude Code runs it with (wum.ai): everymcp.callcarries that id, and while that job runs the tool handlers seectx.caller == "lobby-prompt"andctx.job. Any other client’s calls are"external".- It runs before the window, WebView2, the updater and the single-instance check, so it never disturbs a launcher that
is open. Diagnostics go to stderr and
%LOCALAPPDATA%\Melange\mcp.log(the launch token is masked); stdout carries only the protocol.
Core test tools ([Testing] Enabled=1)
Section titled “Core test tools ([Testing] Enabled=1)”Six core tools let any MCP client (Melange.exe’s server, an external Claude Code, a test harness) play and check a
match on this machine. They exist only while [Testing] Enabled=1 in Melange.ini (default 0, also in public
builds): the game adds them when the key is turned on and removes them when it goes back to 0. They are
src/oasis/rpc/test_tools.cpp; level.test.* and input.drive are separate and unchanged.
| Tool | Arguments | What it does |
|---|---|---|
test_state |
none | Read-only. scene, phase (menu, lobby, match), net (the net session’s phase), members (lobby members), and in a match turn, turnPhase, team, worm, localTurn, canAct (and whyNot), turnMsLeft, roundMsLeft, suddenDeath, water, teams, worms (slot, team, name, hp, alive, pos, weapon), the active worm’s inventory ({id, name, ammo}, -1 unlimited), digest, turnDigests (the digest at each of the last 32 turn starts) and fire (the last test_fire or test_skip_turn: stage done or failed with why). |
test_select_weapon |
weapon: an engine id (1-29, 34-43) or name (kWeaponBazooka, bazooka, kUtilitySkipGo) |
The active worm takes the weapon, as a pick in the weapon panel does. Refused when the worm has none of it (or it is delayed). |
test_fire |
weapon?, aimUpMs?, aimDownMs? (0-5000), fireMs? (30-5000, default 300) |
Takes the weapon if one is given, then holds aim up, aim down and fire (the power of a charged weapon) through the game’s own key inputs. Answers at once; follow test_state’s fire. |
test_skip_turn |
none | Ends the turn being played (see below). |
test_shot |
name (1-48 of A-Z a-z 0-9 _ - .), width? (160-1280, default 960) |
The game’s own view, with the HUD, as a PNG image (and the file Documents\Melange\shots\test_<name>.png). Made smaller when it would not fit one Oasis message. |
test_quit_now |
reason? |
Flushes Melange’s logs and mod storage, then terminates the process half a second after answering. Nothing else is written: no Steam save, no match result, no settings. |
test_select_weapon, test_fire and test_skip_turn act only on a human team whose turn is in its play phase,
and only on the machine that plays it: canAct says whether they would act now, whyNot why not.
The digest is FNV-1a 64 (16 hex digits) over every worm’s slot, team, health and alive flag and every team’s ammo of
the weapon panel’s items. Positions are left out, so two machines read at different moments of the same turn agree.
Compare turnDigests of the same turn between the peers of a network match.
Offline and online
Section titled “Offline and online”| Tool | Offline match | Network match |
|---|---|---|
test_select_weapon |
Weapon.DelayedPanelChanged <id> sent from the next sim tick (the match VM’s own Lua, as level.test.selectWeapon does) |
Only on the machine whose turn it is: Weapon.DelayedPanelChanged <id> through the replicated int sender, stamped for the next tick, exactly as the weapon panel sends it |
test_fire |
The Controls drive’s Input.AimUp, Input.AimDown, Input.Fire holds |
The same holds, only on the machine whose turn it is, re-checked before every post |
test_skip_turn |
Timer.TurnTimedOut from the next sim tick (the turn timer running out) |
Only on the machine whose turn it is: the worm takes Skip Go and fires it; without Skip Go it fires the Prod (no damage, it only pushes a worm standing right next to it); with neither it is refused |
test_shot |
The back buffer | The back buffer; never a camera override |
Why the test tools are net-safe
Section titled “Why the test tools are net-safe”A network match is lockstep: every machine runs the same simulation from the same replicated inputs, and anything one machine changes in its simulation alone is a desync (Wormsign’s check, the turn-end validation and the time-sync check then end the match). So in a network match the tools:
- Never run sim Lua. The offline paths (the sim-tick queue and
Timer.TurnTimedOut) are refused online, and a message still queued when the session turns out to be online is dropped. - Act only on the machine that owns the active turn, by the engine’s own answer (the current net player’s “local” flag, the test behind its replication gate), checked when the tool is called and again before every post, and never for a CPU team. A replicated send from a machine that does not own the turn is applied on that machine alone, which is exactly a desync, so every other machine refuses and sends nothing.
- Send only what a player sends: the weapon panel’s own selection message, and the key inputs a bound key posts. The engine replicates both to the peers, and Wormsign records them as live input. With a menu open (the pause menu or a popup) selection is refused, so the panel-under-menu case never arises.
- Leave timers, the camera and the turn order alone. The online skip is Skip Go fired by its owner, never the
timer’s time-out;
test_shotnever sets a camera override (the post-explosion camera hold delays one machine’s turn end, see multiplayer-fixes.md). - Are checked, not only argued:
turnDigestslets a harness compare the peers turn by turn. - End by process exit:
test_quit_nowsends no quit message, so the other machines see the player drop, and no save or result is written.