Skip to main content
Glama

Execute Lua

nvim_exec_lua

Run Lua in Neovim to control buffers, windows, diagnostics, LSP, and terminals, returning results as JSON. Use return for values and ... for arguments to access the full Neovim Lua API.

Instructions

Run Lua in Neovim via nvim_exec_lua and return the result as JSON. The code is a function body, so use return to produce a value and reference call arguments via .... This is the most powerful tool: anything the Neovim Lua API can do is reachable here.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
argsNoOptional arguments, available in the Lua code via `...`.
codeYesLua code to execute. Use `return` to yield a value.
Behavior4/5

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

With no annotations, the description carries the full burden. It clearly explains the execution model: the code is a function body requiring `return` to produce a value, and args are accessed via `...`. It also discloses the output format as JSON. It does not explicitly warn about side effects or error handling, but the 'most powerful' phrasing hints at broad capabilities. This is substantial behavioral disclosure for a tool with no annotations.

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?

The description is three sentences with no filler. It front-loads the core function and return format, follows with the critical usage requirement (return and varargs), and ends with capability scope. Every sentence earns its place, making it efficient and easy to parse.

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

Completeness4/5

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

Despite no annotations and no output schema, the description is quite complete for a two-parameter tool. It explains the purpose, execution model, return type, and scope. It lacks explicit side-effect warnings and error behavior, but the essential operational details are present. Given the simplicity of the schema, the description is sufficient for an agent to invoke it correctly.

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?

The schema already describes both parameters with 100% coverage. The description adds value by explaining the relationship between the `code` parameter and the function-body semantics, and how `args` maps to `...` in the code. This goes beyond the schema's simple descriptions, providing practical guidance on how to construct calls.

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?

The description states the tool runs Lua via nvim_exec_lua and returns JSON, using a specific verb (Run) and resource (Neovim Lua API). It distinguishes itself from sibling tools like nvim_eval (Vimscript) and nvim_command by emphasizing that any Neovim Lua API call is reachable, which clearly sets it apart. This is specific and actionable.

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

Usage Guidelines4/5

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

The description gives clear context: it is labeled 'the most powerful tool' with access to everything the Lua API can do, implying it is the general-purpose fallback. However, it does not explicitly say when to prefer alternatives like nvim_eval for Vimscript or nvim_command for commands, nor does it state any exclusions. Thus it provides context but no explicit when/when-not guidance.

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

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Shooooooooo/nvim-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server