Skip to main content
Glama

Neovim MCP 服务器

这是 Claude Desktop(或任何客户端)与 Neovim 之间使用模型上下文协议 (MCP) 和官方 neovim/node-client JavaScript 库进行概念验证集成的成果。该服务器利用 Vim 原生的文本编辑命令和工作流程(Claude 已理解这些命令和工作流程),创建轻量级代码或通用的 AI 文本辅助层。

特征

  • 如果您在启动 nvim 时公开套接字文件(例如--listen /tmp/nvim ),则连接到您的 nvim 实例

  • 查看当前缓冲区

  • 获取光标位置、模式、文件名

  • 通过 vim 运行 vim 命令和可选的 shell 命令

  • 可以使用插入或替换进行编辑

Related MCP server: loreto-mcp

API

资源

  • nvim://session :当前 neovim 文本编辑器会话

  • nvim://buffers :当前 Neovim 会话中所有打开的缓冲区的列表,其中包含修改状态、语法和窗口 ID 等元数据

工具

  • vim_buffer

    • 显示当前 VIM 文本编辑器缓冲区的行号

    • 输入filename (字符串)

    • 忽略文件名,返回包含当前活动缓冲区内容的编号行字符串

  • vim命令

    • 向 VIM 发送命令以进行导航、点编辑和行删除

    • 输入command (字符串)

    • 运行首先通过nvim.replaceTermcodes传递的 vim 命令。多个命令之间用换行符分隔即可运行。

    • 发生错误时,返回'nvim:errmsg'内容

  • vim_status

    • 获取 VIM 编辑器的状态

    • 状态包含光标位置、模式、文件名、视觉选择、窗口布局、当前选项卡、标记、寄存器和工作目录

  • vim_edit

    • 在 VIM 编辑器中使用 insert、replace 或 replaceAll 编辑行

    • 输入startLine (数字), mode ( "insert" | "replace" | "replaceAll" ), lines (字符串)

    • 插入将在 startLine 处插入行

    • replace 将替换从 startLine 开始的行

    • replaceAll 将替换整个缓冲区内容

  • vim_window

    • 操作 Neovim 窗口(拆分、vsplit、关闭、导航)

    • 输入command (字符串:“split”、“vsplit”、“only”、“close”、“wincmd h/j/k/l”)

    • 允许窗口管理操作

  • vim_mark

    • 在特定位置设置标记

    • 输入mark (字符串:az)、 line (数字)、 column (数字)

    • 在指定位置设置命名标记

  • vim_register

    • 设置寄存器的内容

    • 输入register (字符串:az或“), content (字符串)

    • 管理寄存器内容

  • vim_visual

    • 进行视觉选择

    • 输入startLine (数字)、 startColumn (数字)、 endLine (数字)、 endColumn (数字)

    • 创建视觉模式选择

使用这套简单的工具,Claude 可以窥视您的 neovim 会话来回答问题以及对缓冲区进行编辑。

限制

  • 这是对模型上下文协议进行快速概念验证的实验。使用风险自负。

  • 可能无法与自定义 neovim 配置很好地交互!

  • 错误处理可能会更好。

  • 有时 Claude 无法正确输入 vim 命令。

配置

环境变量

  • ALLOW_SHELL_COMMANDS :设置为 true 以允许执行 shell 命令(例如!ls )。出于安全考虑,默认为 false 。

  • NVIM_SOCKET_PATH :设置为 Neovim 套接字的路径。如果未指定,则默认为 '/tmp/nvim'。

与 Claude Desktop 一起使用

将其添加到您的claude_desktop_config.json中:

{
  "mcpServers": {
    "MCP Neovim Server": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-neovim-server"
      ],
      "env": {
        "ALLOW_SHELL_COMMANDS": "true",
        "NVIM_SOCKET_PATH": "/tmp/nvim"
      }
    }
  }
}

执照

此 MCP 服务器采用 MIT 许可证。这意味着您可以自由使用、修改和分发该软件,但须遵守 MIT 许可证的条款和条件。更多详情,请参阅项目仓库中的 LICENSE 文件。

Available Tools

19 tools
vim_bufferC

Get buffer contents with line numbers

Inputs: filename.

vim_buffer_saveC

Save current buffer or save to specific filename

Inputs: filename.

vim_buffer_switchC

Switch between buffers by name or number

Inputs: identifier (required).

vim_commandC

Execute Vim commands with optional shell command support

Inputs: command (required).

vim_editC

Edit buffer content using insert, replace, or replaceAll modes

Inputs: lines (required), mode (required), startLine (required).

vim_file_openC

Open files into new buffers

Inputs: filename (required).

vim_foldC

Manage code folding: create, open, close, and toggle folds

Inputs: action (required), endLine, startLine.

vim_grepC

Project-wide search using vimgrep with quickfix list

Inputs: pattern (required), filePattern.

vim_healthB

Check Neovim connection health

Inputs: no named parameters.

vim_jumpC

Navigate Neovim jump list: go back, forward, or list jumps

Inputs: direction (required).

vim_macroC

Record, stop, and play Neovim macros

Inputs: action (required), count, register.

vim_markB

Set named marks at specific positions in the buffer

Inputs: column (required), line (required), mark (required).

vim_registerC

Manage Neovim register contents

Inputs: content (required), register (required).

vim_search_replaceC

Find and replace with global, case-insensitive, and confirm options

Inputs: pattern (required), replacement (required), confirm, global, +1 more.

vim_statusA

Get comprehensive Neovim status including cursor position, mode, marks, and registers

Inputs: no named parameters.

vim_tabC

Manage Neovim tabs: create, close, and navigate between tabs

Inputs: action (required), filename.

vim_visualC

Create visual mode selections in the buffer

Inputs: endColumn (required), endLine (required), startColumn (required), startLine (required).

vim_windowB

Manage Neovim windows: split, close, and navigate between windows

Inputs: command (required).

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3.4/5.0

    Scored across 19 tools

    Disambiguation5/5

    Each tool has a clearly distinct purpose targeting specific Neovim operations like buffer management, editing, navigation, and system control. There is no overlap or ambiguity; for example, vim_search handles searching within a buffer while vim_grep handles project-wide searches, and vim_buffer_switch is distinct from vim_tab or vim_window for navigation.

    Naming Consistency5/5

    All tools follow a consistent 'vim_' prefix with descriptive snake_case names that clearly indicate their function, such as vim_buffer_save, vim_command, and vim_search_replace. This uniform pattern makes the tool set predictable and easy to understand, with no deviations in style or structure.

    Tool Count4/5

    With 19 tools, the count is slightly high but reasonable for covering the broad scope of Neovim operations, including editing, navigation, file management, and system health. It avoids being excessive by focusing on core functionalities without redundant tools, though it might feel heavy compared to simpler servers.

    Completeness5/5

    The tool set provides comprehensive coverage of Neovim's core features, including CRUD-like operations for buffers, files, and content, as well as navigation, search, macros, marks, and system status. There are no obvious gaps; it supports full lifecycle management from opening files to editing, saving, and navigating, ensuring agents can handle typical workflows without dead ends.

    Maintenance

    ActivityNo data
    ResponsivenessOutdated data

    Related MCP Connectors

    Related MCP Servers