# Game bridge and agent RPC (`jmvcc client`)
Deploy and debug in the live game through the JMVCC Bridge mod (deploy, logs, vars, tests, menus, keys, items) and call / inspect running code with `rpc function` / `rpc game var`. Open before the first deploy or in-game check.

## Launchers, MCP server, editor, bug reports
Where things are: the compiler lives in `<JMVCC>` (your jmvcc folder), docs in `<JMVCC>\docs` (`llms.txt`, `topics/`, `recipes*.jc`; all signatures — https://jmvcc.dev/signatures.txt). Launchers: `<JMVCC>\jmvcc.cmd` for cmd/PowerShell, `<JMVCC>/jmvcc` (POSIX script) for Git Bash.
For an event, `jmvcc sig` takes the bare name (`player_kill_player`). The form `event<player_kill_player>` works
only quoted (`'event<player_kill_player>'`): `<` `>` are redirections in a shell, and `jmvcc.cmd` re-parses
them through cmd.exe even when quoted — from Git Bash use `<JMVCC>/jmvcc` or the bare name.
The old command name `jmcc` (`<JMVCC>/jmcc`, `<JMVCC>\jmcc.cmd`) still works as an alias of `jmvcc`.
MCP: `jmvcc mcp` is a stdio MCP server with the same loop as tools (check, compile, trace, sig, search, docs,
decompile; with the mod: status, logs, vars, deploy, stop, send, act, screen, shot, rpc). Connect it with
`jmvcc mcp install --yes` (every agent program found: Claude Code, Cursor, Copilot, Codex, Gemini, Zed... — https://jmvcc.dev/guide/mcp)
or `claude mcp add jmvcc -- node <JMVCC>/dist/index.js mcp`. VS Code: extension (https://jmvcc.dev/guide/vscode) on `jmvcc lsp`
(errors while typing, hover, completion, F12, Ctrl+. fixes). `deploy` / `stop` need `confirm: true` — set it only after
the user agreed; `send` can change the world too.
Found a compiler bug or a missing feature: `jmvcc report [file.jc] -m "what happened"` (MCP tool `report`) builds a
markdown report (versions, last failed command, diagnostics; code only with --with-code) — give the text to the user (for the author).

## Client commands (mod JMVCC Bridge, https://jmvcc.dev/src/bridge-api.md)
When the player runs Minecraft with the JMVCC Bridge mod, you deploy and read server errors yourself:
```
jmvcc client status               # is the mod up, player on the server, remote control on, current session
jmvcc client deploy main.jc       # compile → upload → /build, /dev, /module load-url, /play → wait 5 s →
                                 # print errors, log(...) and module messages (player::message) of the new session; exit 1 on errors
jmvcc client deploy main.jc --no-play --wait 10
                                 # deploy backs the world up first and refuses (exit 4) to erase lines edited by hand or
                                 # not made by this jmvcc project: ask the user, then `client pull --from <backup>` or --force;
                                 # "⚠ защита выключена" = the world could not be read (rank below Meteor+): tell the user
                                 # (--strict refuses instead); backups / restore <id>
jmvcc client test t.json --json   # in-game test: steps say/command/click/key/wait + expectations log/chat/var/item/gui → report
jmvcc client logs                 # current session without chat and server ads; --errors, --types log,system,chat, --all, --json
jmvcc client logs --since 42      # only new events (the footer prints the last seq)
jmvcc client send "/play"         # server command or chat message (never "!..." — global chat is blocked)
jmvcc client control begin | end  # a series of key/click/command steps under ONE warning title for the player
                                 # (auto-ends after 60 s without requests); reads (logs, vars, status) need none
jmvcc client vars game [substr]   # game/save variables with values now (all pages of /env var list); --json
jmvcc client send "/env var clear game <exact_name>"   # reset one variable; without a name clears the whole
                                 # scope — never "clear save" without a name unless the user asked
jmvcc client screen | click <slot> [--right] [--shift] | use | close | shot   # menus and screenshots
jmvcc client button Возродиться     # press a button on a non-container screen (death, confirm); list: jmvcc client screen
jmvcc client items [--all] [--json] # items in the player's backpack (slots 9-35) and open menu -> ready lines
                                 # inline var ITEM_X = item_raw("H4sI...")  // player_head "Name"; --all adds hotbar/armor
                                 # --slots 32,40-44: only these; heads also print their skin value (for set_player_head)
jmvcc client render [--heads] [--size 192] [--slots 0-44]   # the open menu (or inventory) drawn large by the game
                                 # itself -> PNG path + list: each item 32..256 px with its slot number and name
                                 # (heads = 3D with skin). Read the PNG to choose; the menu stays open
jmvcc client key forward sprint --ms 2000   # hold keys: forward back left right jump sneak sprint
                                 # swap_offhand drop attack use inventory hotbar1..hotbar9 (default 100 ms)
jmvcc client call give 5          # call an `rpc function` in the RUNNING code (deployed with --rpc), print its result
jmvcc client get coins | set coins 100 | rpc-list   # read / write an `rpc game var`, list what is exposed
```
A runtime error line looks like `#17 19:01:52 error  <action>: <reason> @ x y z` — the action and reason
come from the server; x y z is the code block. Fix the code, deploy again, read logs again.
Exit codes: 1 error/failed deploy, 2 the mod is not running (ask the player to start the game with the mod),
3 the player turned remote control off: write it to the user and ask to run `/j remote on` in chat.
Git Bash only: it rewrites a leading `/` into a Windows path — write `"//build"` there or set `MSYS_NO_PATHCONV=1`.

`log(...)` — debug print for you: `log("x = $x, top =", top)` → `player::message<all_players>("\u2063x = …")`.
Args are joined by spaces, `$x`/`%var%` work as in player::message; a statement only (no value).
The invisible U+2063 marker makes the mod log it as type `log`. Your own `function log(...)` wins over it.
Every player sees log lines in chat: remove them when the code works.
## Heads from /hdb
With the mod do it yourself, do not ask the player (decor, custom items). Inside a
`client control begin` … `end`: `client send "/hdb search bag"` — search by the main object you see (bag, barrel,
chest, pot, book, crate), not by material or colour (`gold` returns hundreds of golden letters); narrow with a second
word (`/hdb search bag of coins`). `client render --heads` → read the PNG (16 px menu icons hide what a head is),
next page = `client click` on the page item (`client screen` lists them), pick, then `client items --slots <n>`
gives the item_raw line and the skin value; `client close` at the end. The menu does not need the head in the
backpack. Use heads where a block cannot show the thing (money bags, food, potions) — a few, not everywhere.
## Agent RPC (`rpc function`, `rpc game var`)
Call functions and read / write variables of the code that is RUNNING in the world, without a redeploy (the
state stays): a REPL / debugger for you. Mark what you may touch:
```js
rpc game var coins = 0               // also rpc save var x; only these are reachable by get / set
rpc function give(n, extra = 1) {    // an ordinary function: the code calls it too (at most 12 parameters)
  coins += n + extra
  return coins
}
```
```
jmvcc client deploy main.jc --rpc    # dev build: WITHOUT --rpc the word rpc changes nothing (same JSON, no receiver)
jmvcc client rpc-list                # function give(n, extra?) → значение / game var coins
jmvcc client call give 5             # → 6 (prints the return value as JSON; null for a function without return)
jmvcc client call greet Steve '[1,2]' '"5"'   # each arg: JSON if it parses, else text ("5" in quotes = text)
jmvcc client call greet 5 --text     # all args as text, no JSON parsing
jmvcc client call echo --file args.json   # args = a JSON list from a file: no quotes on the command line
jmvcc client call give -- -5         # negative numbers after --
jmvcc client get coins               # → 6
jmvcc client set coins 100           # → 100 (value: JSON, else text; --text / --file value.json too)
```
- Windows PowerShell 5.1 DROPS `"` inside arguments of native programs: `'[1,"a"]'` arrives as `[1,a]`, `'"5"'`
  as the number 5. Arguments that start with `[` / `{` but are not JSON are an error (not silently text); for
  quoted JSON in PowerShell write `\"` (`'[1,\"a\"]'`, `'\"5\"'`), or use `--file`, or run from bash.
- Release builds (`compile`, `client deploy` without `--rpc`) never carry RPC: deploy with `--rpc` only while
  you debug. With `--rpc` and at least one `rpc` item the compiler adds the receiver; `compile/check/trace --rpc` too.
- Only the world OWNER is served (`"%uuid%" == value::owner_uuid` and `has_privilege("OWNER")`); a packet from
  anyone else is silently dropped. Only names marked `rpc` are reachable (a compiled if-chain, no call by text).
- Every request carries this machine's key (`~/.jmvcc/rpc-key`, made on the first `--rpc` build and compiled
  into the receiver): the owner clicking someone else's text with a custom `click_event` sends the same packet,
  but without the key it calls nothing (`error bad key: redeploy with --rpc from this machine` — also what you
  get after the key file changed). Deploy and call from the same machine.
- `--max-line` / `JMVCC_MAX_LINE` never split the generated dispatcher (line vars and early returns cannot be cut).
- The function runs in the owner's thread (target = the owner: `player::message` goes to them), args by position
  (fewer is fine when the rest have defaults). Edition 1: it shares the caller's `var`s like any call. `code::wait` inside
  is allowed: the reply comes when it returns (verified: 3 s wait → reply after 3 s; `--timeout <s>`, default 5).
  No reply (exit 1, "нет ответа") = the world was deployed without `--rpc`, no such rpc, you are not the owner,
  a server error stopped the line
  (`jmvcc client logs --errors`), or the function ended the thread (`code::end_thread`, `break` outside a loop).
- Errors (exit 1): `unknown function f`, `give takes 1..2 arguments (n, extra), got 3`, `unknown variable x`,
  `set needs value`, `args must be a JSON list, got ...`, `bad key ...`, and a reply that is not a JSON list
  (the server cut or changed the line). `rpc` goes only on `function` (not `process`: start it from an rpc
  function) and on `game var` / `save var` with a plain name.
- Values go through `variable::parse_json` / `variable::to_json` (verified, server-check-27): numbers come back as
  floats (`6.0` → CLI prints `6`), texts, lists (nested too), maps (JSON objects) round-trip; JSON `true` becomes the
  TEXT "true"; a location comes back as a Java string (`"Location{world=...,x=0.5,y=4.0,...}"`: return
  `[loc.get_coordinate("X"), loc.get_coordinate("Y"), loc.get_coordinate("Z")]` if you need numbers; or simply `loc.x`). Parsing is lenient: `set x abc` stores the text "abc"; args that
  are not a JSON list give `error args must be a JSON list`; broken JSON (`[1,`) is a server error, no reply.
- `%placeholder%` inside a TEXT value is expanded by the server whenever that text is used: the CLI sends `%` as
  `\u0025` so `set s '"%player%"'` stores the literal text, but reading it back (get, a call returning it)
  already gives the nickname. `&` / `§` / `%` in the reply JSON are sent as `\u0026` / `\u00a7` / `\u0025`
  (the message is legacy-parsed: `&c` would become a color); the CLI decodes them.
- Protocol (`jmvcc client` speaks it): custom click packet `jmvcc:rpc` with SNBT data `{id:"<id>", k:"<key>",
  op:"call", fn:"give", args:"[5]"}` | `{id, k, op:"get", var:"coins"}` | `{id, k, op:"set", var:"coins",
  value:"100"}` | `{id, k, op:"list"}` (args / value are JSON TEXT: NBT lists hold one type). Reply — a log line
  to the asker only: `jmvcc:rpc <id> ok [<json>]` (always a one-element list; `[null]` — no return value) or
  `jmvcc:rpc <id> error <text>`. The mod hides `jmvcc:*` lines from chat. Shares one `player_custom_click` with
  the graceful stop receiver; your own `player_custom_click` handlers keep working and never see `jmvcc:*` keys.
- Cost: nothing per tick; one key compare per custom click packet.
