Luau — 119 Operations for AI Agents
This page is the canonical reference an AI coding agent uses to refactor, query, and analyze Luau code through the act MCP server. 119 operations available: 45 refactor, 18 query, 42 analysis, 14 verification. Each operation is callable from Claude Code, Cursor, Codex, OpenCode, or any MCP-compatible agent host. Click any operation for a stable anchor link suitable for citation.
Worked Luau examples
act101 edits Luau source using the statement, expression, and metatable-class structure the tree-sitter grammar exposes, so an edit targets a specific call or method definition rather than a raw line offset. It can wrap a statement in an if x ~= nil then ... end guard around a variable that may be nil. It can rewrite a .. string concatenation chain into a string.format call with the right %s placeholders. And it can generate a __tostring metamethod for a metatable-based class that formats the fields you name. Each example below is the verbatim output of the command shown, run against the file shown.
Add a nil guard around a method call
player.luau calls player:Destroy() right after getPlayer(), with no check that player is non-nil.
$ act refactor-lang add_nil_guard --file player.luau --params '{"variable_name":"player","line":2,"column":1}'
Before
local player = getPlayer()
player:Destroy()
After
local player = getPlayer()
if player ~= nil then
player:Destroy()
end
player:Destroy() is wrapped in if player ~= nil then ... end, so the call only runs when getPlayer() returned a value.
Convert string concatenation to string.format
greet.luau builds greeting by concatenating "Hello, ", name, and "!" with ...
$ act refactor-lang convert_string_concatenation_to_interpolation --file greet.luau --params '{"line":2,"column":1}'
Before
local name = "Alice"
local greeting = "Hello, " .. name .. "!"
print(greeting)
After
local name = "Alice"
local greeting = string.format("Hello, %s!", name)
print(greeting)
The concatenation becomes string.format("Hello, %s!", name), with one %s placeholder for the interpolated variable.
Generate a __tostring metamethod
point.luau defines a Point class with x/y fields set in Point.new, but no way to print it as a readable string.
$ act refactor-lang generate_tostring --file point.luau --params '{"class_name":"Point","display_fields":["x","y"],"line":1,"column":1}'
Before
local Point = {}
Point.__index = Point
function Point.new(x, y)
local self = setmetatable({}, Point)
self.x = x
self.y = y
return self
end
return Point
After
local Point = {}
Point.__index = Point
function Point:__tostring()
return string.format("Point(x=%s, y=%s)", tostring(self.x), tostring(self.y))
end
function Point.new(x, y)
local self = setmetatable({}, Point)
self.x = x
self.y = y
return self
end
return Point
A Point:__tostring() method is inserted that returns string.format("Point(x=%s, y=%s)", tostring(self.x), tostring(self.y)), so tostring(instance) renders the fields by name.
Query
18 query tools, the same on every supported language. Descriptions live in the shared reference: /docs/query-tools.
callers control_flow data_flow definition diagnostics effect_closure effect_summary fix_auto get_type graph import_organize interface mutations references repo_outline skeleton symbols symbols_batch
Refactor
| Operation | Description |
|---|---|
add-nil-guard |
Wrap expression in nil check guard |
add-type-annotation |
Add explicit type annotation to a local variable declaration |
consolidate-imports |
Merge multiple require() calls for the same module |
convert-for-each-to-for |
Convert generic for-each loop to numeric for loop |
convert-for-to-for-each |
Convert numeric for loop to generic for-each with ipairs |
convert-function-declaration-to-variable |
Convert function declaration to variable assignment form |
convert-if-to-ternary |
Convert if-else to ternary (cond and a or b) idiom |
convert-repeat-to-while |
Convert repeat-until loop to while loop |
convert-string-concatenation-to-interpolation |
Convert string concatenation to string.format() |
convert-ternary-to-if |
Convert ternary (cond and a or b) to explicit if-else |
convert-variable-to-function-declaration |
Convert variable function assignment to function declaration form |
convert-while-to-repeat |
Convert while loop to repeat-until loop |
extract-constant |
Extract a literal into a module-level constant and replace all occurrences |
extract-function |
Extract code block into new local function |
extract-to-module |
Wrap file content in module return pattern |
extract-variable |
Extract expression into local variable |
extract_function |
Extract a code selection into a new function — automatically infers parameters, return types, and inserts the call site. Use instead of manually cutting/pasting code. Works without LSP; LSP improves type inference. Params: file (string), new_name (string), start_line (u32), start_column (u32), end_line (u32), end_column (u32) [, preview (bool), receipt (bool)] |
extract_variable |
Extract an expression into a named variable — inserts the declaration and replaces the expression with the variable name. Works without LSP. Params: file (string), new_name (string), start_line (u32), start_column (u32), end_line (u32), end_column (u32) [, preview (bool)] |
generate-class-from-interface |
Generate a class/table implementation from a type definition |
generate-constructor |
Generate a new() constructor for a Luau class table |
generate-eq |
Generate a __eq metamethod for equality comparison |
generate-getter |
Generate a getter method for a class property |
generate-getters-setters |
Generate both getter and setter for a class property |
generate-setter |
Generate a setter method for a class property |
generate-test-function |
Generate a test function stub for a given function |
generate-tostring |
Generate a __tostring metamethod for a class |
inline |
Inline a variable, function, or method — replace every usage with its definition body, then remove the original. The inverse of extract. Works without LSP (single-file); LSP enables cross-file inlining. Params: file (string), symbol (string) [, line (u32), preview (bool), receipt (bool)] |
inline-function |
Inline a simple function call with the function body |
inline-variable |
Inline a local variable by replacing all uses with its value |
insert_body |
Replace a function's implementation body with new code. AST-validated — rejects if the result has parse errors, so you can't accidentally break syntax. Use instead of manual text editing for function rewrites. Params: file (string), symbol (string), code (string) [, commit (bool)] |
introduce-parameter |
Extract a literal into a new function parameter |
introduce-variable |
Extract a repeated expression into a new local variable |
move_symbol |
Move a function, class, or type to a different file and automatically update all imports across the codebase. Use instead of manually cut/paste + fixing imports. Works without LSP (single-file); LSP enables cross-file import updates. Params: file (string), symbol (string), destination (string) [, preview (bool), receipt (bool)] |
promote-local-to-module |
Convert a local variable to a module-level export |
recipe_run |
Run a codemod recipe: declarative match → transform → optional verify across modeled grammars. Preview lists matches; apply writes with optional E7 receipts and all-or-nothing rollback. Returns a per-site report. |
remove-unreachable-code |
Remove unreachable statements after return/break/continue |
remove-unused-function |
Remove a function definition that is never called |
remove-unused-import |
Remove a require() statement that is not used in the file |
remove-unused-parameter |
Remove a function parameter that is never used in the function body |
remove-unused-variable |
Remove a local variable declaration that is never used |
rename |
Rename a symbol and automatically update ALL references across the codebase. Safer and faster than find-and-replace — AST-aware, won't rename strings or comments. Works without LSP (single-file); LSP enables cross-file renames. Params: file (string), old_name (string), new_name (string) [, line (u32), column (u32), preview (bool), receipt (bool)] |
rename-identifier |
Rename variable, function, or parameter across references |
rename-module-member |
Rename a module-level function or variable by name |
rename-type-alias |
Rename a type alias across all usages |
reorder-function-parameters |
Reorder function parameters according to a new order |
Analysis
42 analysis tools, the same on every supported language. Descriptions live in the shared reference: /docs/analysis-tools.
analyze_api_diff analyze_chokepoints analyze_clones analyze_clusters analyze_cohesion analyze_conformance analyze_coupling analyze_cycle_risk analyze_cycles analyze_dead_code analyze_depth analyze_entry_points analyze_export analyze_extraction analyze_fan_balance analyze_features analyze_hotspots analyze_impact analyze_inconsistencies analyze_inheritance analyze_interface_bloat analyze_interfaces analyze_layers analyze_orphan_types analyze_patterns analyze_platform_deps analyze_readiness analyze_roles analyze_seams analyze_stability analyze_surface analyze_test_gaps analyze_thickness analyze_type_completeness churn_hotspots co_change_clusters coverage_overlay ownership_map profile_overlay simulate split_module trace_overlay
Verify
14 verify tools, the same on every supported language. Descriptions live in the shared reference: /docs/verification.
bisect_regression gate generate_test_harness scan secret_surface summarize_pr taint_flow unsafe_surface verify_behavioral_equivalence verify_contract_preserved verify_diff_semantics verify_port_parity verify_side_effects verify_test_impact