Skip to main content
Glama

Execute a Lua file

lua_exec_file
Destructive

Executes 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

NameRequiredDescriptionDefault
jitNoObsolete. 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`.
pathYesAbsolute 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).
depthNoCut tables deeper than this (default: no cut).
limitNoCut tables longer than this (default: no cut).
realmNoLua 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).
budgetNoOptional 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.
fieldsNoKeep 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.
instanceNoOptional. Instance identifier (see instances_list). If present and different from the local instance, the call is relayed by the coordinator to that instance.
chunknameNoChunk 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_sNoHow 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_stringNoCut strings longer than this (default: no cut).

Output Schema

NameRequiredDescriptionDefault
nYes
fileNo
nextNo
noteNo
outputNo
valuesYes
warningNo
budget_sNo
chunknameNo
next_callNo
projectedNo
truncatedNo
generationNo
answered_byNo
chunk_bytesNo
duration_msNo
fields_noteNo
truncated_noteNo
version_warningNo
blocked_console_commandsNo

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.3.7

TDQS

A4.5/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already declare destructiveHint=true and openWorldHint=false, so the safety profile is carried by structured data. The description adds real value beyond that (chunk named after the real path for actionable errors/tracebacks, and that `fields` returns only a projected verdict), but it does not itself warn that executing arbitrary code can mutate or break game state, leaving the risk implied by the annotation alone.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Front-loaded with the lua_exec contrast, then rationale, then a single dense example; every sentence adds decision-relevant information and nothing is repeated from the schema verbatim.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For an 11-parameter, destructive, output-schema-backed tool, the description covers the alternative it replaces, the path resolution preconditions, chunk naming, and result projection. Remaining detail (budget, realm, timeouts) is thoroughly documented in the schema, so nothing needed to call it correctly is missing.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so baseline is 3, but the description goes further: it explains why chunkname matters (debug.getinfo/errors/tracebacks identifying callers) and shows how `fields` narrows the returned result, with a concrete example call combining path and fields.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb+resource (execute a Lua file) and immediately distinguishes it from the sibling lua_exec by explaining it reads code from a file on the game's disk. An agent can choose between the two without opening either schema.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Explicit routing: 'Prefer it to pasting a file into lua_exec's code: it saves the tokens of the file on every call.' It also names the lua_mount dependency and explains path resolution order, so the agent knows the preconditions for a relative path.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.