nvim-mcp
nvim-mcp is an MCP server that gives AI agents full programmatic access to a running Neovim session via its native msgpack-RPC socket, enabling them to view, edit, and manipulate code as if directly using the editor.
Connect to Neovim: Auto-discover and connect to one or more running Neovim instances by index, socket path, or terminal PID.
Run Ex commands: Execute any Vim/Neovim ex command (e.g.,
:w,:vsplit,:lua ...), single or batched.Send keystrokes: Send raw key sequences for navigation, mode switching, and triggering mappings.
Get session state: Retrieve a full snapshot including mode, CWD, open buffers, window layout, cursor position, folds, visual selections, marks, diagnostics summary, and active highlights.
Read buffer contents: Read an entire in-memory buffer or a specific line range, with line numbers.
Edit buffers: Perform find-and-replace (must match exactly once) or overwrite entire buffer contents — all in-memory with full undo support, nothing written to disk until explicitly saved.
Get LSP diagnostics: Retrieve errors, warnings, hints, and info from LSP for all buffers or a specific file.
Highlight lines: Annotate specific line ranges with colored extmarks (without modifying content), apply multiple highlights simultaneously, and clear them when done.
Allows AI assistants to control a running Neovim session by sending ex commands, Vimscript expressions, and key sequences; retrieving structured state snapshots including current file, cursor position, mode, window layout, and modified buffers; managing connections to specific instances; and browsing operation recipes for files, navigation, buffers, windows, marks, registers, folds, and LSP actions.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@nvim-mcp go to definition of the function under cursor"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
nvim-mcp
An MCP server that gives AI agents first-class access to your running Neovim session. It connects through Neovim's native msgpack-RPC socket — no plugins required.
Works with Cursor, Claude Code, Codex, OpenCode, and any MCP-compatible client.
Before you connect an agent to Neovim, please read Working safely.
What agents can do
See what you see — editor mode, working directory, open buffers, window layout, cursor context, folds, selections, marks, and diagnostics.
Edit buffers in memory — find-and-replace or full rewrites with immediate feedback and full undo support. Nothing touches disk until you save.
Run any Vim command —
:w,:e,:vsplit, macros, or anything else you could type at the command line.Send keystrokes — navigate, enter insert mode, trigger mappings.
Query LSP diagnostics — errors, warnings, and hints across one buffer or the whole session.
Annotate code with highlights and virtual text — colored line highlights and inline/above/below text notes that never touch the buffer's real content.
Work with multiple instances — auto-discovers running sessions and connects to the right one. See multiple instances.
Anything you can do in Neovim, the agent can too. See the full tool reference for details.
Related MCP server: @aetherall/mcp-nvim-tmux
Demos
Quick start
nvim-mcp runs via uv (recommended) or Nix.
Cursor users: A Marketplace plugin is pending review — once available, it installs the MCP server and agent rule together (you can skip to step 4). To activate the rule, start chats with something like "Connect to my Neovim instance" — or set the rule to "Always" in Settings → Rules to apply it on every turn.
Install a launcher.
curl -LsSf https://astral.sh/uv/install.sh | shInstall Nix — flakes must be enabled.
Register the MCP server with your client. Example for Cursor (
.cursor/mcp.json):{ "mcpServers": { "nvim-mcp": { "command": "uvx", "args": ["nvim-mcp"] } } }{ "mcpServers": { "nvim-mcp": { "command": "nix", "args": ["run", "github:paulburgess1357/nvim-mcp"] } } }For Claude Code, Codex, Claude Desktop, OpenCode, and other clients, see the configuration guide.
Add agent rules — do not skip this. Without rules, the agent has the tools but doesn't know when or how to use them, and behavior will be unreliable. See the configuration guide for setup.
Start Neovim — on most Linux systems it listens on a Unix socket automatically and is discovered by nvim-mcp. If auto-discovery doesn't work, see environment variables. Running multiple instances? See multiple instances.
Verify it works
Open a file in Neovim and paste this into your AI agent:
For each step: explain what you're about to do, then do it, then tell me
what happened. Wait for me to say "next" before moving on.
1. What file am I in? Highlight the function my cursor is in.
2. Are there any diagnostics? Highlight any lines with errors or warnings.
3. Add a docstring above the function, then show me the diff.
4. Open a vertical split, write a short test for that function, and save both files.Working safely
The tools and agent rules are designed to use non-destructive operations — edits happen in memory, undo history is preserved, and the agent is steered toward buffer operations. But LLMs are non-deterministic, have full access to Neovim's API, and you should assume they will make mistakes. Work in a version-controlled directory.
Requirements
Linux
Python ≥ 3.10
Neovim ≥ 0.11 (older versions work with
--listenandNVIM_ADDRESS)
License
MIT — see LICENSE.
Available Tools
18 toolsadd_virtual_textA
Add a virtual text annotation to a Neovim buffer. Visual only — the buffer's actual content is unchanged and nothing is written to disk. Annotations stack; multiple calls accumulate.
file: path relative to Neovim's cwd (as shown in get_state buffers).
The buffer must already be open in Neovim; returns an error otherwise.
line: 1-indexed anchor line. Out-of-range values are clamped.
text: list of strings, one per virtual line. Must be non-empty.
When position is "eol", exactly one item is allowed.
position: where the annotation appears relative to the anchor line.
One of "eol" (after end of line), "above" (between previous and
anchor lines), or "below" (between anchor and next lines).
Defaults to "eol".
color: a Neovim highlight group name (e.g. "Comment",
"DiagnosticError") or a hex color (e.g. "#7a9ad4"). Defaults to
"Comment", which adapts to the user's colorscheme. Unknown names
(including bare color literals like "Red") return an error.
Use this for a single annotation. Use add_virtual_texts for
multiple annotations in one call. Use clear_virtual_texts to
remove all MCP virtual text from a buffer.
Returns {added: 1} on success, or {error} with a message on failure.
Inputs: file (required), line (required), text (required), color, +1 more.
add_virtual_textsA
Add multiple virtual text annotations to Neovim buffers in a single call. Visual only — buffer content is unchanged. Annotations stack; calling this adds more without removing previous ones.
items: a list of dicts. Each dict requires:
file: path relative to Neovim's cwd. Buffer must be open.
line: 1-indexed anchor line. Out-of-range values are clamped.
text: list of strings, one per virtual line. Non-empty. EOL position requires exactly one item. And optionally:
position: "eol" (default), "above", or "below".
color: hex color (e.g. "#7a9ad4") or Neovim highlight group name (e.g. "Comment", "DiagnosticError"). Defaults to "Comment". Unknown names (including bare color literals like "Red") return an error.
Use this when you need to add several annotations at once (possibly
across different files). Use add_virtual_text for a single
annotation. Use clear_virtual_texts to remove all MCP virtual
text from a buffer.
Returns a list of {added: 1} results in input order. Raises a
ValueError if any item is missing a required key. Iteration is
sequential: if item N fails validation or the manager raises,
items 0..N-1 have already been applied (call clear_virtual_texts
to roll back).
Example: [{"file": "foo.py", "line": 10, "text": ["this is the bug"]}, {"file": "foo.py", "line": 20, "text": ["note one", "note two"], "position": "above", "color": "DiagnosticInfo"}]
Inputs: items (required). Returns: result
clear_highlightsA
Remove all MCP highlights from a Neovim buffer. Only removes
highlights added by highlight_range or highlight_ranges — does
not affect syntax highlighting, LSP highlights, or other plugins.
Does not modify buffer content. Safe to call even if no highlights
are present (returns {cleared: true} either way).
file: path relative to Neovim's cwd (as shown in get_state buffers).
The buffer must already be open in Neovim; returns an error otherwise.
Use this to clean up highlights after an annotation workflow.
Use highlight_range or highlight_ranges to add highlights.
Inputs: file (required).
clear_virtual_textsA
Remove all MCP virtual text annotations from a Neovim buffer.
Only removes annotations added by add_virtual_text or
add_virtual_texts — does not affect highlights, LSP virtual
text, inlay hints, or other plugins. Does not modify buffer
content. Safe to call even if no annotations are present
(returns {cleared: true} either way).
file: path relative to Neovim's cwd (as shown in get_state buffers).
The buffer must already be open in Neovim; returns an error otherwise.
Use this to clean up after an annotation workflow. Use
add_virtual_text or add_virtual_texts to add annotations.
Inputs: file (required).
connectA
Connect to a running Neovim instance over its Unix socket or TCP address.
Call this before any other tool if the agent is not yet connected. Connection is persistent for the session; you only need to call it once unless you want to switch instances.
Called with no arguments: auto-connects when exactly one instance is running; returns a list of instances when multiple are found.
Optional selection (provide at most one):
index: pick from the listed instances (1-based).
socket_path: connect directly to a known Unix socket or host:port.
terminal_pid: find the Neovim instance whose process tree contains this PID (useful when Neovim runs inside a specific terminal).
Returns {connected, cwd, file} on success, or {error} with details on failure (e.g. no instances found, connection timeout, bad index).
Inputs: index, socket_path, terminal_pid.
find_and_replace_bufA
Find and replace text in a Neovim buffer. The edit happens in-memory and is fully undoable — nothing is written to disk until the user saves.
file: path relative to Neovim's cwd (as shown in get_state buffers).
old_string: the exact text to find. Must match exactly once in the
buffer; returns an error if not found or if it matches multiple
locations. Include surrounding lines to disambiguate.
new_string: the replacement text.
Creates the buffer if it doesn't already exist. Use this for targeted
edits. Use write_full_buf instead when replacing the entire buffer
content. Use read_full_buf or read_buf_range first if you need
to see the current content before editing.
Returns {start_line, lines_removed, lines_added, total_lines} on success, or {error} with a message on failure.
Inputs: file (required), new_string (required), old_string (required).
get_all_diagnosticsA
Get LSP diagnostics from all open buffers in Neovim. Read-only.
Use this for a project-wide overview of errors and warnings. Use
get_buf_diagnostics instead when you only need diagnostics for a
specific file — it is more focused and returns less data.
Returns a list of {file, line, col, severity, message, source}. severity is one of "error", "warning", "info", "hint". Returns an empty list when there are no diagnostics. Results depend on which LSP servers are attached and which buffers are loaded in Neovim.
Inputs: no named parameters.
get_buf_diagnosticsA
Get LSP diagnostics for a single Neovim buffer. Read-only.
file: path relative to Neovim's cwd (as shown in get_state buffers).
The buffer must already be open in Neovim; returns an error otherwise.
Use this when you need diagnostics for one specific file. Use
get_all_diagnostics instead for a project-wide overview.
Returns a list of {file, line, col, severity, message, source}. severity is one of "error", "warning", "info", "hint". Returns an empty list when the buffer has no diagnostics.
Inputs: file (required).
get_stateA
Full snapshot of the current Neovim session. Read-only — does not modify any editor state.
Use get_state_brief for quick orientation at the start of a turn.
Use this when you need the complete picture: all window details,
folds, marks, diagnostics summaries, highlights, virtual text, and
indent settings.
Returns: mode (normal/insert/visual/etc.), cwd, buffers (relative
paths of all listed buffers), modified_buffers, current_tab, tab_count,
and terminals — a list of open terminal buffers as {buf, name,
visible}, present only when at least one exists (targets for
send_to_terminal).
windows — list of visible windows (current tab only). The active window is always first, the alternate window (previous) is second. Each window entry contains: file (path relative to cwd), filetype, total_lines, modified, buftype ("file" for normal buffers, "terminal", etc.), line, col, indent: {expandtab, shiftwidth, tabstop}. Optional per-window fields (present when applicable):
role: "active" or "alternate".
context: numbered lines surrounding the cursor.
selection: {start_line, start_col, end_line, end_col} in visual modes.
folds: list of [start, end] closed fold ranges.
diagnostics_summary: {error, warning, info, hint} counts.
marks: list of {mark, line, col} for lowercase (a-z) buffer marks.
mcp_highlights: list of {start_line, end_line, color} for active highlights.
mcp_virtual_text: list of {line, position, lines, color} for active virtual text.
Inputs: no named parameters.
get_state_briefA
Lightweight snapshot of the Neovim session for quick orientation. Read-only — does not modify any editor state.
Use this when a turn depends on what the user is working on:
before reading or editing files, acting on the editor, or
answering about the current view. One call per turn is enough;
skip it for turns that don't touch the editor or files. Use
get_state instead when you need the full picture: all windows,
folds, marks, diagnostics summaries, highlights, virtual text, and
indent settings.
Returns: mode (normal/insert/visual/etc.), cwd, buffers (relative paths of all listed buffers), modified_buffers, and active_window: {file, filetype, total_lines, modified, buftype, line, col, context}. context is a short list of numbered lines around the cursor.
If an alternate window exists, also returns alternate_window with
the same fields. When terminal buffers exist, returns terminals — a
list of {buf, name, visible} (targets for send_to_terminal).
Inputs: no named parameters.
highlight_rangeA
Add a colored line highlight to a Neovim buffer. This is a visual annotation only — it does not modify buffer content and is not persisted to disk. Highlights stack; calling this multiple times adds more highlights without removing previous ones.
file: path relative to Neovim's cwd (as shown in get_state buffers).
The buffer must already be open in Neovim; returns an error otherwise.
start_line: first line to highlight (1-indexed, inclusive).
end_line: last line to highlight (1-indexed, inclusive). Out-of-range
values are clamped. If start_line > end_line they are swapped.
color: a hex color (e.g. "#3b4048") or a Neovim highlight group name
(e.g. "Comment", "DiagnosticError"). For groups, the resolved
foreground color becomes the line background — so highlights adapt
to the user's colorscheme. Defaults to "Comment". Unknown names
(including bare color literals like "Red") return an error.
Use this for a single highlight. Use highlight_ranges to apply
multiple highlights in one call. Use clear_highlights to remove
all highlights from a buffer.
Returns {highlighted} with the number of lines highlighted, or {error} with a message on failure.
Inputs: file (required), end_line (required), start_line (required), color.
highlight_rangesA
Add colored line highlights to one or more Neovim buffers in a single call. This is a visual annotation only — it does not modify buffer content and is not persisted to disk. Highlights stack; calling this adds more highlights without removing previous ones.
highlights: a list of dicts. Each dict requires:
file: path relative to Neovim's cwd (as shown in
get_state). The buffer must be open in Neovim.start_line: first line (1-indexed, inclusive).
end_line: last line (1-indexed, inclusive).
color (optional): hex color (e.g. "#5f3a3a") or Neovim highlight group name (e.g. "Comment", "DiagnosticError"). For groups, the resolved foreground color becomes the line background. Defaults to "Comment". Unknown names (including bare color literals like "Red") return an error. Out-of-range lines are clamped.
Use this when you need to highlight several ranges at once (possibly
across different files). Use highlight_range for a single range.
Use clear_highlights to remove all highlights from a buffer.
Returns a list of {highlighted} results in the same order as the input. Raises an error if any item is missing required keys.
Example: [{"file": "foo.py", "start_line": 1, "end_line": 3, "color": "DiagnosticError"}, {"file": "foo.py", "start_line": 10, "end_line": 12}]
Inputs: highlights (required). Returns: result
read_buf_rangeA
Read a specific line range from a Neovim buffer. Read-only; reads from Neovim's in-memory buffer, which may differ from the file on disk if there are unsaved changes.
file: path relative to Neovim's cwd (as shown in get_state buffers).
The buffer must already be open in Neovim; returns an error otherwise.
start_line: first line to read (1-indexed, inclusive).
end_line: last line to read (1-indexed, inclusive). Out-of-range
values are clamped to the buffer bounds. If start_line > end_line
they are swapped automatically.
Use this when you only need a section of a file. Use read_full_buf
instead when you need the entire buffer.
Returns {lines, total_lines}. lines is a list of strings, each prefixed with its 1-based line number (e.g. "10: some code").
Inputs: file (required), end_line (required), start_line (required).
read_full_bufA
Read the full content of a Neovim buffer. Read-only; reads from Neovim's in-memory buffer, which may differ from the file on disk if there are unsaved changes.
file: path relative to Neovim's cwd (as shown in get_state buffers).
The buffer must already be open in Neovim; returns an error otherwise.
Use this when you need to see the entire file. Use read_buf_range
instead when you only need a specific section — it returns less data.
Returns {lines, total_lines}. lines is a list of strings, each prefixed with its 1-based line number (e.g. "1: first line").
Inputs: file (required).
send_commandA
Run one or more Vim ex commands in Neovim. This is a mutation tool — commands can modify buffers, files on disk, windows, and editor state.
command: a single command string or a list of strings, without the leading ':'. E.g. "w", "e src/main.py", "42", "wincmd v", "lua vim.print(...)", or ["wincmd p", "e file.py", "wincmd p"].
Use this for editor operations that don't have a dedicated tool
(e.g. saving, opening files, splitting windows, setting options).
Use send_keys instead when you need normal-mode motions or
operator sequences. Use find_and_replace_buf or write_full_buf
for buffer text edits — they are safer and provide undo.
Returns {output} with the command's captured output, or {error} if the command failed. When given a list, returns a list of results in the same order; execution stops on the first error.
Inputs: command (required). Returns: result
send_keysA
Send raw keystrokes to Neovim as if typed by the user. This is a mutation tool — keystrokes can modify buffers, change mode, and trigger editor actions.
keys: a string of Vim keystrokes. Esc is prepended automatically, so input always begins in normal mode. Multi-mode sequences must be sent in a single call (e.g. "17GVG", not "17GV" then "G"). Use Vim notation for special keys (e.g. "", "v", "").
Use this for normal-mode motions, visual selections, or operator
sequences. Use send_command for ex commands, and
find_and_replace_buf or write_full_buf for text edits — they
are safer and provide structured results.
Returns {sent} confirming the keys that were dispatched. Keystrokes are fire-and-forget; errors from the resulting Vim actions are not captured in the return value.
Inputs: keys (required).
send_to_terminalA
Type text into a terminal buffer's running program (usually a shell) by writing to its job channel. This is a mutation tool — the text reaches the program's stdin as if typed, but is not executed unless submit is true.
text: the text to send, raw. In most shells an embedded newline acts
like pressing Enter, so multi-line text may execute line by line.
When submit is false, trailing newlines are stripped so nothing
runs by accident.
terminal: which terminal to target — a buffer number or buffer name,
as listed under terminals in get_state / get_state_brief.
Names match exactly first, then by unique substring. Omit it when
exactly one terminal exists; with several open, omitting it
returns an error listing them.
submit: false (default) leaves the text at the prompt for the user
to review and press Enter. true appends a carriage return so the
program executes it immediately. NEVER pass submit=true unless
the user has explicitly asked for the command to be run — "put",
"paste", "type", or "prepare" a command always means
submit=false. Suggesting a command yourself is not permission to
run it. When in doubt, use submit=false and let the user press
Enter.
Use this whenever text needs to go into a terminal. It works
regardless of focus, mode, or visibility and never moves the user's
cursor — unlike send_keys, which requires focusing the terminal
and juggling modes. Terminal buffers cannot be edited with the
buffer tools.
Returns {sent, terminal, buf, submitted} on success — sent is the
byte count actually written. On failure returns {error}, including
a terminals list when the target was missing or ambiguous.
Inputs: text (required), submit, terminal.
write_full_bufA
Replace the entire content of a Neovim buffer. The edit happens in-memory and is fully undoable — nothing is written to disk until the user saves.
file: path relative to Neovim's cwd (as shown in get_state buffers).
content: the full new text for the buffer.
Creates the buffer if it doesn't already exist. Use this when you
need to rewrite the whole file. Use find_and_replace_buf instead
for targeted edits that preserve surrounding content.
Returns {total_lines} with the new line count.
Inputs: file (required), content (required).
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 18 tools
Each tool targets a distinct resource+action, and descriptions explicitly cross-reference siblings (get_state vs get_state_brief, read_buf_range vs read_full_buf, send_command vs send_keys vs send_to_terminal). The singular/plural annotation pairs (highlight_range/highlight_ranges, add_virtual_text/add_virtual_texts) are clearly differentiated by scope. No meaningful overlap remains.
Consistent snake_case verb_noun (or verb_noun_qualifier) pattern throughout: get_state_brief, read_buf_range, send_command, find_and_replace_buf, clear_virtual_texts. The lone bare 'connect' is a natural exception that breaks no pattern. No mixing of conventions.
18 tools is slightly heavy but each earns its place by covering a genuinely broad editor surface (state, reads, edits, commands, terminals, diagnostics, annotations). The sing/plural annotation variants could arguably be collapsed, but the scoping is reasonable for a full Neovim integration.
Strong coverage of state inspection, buffer reads/writes, ex/keystroke/terminal input, diagnostics, and annotation workflows with cleanup tools. Minor gaps exist (no undo/redo, search/navigate, or buffer-close tools), but agents can reach these via send_command.
Maintenance
Related MCP Connectors
Operate Linux, macOS and Windows from your LLM. Every action runs through an auditable allowlist.
- DNS-DATA RemoteDeprecatedcom.dns-data
Connect AI assistants to authorized Windows and macOS devices for files, commands, and management.
Use your own Windows, Mac or Linux computer from ChatGPT, Claude, Cursor or Gemini CLI: run commands, read, write and search files, run long processes. Your computer only makes an outgoing connection (no open ports or VPN). Read-only mode, allowed folders, blocked commands and an action log keep you in control. Free plan available.
Connect AI assistants to your approved computer for files, commands, browser and desktop tasks.
Related MCP Servers
- AlicenseBqualityDmaintenanceLeverages Vim's native text editing commands and workflows, which Claude already understands, to create a lightweight code assistance layer.1999 npm324MIT
- AlicenseBqualityDmaintenanceAn MCP server that enables AI agents to control Neovim instances running in tmux sessions.12MIT
- AlicenseAqualityDmaintenanceMake Neovim feel like Cursor. This MCP server gives an agent full control over the Neovim session it is running inside, including buffers, windows, diagnostics, LSP language intelligence, and terminals.23MIT
- AlicenseNot gradedqualityBmaintenanceMCP server bridging tool calls to Neovim editor actions via RPC. Enables AI agents to open files, run Lua, manage quickfix lists, fetch diagnostics, and send notifications.1GPL 2.0