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

Claude and Cursor collaborating in one Neovim instance

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. Run ./config/generate-configs.sh and pick your tool (Cursor, Claude Code, or Codex).
  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.

Setup Test

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.3.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.3-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nvim_mcp-0.5.3.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.3.tar.gz
Algorithm Hash digest
SHA256 397df1a2f87dcdd698e2c8900baf603b44b4ac43b393afec4f0de3f4b17cbae4
MD5 28c8dc78de46e4780c05e2f1ff5446ff
BLAKE2b-256 3a256a68c4227b546e9af92b9ed00cae36aa0c68a26fe999a83c01a5636aacfc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: nvim_mcp-0.5.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d428b2c3e75707e0bfbc8d558d888bd019c7c7b935b4d5ab5605b0fe3ff43481
MD5 42202c06448f69d6babec14ec72fcb34
BLAKE2b-256 b231234ee2e38ae28c2871d7e5e2d851ea70bad5e85748066f5d3c169c77f63c

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