ReScript — 143 Operations for AI Agents
This page is the canonical reference an AI coding agent uses to refactor, query, and analyze ReScript code through the act MCP server. 143 operations available: 98 refactor, 15 query, 30 analysis. 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.
15Query
98Refactor
30Analysis
Query
| Operation | Description |
|---|---|
callers | Find every call site of a function or method across the codebase. Use to understand who depends on a function before changing its signature. Requires LSP. Params: symbol (string) [, file (string)] |
control_flow | Get a function's control flow — branches, loops, early returns, and basic blocks in execution order. Use to understand complex logic without reading the full implementation. Params: target (string), file (string) |
definition | Jump to definition — find where a symbol is defined given a usage location. Uses abstract syntax trees by default, no LSP required. Params: symbol (string), file (string), line (u32), column (u32) |
diagnostics | Get compiler errors and warnings from the language server. Omit `file` for workspace-wide diagnostics. Pass a file path or directory path to scope results. Requires LSP. |
fix_auto | Auto-fix all deterministic issues in a file, directory, or workspace — missing imports, unused imports, simple type errors. Runs multiple fix-revalidate cycles. Use after making changes to clean up automatically. Requires LSP. Params: none [, file (string), workspace_mode (bool), category (string), commit (bool), max_rounds (u32)] |
get_type | Get the compiler-inferred type of any expression at a position. Use to understand types without reading surrounding code. Requires LSP. Params: file (string), line (u32), column (u32) |
graph | Build a dependency graph from a file — trace what it imports and what imports it, across multiple hops. Use to understand module relationships and change impact before refactoring. Params: file (string) [, depth (u32), direction (string), leaves (bool), order (string)] |
import_organize | Organize, sort, and deduplicate imports in a file. Removes unused imports. Use after adding new code or moving symbols to clean up import blocks automatically. Params: file (string) [, preview (bool)] |
interface | Get a symbol's public API — signatures, types, and docstrings without implementation bodies. Like skeleton but for a single symbol. Use to understand how to call something without reading its internals. Params: target (string), file (string) [, include_private (bool)] |
mutations | Identify side effects — what external state a function reads or writes (globals, file I/O, network, etc.). Use to understand if a function is pure or has hidden dependencies. Params: target (string), file (string) |
references | Find every usage of a symbol across the entire codebase — all files, not just the current one. Use before renaming, refactoring, or deleting to understand full impact. Requires LSP. Params: symbol (string), file (string) |
repo_outline | Get a compressed overview of the entire repository in one call — file tree with languages, line counts, and optionally symbol names per file. Orders of magnitude cheaper than listing directories and reading files individually. Params: none [, path (string), depth (u32), include (glob), exclude (glob), symbols (bool), max_files (u32), relative (bool)] |
skeleton | Get a file's structure — function signatures, class declarations, type definitions — without implementation bodies. Use INSTEAD of reading the full file to understand its API. Typically 5-10x fewer tokens than reading the raw file. Params: file (string) |
symbols | List all symbols (functions, classes, variables, types, constants) defined in a file with their locations and kinds. Use INSTEAD of reading a file when you need to know what's defined in it. Much cheaper than reading the full file. IMPORTANT: file must be a path to a single source file — never a directory or empty string. Params: file (string) |
symbols_batch | Retrieve symbols from multiple files in a single call. Use instead of calling symbols() in a loop — one request instead of N. Params: none [, files (string[]), ids (string[]), kinds (string[])] — provide files or ids |
Refactor
| Operation | Description |
|---|---|
add-error-handling-to-promise | Add .catch() to a promise chain |
add-export-declaration | Mark a symbol as exported (adds interface annotation comment) |
add-import | Add an open statement for a module |
add-import-alias | Add a module alias declaration: module Alias = ModulePath |
add-missing-cases | Add missing switch cases |
add-missing-record-fields | Add missing required fields to a record literal |
add-module-open | Prepend an open statement at the top of the file |
add-option-annotation | Add option<type> annotation to a binding |
add-result-annotation | Add result<ok_type, err_type> annotation |
add-return-type-annotation | Add return type annotation to a function |
add-try-catch-around-await | Wrap async operation in try-catch |
add-type-annotation | Add a type annotation to a let binding |
add-type-annotation-to-param | Add type annotation to a function parameter |
convert-callback-to-promise | Wrap callback-based function in a Promise |
convert-concat-to-template-literal | Convert ++ string concatenation to a template literal |
convert-curried-to-uncurried | Convert a curried function (a => b => body) to uncurried form (. a, b) => body |
convert-exception-to-result | Wrap an exception-raising expression in a result type |
convert-for-loop-to-array-filter | Convert a for-in loop to an Array.filter call |
convert-for-loop-to-array-map | Convert a for-in loop to an Array.map call |
convert-for-loop-to-array-reduce | Convert a for-in loop to an Array.reduce call |
convert-for-loop-to-list-map | Convert for loop to List.map |
convert-if-else-to-switch | Convert an if-else chain to a switch expression |
convert-if-to-ternary | Convert an if-else expression to a ternary (cond ? a : b) |
convert-imperative-to-functional | Convert imperative mutation to functional pipeline |
convert-let-to-ref | Convert a let binding to a mutable ref cell |
convert-null-to-none | Replace Js.null / null with None |
convert-nullable-to-option | Wrap a nullable JS value in option |
convert-positional-to-labeled-args | Convert positional function parameters to labeled (~param) form |
convert-promise-chain-to-async | Convert .then() chain to async/await |
convert-record-to-variant | Convert a record type definition to a variant |
convert-ref-to-let | Convert a ref cell back to an immutable let binding |
convert-switch-to-if-else | Convert a switch expression to an if-else chain |
convert-ternary-to-if | Convert a ternary expression to an if-else block |
convert-to-option-pattern-match | Generate a switch pattern match for an Option variable |
convert-to-result-for-safety | Wrap a fallible expression in a result type |
convert-to-result-pattern-match | Convert try-catch to pattern match on result |
convert-uncurried-to-curried | Convert an uncurried function (. a, b) => body to curried form a => b => body |
convert-while-to-recursion | Convert while loop to tail-recursive function |
extract-condition-to-variable | Extract complex condition to named binding |
extract-constant | Extract a literal or expression into a top-level constant binding |
extract-function | Extract selected lines into a new named function |
extract-record-type | Extract an inline record literal to a named type |
extract-variable | Extract an expression into a new local let binding |
extract-variant-type | Extract an inline variant to a named type |
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)] |
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-accessor-functions | Generate getter accessor functions for each record field |
generate-documentation-comment | Generate a doc comment block above a binding |
generate-equality-function | Generate a structural equality function for a type |
generate-external-binding | Generate a @external binding |
generate-function-stub | Generate a function stub with Js.log("TODO") body |
generate-impl-stubs | Generate implementation stubs inside a module block |
generate-module-type | Generate a module type signature block |
generate-option-wrapper | Generate an option<'a> wrapper |
generate-record-constructor | Generate a type declaration for a record type |
generate-record-creator | Generate a maker function (makeRecord) for a record type |
generate-record-type | Generate a record type definition from field descriptions |
generate-record-updater | Generate an updater function for a record |
generate-result-wrapper | Generate a result<'a, string> error wrapper function |
generate-send-binding | Generate a @send method binding |
generate-string-representation | Generate a typeToString conversion function |
generate-test-case | Generate a single test(...) case with Arrange/Act/Assert comments |
generate-type-definition-docs | Generate a doc comment for a type |
generate-unit-test-scaffold | Generate a describe/test scaffold for a module |
generate-variant-matcher | Generate a pattern match function for a variant |
generate-variant-type | Generate a variant type definition |
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)] |
inline-constant | Inline a named constant by replacing all references with its value |
inline-variable | Inline a let-bound variable by replacing 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-local-binding | Insert a new let binding at the specified line |
introduce-named-constant | Extract a literal expression into a named top-level constant |
introduce-parameter-from-local | Promote a local binding to a function parameter |
invert-if-condition | Invert the condition of an if-else |
join-adjacent-strings | Merge adjacent string literals joined with ++ |
make-field-optional | Make a record field optional (option<'a>) |
move-to-module | Move a symbol into a qualified module path |
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)] |
organize-imports | Sort and deduplicate open statements alphabetically |
remove-dead-code | Remove unused declarations |
remove-import | Remove an open statement for a module |
remove-module-open | Remove a specific open statement from the file |
remove-unnecessary-else | Remove else branch after early return |
remove-unused-parameter | Remove a parameter that is never used in the function body |
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)] |
rename-identifier | Rename a variable, function, or binding across its scope |
rename-record-field | Rename a field in a record type definition |
reorder-parameters | Reorder the parameters of a function definition |
use-option-flat-map | Convert nested option map to flatMap |
use-option-get-or | Convert switch on option to Option.getOr |
use-option-instead-of-if | Replace an Option null-check if-statement with Option.isSome / Option.isNone |
use-option-map | Convert switch on option to Option.map |
use-record-shorthand | Convert {x: x} to {x} shorthand |
use-result-flat-map | Convert nested result map to flatMap |
use-result-map | Convert switch on result to Result.map |
use-spread-operator | Convert manual field copies to record spread |
wrap-in-option-for-safety | Wrap a potentially-missing value binding in Option |
wrap-value-in-option | Wrap an expression in Some(...) |
Analysis
| Operation | Description |
|---|---|
analyze_chokepoints | Find files that act as critical bottlenecks — high betweenness centrality in the dependency graph (R4). Params: none [, include (string[]), exclude (string[])]. Use include/exclude to restrict the scan scope (e.g. include=["crates"], exclude=["corpus"]). |
analyze_clusters | Identify tightly coupled groups of files using community detection. Use to discover natural module boundaries and understand which files change together. Params: none [, granularity (string), min_size (u32), include (string[]), exclude (string[])]. Use include/exclude to restrict the scan scope (e.g. include=["crates"], exclude=["corpus"]). |
analyze_cohesion | Measure intra-module cohesion for each file — ratio of internal to total symbol edges (H2). Params: none [, include (string[]), exclude (string[])]. Use include/exclude to restrict the scan scope (e.g. include=["crates"], exclude=["corpus"]). |
analyze_coupling | Measure coupling per file — how many files depend on it (afferent) vs how many it depends on (efferent), plus instability and abstractness scores. Use to find the most critical/fragile files. Params: none [, granularity (string), sort (string), threshold (f64), include (string[]), exclude (string[])]. Use include/exclude to restrict the scan scope (e.g. include=["crates"], exclude=["corpus"]). |
analyze_cycle_risk | Score each circular dependency cycle by its external risk surface (R6 circular risk zones analysis). Params: none [, include (string[]), exclude (string[])]. Use include/exclude to restrict the scan scope (e.g. include=["crates"], exclude=["corpus"]). |
analyze_cycles | Find circular dependency chains in the codebase. Use to identify import cycles that cause build issues or indicate architecture problems. Params: none [, granularity (string), max_length (u32), include (string[]), exclude (string[])]. Use include/exclude to restrict the scan scope (e.g. include=["crates"], exclude=["corpus"]). |
analyze_dead_code | Find dead code — functions, classes, and types that are never referenced from any entry point. Use before cleanup to safely identify what can be deleted. Params: none [, entry (string[]), granularity (string), include_tests (bool), include (string[]), exclude (string[])]. Use include/exclude to restrict the scan scope (e.g. include=["crates"], exclude=["corpus"]). |
analyze_depth | Compute longest transitive dependency chain per file (S4 dependency depth analysis). Params: none [, include (string[]), exclude (string[])]. Use include/exclude to restrict the scan scope (e.g. include=["crates"], exclude=["corpus"]). |
analyze_entry_points | Detect entry points: main functions, HTTP routes, CLI commands, event listeners, test files (S5). Params: none [, include (string[]), exclude (string[])]. |
analyze_export | Export the full semantic graph (files, symbols, dependencies) in JSON, DOT (Graphviz), or CSV format. Use for visualization or external analysis. Params: none [, format (string), include (string[]), exclude (string[])]. Use include/exclude to restrict the scan scope (e.g. include=["crates"], exclude=["corpus"]). |
analyze_extraction | Score clusters for service or package extraction viability (M2 extraction candidates analysis). Params: none [, include (string[]), exclude (string[])]. Use include/exclude to restrict the scan scope (e.g. include=["crates"], exclude=["corpus"]). |
analyze_fan_balance | Compute fan-in/fan-out imbalance for migration ordering guidance (M6 fan balance analysis). Params: none [, include (string[]), exclude (string[])]. Use include/exclude to restrict the scan scope (e.g. include=["crates"], exclude=["corpus"]). |
analyze_features | Inventory language-specific AST features used in the codebase — async, generics, decorators, etc. (M3). Params: none [, include (string[]), exclude (string[])]. Use include/exclude to restrict the scan scope (e.g. include=["crates"], exclude=["corpus"]). |
analyze_hotspots | Rank files by composite complexity score — max cyclomatic complexity, statement count, nesting depth (H1). Params: none [, top_n (u32), include (string[]), exclude (string[])]. Use include/exclude to restrict the scan scope (e.g. include=["crates"], exclude=["corpus"]). |
analyze_impact | Compute change impact for a target file — finds all files directly and transitively depending on it (R1). Params: target (string) [, max_depth (u32), include (string[]), exclude (string[])]. Use include/exclude to restrict the scan scope (e.g. include=["crates"], exclude=["corpus"]). |
analyze_inconsistencies | Detect inconsistent abstractions — sibling files in the same directory that diverge from the group's structural pattern (H5). Params: none [, include (string[]), exclude (string[])]. |
analyze_inheritance | Detect tangled inheritance — deep hierarchies (>N levels) and diamond inheritance (H6). Params: none [, include (string[]), exclude (string[])]. |
analyze_interface_bloat | Detect interface bloat — files where the public API is disproportionately large relative to implementation (H3). Params: none [, include (string[]), exclude (string[])]. |
analyze_interfaces | Map cross-module interfaces — symbols that cross directory-module boundaries, ranked by interface width (M4). Params: none [, include (string[]), exclude (string[])]. Use include/exclude to restrict the scan scope (e.g. include=["crates"], exclude=["corpus"]). |
analyze_layers | Detect architectural layers from directory names and find dependency direction violations (S1+S2). Params: none [, detect_only (bool), include (string[]), exclude (string[])]. Use include/exclude to restrict the scan scope (e.g. include=["crates"], exclude=["corpus"]). |
analyze_orphan_types | Find type definitions used exclusively outside their defining directory (H4 orphan types analysis). Params: none [, include (string[]), exclude (string[])]. Use include/exclude to restrict the scan scope (e.g. include=["crates"], exclude=["corpus"]). |
analyze_patterns | Find code smells — god functions, deep nesting, high coupling, and other structural issues. Use to identify refactoring targets or assess code quality. Params: none [, tier (string), pattern (string), file (string), severity (string), include (string[]), exclude (string[])]. Use include/exclude to restrict the scan scope (e.g. include=["crates"], exclude=["corpus"]). |
analyze_platform_deps | Detect platform-specific API usage by scanning imports (M5 platform dependencies analysis). Params: none [, include (string[]), exclude (string[])]. Use include/exclude to restrict the scan scope (e.g. include=["crates"], exclude=["corpus"]). |
analyze_readiness | Compute migration readiness scores per file — composite of complexity, coupling, porting blockers (M1). Params: none [, include (string[]), exclude (string[])]. Use include/exclude to restrict the scan scope (e.g. include=["crates"], exclude=["corpus"]). |
analyze_roles | Classify files by architectural role: entry point, routing, business logic, data access, config, test, utility, types, generated (S3). Params: none [, include (string[]), exclude (string[])]. |
analyze_seams | Find the natural boundaries between file clusters — the narrowest points where groups of files communicate. Use to identify where to split modules or add API boundaries. Params: none [, min_cluster_size (u32), max_seam_width (u32), include (string[]), exclude (string[])]. Use include/exclude to restrict the scan scope (e.g. include=["crates"], exclude=["corpus"]). |
analyze_stability | Compute stability index (R2) and detect stable dependency violations (R3) — flags edges where stable modules depend on unstable ones. Params: none [, index_only (bool), include (string[]), exclude (string[])]. |
analyze_surface | Measure API surface area — count exposed functions, types, and complexity at a module boundary. Use to assess whether an API is too large or leaky. Params: none [, boundary (string), files (string), include (string[]), exclude (string[])]. Use include/exclude to restrict the scan scope (e.g. include=["crates"], exclude=["corpus"]). |
analyze_test_gaps | Detect source files with no or partial test coverage based on graph import analysis (R5). Params: none [, include (string[]), exclude (string[])]. Use include/exclude to restrict the scan scope (e.g. include=["crates"], exclude=["corpus"]). |
analyze_type_completeness | Analyze type boundary completeness — detect 'any' types, untyped parameters, missing return types at exported function boundaries (M7). Params: none [, include (string[]), exclude (string[])]. |