Skip to main content

MCP server for AI-assisted control of Neovim via msgpack-RPC

Project description

nvim-mcp

PyPI

nvim-mcp is an MCP server that gives AI assistants (Cursor, Claude, and others) full access to a running Neovim session. The assistant sees what you see — cursor position, visible code, window layout, visual selections — and can send keystrokes, run commands, or read buffer contents.

It talks to Neovim directly over its default Unix socket using msgpack-RPC and discovers running instances automatically.

Demos

Using nvim-mcp with a terminal inside Neovim

Using nvim-mcp in Cursor

Using nvim-mcp across two terminals

Setup

  1. Install uv if you don't have it: curl -LsSf https://astral.sh/uv/install.sh | sh
  2. Register the MCP server with your client — example for Cursor (.cursor/mcp.json):
{
  "mcpServers": {
    "nvim-mcp": {
      "command": "uvx",
      "args": ["nvim-mcp"]
    }
  }
}

See config/README.md for other clients (Claude CLI, Codex, etc.) or to run from a local clone.

  1. Add agent rules — registering the server gives the assistant the tools, but a rule file teaches it when and how to use them. Copy one from config/ into your project (AGENTS.md for Claude Code / Codex / others, or run ./config/generate-mdc.sh for Cursor).
  2. Start Neovim — it listens on an RPC socket by default.

Tools

Tool Purpose
get_state Snapshot of the session: mode, cwd, buffers, and per-window file, cursor, context, folds, diagnostics.
get_all_diagnostics LSP diagnostics from all buffers.
get_buf_diagnostics LSP diagnostics for a single buffer.
find_and_replace_buf Find and replace text in a buffer. old_string must match exactly once.
write_full_buf Set the entire content of a buffer.
read_full_buf Read an entire buffer.
read_buf_range Read a line range from a buffer. Takes start_line and end_line (1-indexed).
send_command Run ex commands (no leading :). Single string or list.
send_keys Send keystrokes. Esc is prepended automatically.
highlight_range Highlight lines with colored extmarks. Takes file, start_line, end_line, color.
highlight_ranges Highlight multiple ranges at once with different colors.
clear_highlights Remove all MCP highlights from a buffer.
connect Connect to a Neovim instance.

Multi-instance

One Neovim instance running? Tools auto-connect. Multiple? connect lists them — pick by index, socket_path, or terminal_pid. Set NVIM_SOCKET_PATH to skip discovery entirely.

Environment

Variable Default Description
NVIM_SOCKET_PATH (auto-discover) Skip discovery; connect directly to this socket.
NVIM_MCP_ACTIVE_CONTEXT_LINES 20 Lines above/below cursor in the active window. Set to 0 to disable.
NVIM_MCP_INACTIVE_CONTEXT_LINES 20 Lines above/below cursor in inactive windows. Set to 0 to disable.

Clearing highlights

clear_highlights clears a buffer via the MCP tool, but you can also clear them directly in Neovim. Add this to your config:

vim.api.nvim_create_user_command('McpClearHighlights', function()
  local ns = vim.api.nvim_create_namespace('mcp_highlight')
  for _, b in ipairs(vim.api.nvim_list_bufs()) do
    vim.api.nvim_buf_clear_namespace(b, ns, 0, -1)
  end
end, {})

Then :McpClearHighlights removes all MCP highlights from every buffer.

Demo

Open a file in Neovim, then paste this into your AI assistant:

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.

Requirements

  • Python ≥ 3.10
  • Linux
  • Neovim ≥ 0.11

License

MIT — see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nvim_mcp-0.5.2.tar.gz (13.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nvim_mcp-0.5.2-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

Details for the file nvim_mcp-0.5.2.tar.gz.

File metadata

  • Download URL: nvim_mcp-0.5.2.tar.gz
  • Upload date:
  • Size: 13.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"25.10","id":"questing","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for nvim_mcp-0.5.2.tar.gz
Algorithm Hash digest
SHA256 9c8fdeafcfd49e9a70b6910427cb094e68cdc68300339910e6bc8d3e7df1c63b
MD5 04a27fd86523037f850dd62cdbbe24f4
BLAKE2b-256 6e876eea1c2e794961c972fd64716363c1aed94afca3bc70d2ad1c7bf5b2461d

See more details on using hashes here.

File details

Details for the file nvim_mcp-0.5.2-py3-none-any.whl.

File metadata

  • Download URL: nvim_mcp-0.5.2-py3-none-any.whl
  • Upload date:
  • Size: 14.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"25.10","id":"questing","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for nvim_mcp-0.5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 761f2c74f99040a5e3877864467769d788dbc49a5c42b09c350fab726abb31db
MD5 9327306537d094786f6c2e39a00b0ff8
BLAKE2b-256 9d881a4f727a9c4de476eb17d06f7a1d2a8d8b8cf4482b0f4c3adeb759929056

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page