Deploy authoritative server logic
deploy_room_logicDeploy server-side game logic (JS source) for a room so it runs AUTHORITATIVELY: clients send inputs and the server computes state on a tick (anti-cheat by construction). Define handlers as functions over a global state (RoomStateView shape): onJoin(id), onLeave(id), onInput(id, input), onEvent(id, type, data), onTick(dt); emit(type,data)/emitTo(id,type,data) send events to clients. For TRUSTWORTHY persistence the client can't fake, call saveData(id, patch)/loadData(id) (the player's server-only save) and submitScore(id, board, score, mode), the server decides the values (the client passes its identity via MP.join({…, player})). Each deploy returns a version (roll back with rollback_room_logic; read runtime errors with get_room_logs). Limits: code <= 256KB, tickRate 1-60. The code runs in a locked-down isolate: handlers must be SYNCHRONOUS (no async/await/promises/timers), there is no network or require, console.* is a no-op, and state must stay JSON-serializable (no Map/Set/class instances). Call get_sdk_reference for the full contract.
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": {
"roomName": "<roomName>"
},
"name": "deploy_room_logic"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | No | JS source defining onJoin/onLeave/onInput/onEvent/onTick over a global `state`. Or, for a long file, pass uploadId instead. | |
| game | No | Which game to act on: its publishable key (pk_…) or its exact name. Defaults to the x-mp-game header, then your primary game. | |
| roomName | Yes | The room name to make authoritative. | |
| tickRate | No | Server ticks per second (default 20). | |
| uploadId | No | Instead of code: the uploadId of a .js file you created with create_upload (for this game) and PUT with curl. For logic too long to send inline. |