Execute a Lua file
lua_exec_fileExecutes Lua code from a file on the game's disk by absolute or relative path, so scripts can be tested without pasting file contents into each call.
Instructions
Like lua_exec but reads the code from a file on the game's disk (with a mounted Lua folder, see lua_mount, a relative path finds its files first, like the engine). The chunk is named after the real path (e.g. @lua/mcpagent_tmp/test.lua) for actionable errors and tracebacks, or chunkname (e.g. the addon-relative name of a file from your git worktree). Prefer it to pasting a file into lua_exec's code: it saves the tokens of the file on every call. With fields, only the test's verdict comes back. Example: {"realm": "server", "path": "tests/check_doors.lua", "fields": ["pass", "fails"]} (relative: lua/mcpagent_tmp/tests/check_doors.lua first).
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": {
"path": "<path>"
},
"name": "lua_exec_file"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| jit | No | Obsolete. gmod-mcp no longer turns the LuaJIT compiler off, neither for this code nor for the functions it defines (hooks and timers run at real speed, timings are real). jit: true now only ignores `budget`. | |
| path | Yes | Absolute path on the game's disk (e.g. a file in your git worktree), or relative: looked up in lua/mcpagent_tmp/, then the mounted Lua folder if any (lua_mount), then the game folder ('addons/x/lua/y.lua'), then lua/, gamemodes/ and addons/*/lua/ (include() style). | |
| depth | No | Cut tables deeper than this (default: no cut). | |
| limit | No | Cut tables longer than this (default: no cut). | |
| realm | No | Lua state to run in. Default: menu in client mode, which has no game libraries (ents, util.TraceLine, players...): pass 'server' or 'client' for game code; they exist only once a map is loaded (map_load). On srcds: server (the default; no menu or client realm). | |
| budget | No | Optional time limit in seconds, best effort (none by default). It stops loops written in this code itself (error budget_exceeded), not a loop inside a compiled function it calls. Without it, an infinite loop freezes the game: the call fails with main_thread_timeout after timeout_s, status shows main_thread_stalled, and game_terminate ends the game. | |
| fields | No | Keep only these keys of each returned table (e.g. ["pass", "fails"]): the rest of a large result is dropped before it reaches you. Only returned tables are projected: when none is (a JSON string, a number), the result says so in fields_note. | |
| instance | No | Optional. Instance identifier (see instances_list). If present and different from the local instance, the call is relayed by the coordinator to that instance. | |
| chunkname | No | Chunk name: the source shown by debug.getinfo, errors and tracebacks, e.g. '@addons/my_addon/lua/my_addon/core.lua' for code that identifies its caller by file. Default: '=mcpagent:lua_exec', or the file's path. | |
| timeout_s | No | How long to wait for the game's answer (default 60, or budget + 10). Past it the call fails with main_thread_timeout; the code may still be running. | |
| max_string | No | Cut strings longer than this (default: no cut). |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| n | Yes | ||
| file | No | ||
| next | No | ||
| note | No | ||
| output | No | ||
| values | Yes | ||
| warning | No | ||
| budget_s | No | ||
| chunkname | No | ||
| next_call | No | ||
| projected | No | ||
| truncated | No | ||
| generation | No | ||
| answered_by | No | ||
| chunk_bytes | No | ||
| duration_ms | No | ||
| fields_note | No | ||
| truncated_note | No | ||
| version_warning | No | ||
| blocked_console_commands | No |