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.

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.0.tar.gz (12.6 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.0-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nvim_mcp-0.5.0.tar.gz
  • Upload date:
  • Size: 12.6 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.0.tar.gz
Algorithm Hash digest
SHA256 e3762829bf6f3768bcebd0c368107452aa91f0c8cc5f2d1d57ab01f05b3aa8c7
MD5 da3b6d96723618e4e8b81e2df5b128ce
BLAKE2b-256 ab4d2ecca436e26515186a38e26eeddffeb68c70c303c86681f9e4fa9fa29fa5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: nvim_mcp-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 13.8 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1211b3a71c37746ad6141abdf7ce5f3da74c39c64b9be32255d0c27cdd854593
MD5 b16f175c13d508023878381385e9124b
BLAKE2b-256 beee9f8c1b7c0682a663d45f787f1f7768a106984baf802630974dff0a707bbe

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