Crates.io | nvim-mcp |
lib.rs | nvim-mcp |
version | 0.5.0 |
created_at | 2025-08-08 14:49:48.616102+00 |
updated_at | 2025-08-20 13:52:36.78803+00 |
description | MCP server for Neovim |
homepage | https://github.com/linw1995/nvim-mcp#readme |
repository | https://github.com/linw1995/nvim-mcp |
max_upload_size | |
id | 1786867 |
size | 466,633 |
A Model Context Protocol (MCP) server that provides seamless integration with Neovim instances, enabling AI assistants to interact with your editor through connections and access diagnostic information via structured resources. Supports both stdio and HTTP server transport modes for different integration scenarios.
cargo install nvim-mcp
nix profile install github:linw1995/nvim-mcp#nvim-mcp
git clone https://github.com/linw1995/nvim-mcp.git && cd nvim-mcp
cargo install --path .
# Start as stdio MCP server (default, manual connection mode)
nvim-mcp
# Auto-connect to current project Neovim instances
nvim-mcp --connect auto
# Connect to specific target (TCP address or socket path)
nvim-mcp --connect 127.0.0.1:6666
nvim-mcp --connect /tmp/nvim.sock
# With custom logging
nvim-mcp --log-file ./nvim-mcp.log --log-level debug
# HTTP server mode with auto-connection
nvim-mcp --http-port 8080 --connect auto
# HTTP server mode with custom bind address
nvim-mcp --http-port 8080 --http-host 0.0.0.0
--connect <MODE>
: Connection mode (default: manual)
manual
: Traditional workflow using get_targets and connect toolsauto
: Automatically connect to all project-associated Neovim instances127.0.0.1:6666
) or absolute socket path--log-file <PATH>
: Path to log file (defaults to stderr)--log-level <LEVEL>
: Log level (trace, debug, info, warn, error;
defaults to info)--http-port <PORT>
: Enable HTTP server mode on the specified port--http-host <HOST>
: HTTP server bind address (defaults to 127.0.0.1)With a plugin manager like lazy.nvim
:
return {
"linw1995/nvim-mcp",
-- install the mcp server binary automatically
-- build = "cargo install --path .",
build = [[
nix build .#nvim-mcp
nix profile remove nvim-mcp
nix profile install .#nvim-mcp
]],
opts = {},
}
This plugin automatically creates a Unix socket/pipe for MCP connections.
Start Neovim with TCP listening:
nvim --listen 127.0.0.1:6666
Or add to your Neovim config:
vim.fn.serverstart("127.0.0.1:6666")
Once both the MCP server and Neovim are running, here are the available workflows:
When using --connect auto
, the server automatically discovers and connects to
Neovim instances associated with your current project:
Start server with auto-connect:
nvim-mcp --connect auto
Server automatically:
connection_id
sUse connection-aware tools directly:
connection_id
s for connected instanceslist_buffers
, buffer_diagnostics
, etc. with these IDsFor direct connection to a known target:
Connect to specific target:
# TCP connection
nvim-mcp --connect 127.0.0.1:6666
# Unix socket connection
nvim-mcp --connect /tmp/nvim.sock
Server automatically connects and reports the connection_id
Use connection-aware tools with the reported ID
For traditional discovery-based workflow:
get_targets
tool to list available socket pathsconnect
tool with a socket path from step 1connection_id
for subsequent operationslist_buffers
, buffer_diagnostics
, etc. with your
connection_id
nvim-connections://
or
nvim-diagnostics://{connection_id}/workspace
disconnect
tool when completely doneThe server supports HTTP transport mode for web-based integrations and applications that cannot use stdio transport. This is useful for web applications, browser extensions, or other HTTP-based MCP clients.
# Start HTTP server on default localhost:8080
nvim-mcp --http-port 8080
# Bind to all interfaces
nvim-mcp --http-port 8080 --http-host 0.0.0.0
# With custom logging
nvim-mcp --http-port 8080 --log-file ./nvim-mcp.log --log-level debug
When using HTTP transport, MCP clients should connect to the HTTP endpoint instead of stdio. The exact integration depends on your MCP client library, but generally involves:
http://localhost:8080
)The HTTP transport maintains full compatibility with all existing MCP tools and resources - only the transport layer changes.
The server provides 23 MCP tools for interacting with Neovim:
get_targets
: Discover available Neovim targets
connect
: Connect via Unix socket/named pipe
target
(string) - Socket path from get_targetsconnection_id
(string) - Deterministic connection identifierconnect_tcp
: Connect via TCP
target
(string) - TCP address (e.g., "127.0.0.1:6666")connection_id
(string) - Deterministic connection identifierdisconnect
: Disconnect from specific Neovim instance
connection_id
(string) - Connection identifier to disconnectAll tools below require a connection_id
parameter from the connection
establishment phase:
list_buffers
: List all open buffers with names and line counts
connection_id
(string) - Target Neovim connectionbuffer_diagnostics
: Get diagnostics for a specific buffer
connection_id
(string), id
(number) - Buffer IDlsp_clients
: Get workspace LSP clients
connection_id
(string) - Target Neovim connectionlsp_workspace_symbols
: Search workspace symbols by query
connection_id
(string), lsp_client_name
(string), query
(string) - Search query for filtering symbolslsp_code_actions
: Get LSP code actions with universal document identification
connection_id
(string), document
(DocumentIdentifier),
lsp_client_name
(string), start_line
(number), start_character
(number),
end_line
(number), end_character
(number) (all positions are 0-indexed)lsp_hover
: Get LSP hover information with universal document identification
connection_id
(string), document
(DocumentIdentifier),
lsp_client_name
(string), line
(number), character
(number)
(all positions are 0-indexed)lsp_document_symbols
: Get document symbols with universal document identification
connection_id
(string), document
(DocumentIdentifier),
lsp_client_name
(string)lsp_references
: Get LSP references with universal document identification
connection_id
(string), document
(DocumentIdentifier),
lsp_client_name
(string), line
(number), character
(number),
include_declaration
(boolean)lsp_resolve_code_action
: Resolve code actions with incomplete data
connection_id
(string), lsp_client_name
(string),
code_action
(CodeAction object) - Code action to resolvelsp_apply_edit
: Apply workspace edits using Neovim's LSP utility functions
connection_id
(string), lsp_client_name
(string),
workspace_edit
(WorkspaceEdit object) - Workspace edit to applylsp_definition
: Get LSP definition with universal document identification
connection_id
(string), document
(DocumentIdentifier),
lsp_client_name
(string), line
(number), character
(number)
(all positions are 0-indexed)lsp_type_definition
: Get LSP type definition with universal document identification
connection_id
(string), document
(DocumentIdentifier),
lsp_client_name
(string), line
(number), character
(number)
(all positions are 0-indexed)lsp_implementations
: Get LSP implementations with universal document identification
connection_id
(string), document
(DocumentIdentifier),
lsp_client_name
(string), line
(number), character
(number)
(all positions are 0-indexed)lsp_declaration
: Get LSP declaration with universal document identification
connection_id
(string), document
(DocumentIdentifier),
lsp_client_name
(string), line
(number), character
(number)
(all positions are 0-indexed)lsp_rename
: Rename symbol across workspace using LSP
connection_id
(string), document
(DocumentIdentifier),
lsp_client_name
(string), line
(number), character
(number),
new_name
(string), prepare_first
(boolean, optional)
(all positions are 0-indexed)lsp_formatting
: Format document using LSP
connection_id
(string), document
(DocumentIdentifier),
lsp_client_name
(string), options
(FormattingOptions),
apply_edits
(boolean, optional) (all positions are 0-indexed)lsp_range_formatting
: Format a specific range in a document using LSP
connection_id
(string), document
(DocumentIdentifier),
lsp_client_name
(string), start_line
(number), start_character
(number),
end_line
(number), end_character
(number), options
(FormattingOptions),
apply_edits
(boolean, optional) (all positions are 0-indexed)lsp_organize_imports
: Sort and organize imports using LSP
connection_id
(string), document
(DocumentIdentifier),
lsp_client_name
(string), apply_edits
(boolean, optional)The document
parameter in the universal LSP tools accepts a DocumentIdentifier
which can reference documents in three ways:
DocumentIdentifier Enum:
{"buffer_id": 123}
{"project_relative_path": "src/main.rs"}
{"absolute_path": "/home/user/project/src/main.rs"}
This system enables LSP operations on files that may not be open in Neovim buffers, providing enhanced flexibility for code analysis and navigation.
exec_lua
: Execute Lua code in Neovim
connection_id
(string), code
(string) - Lua code to executeThe server now supports the full LSP code action lifecycle:
lsp_code_actions
to retrieve available
code actions for a specific rangelsp_resolve_code_action
to resolve any code
action that may have incomplete datalsp_apply_edit
to apply the workspace edit from
the resolved code actionExample Workflow:
1. lsp_code_actions → Get available actions
2. lsp_resolve_code_action → Resolve incomplete action data
3. lsp_apply_edit → Apply the workspace edit to files
This enables AI assistants to perform complete code refactoring, quick fixes,
and other LSP-powered transformations. The implementation uses Neovim's native
vim.lsp.util.apply_workspace_edit()
function with proper position encoding
handling, ensuring reliable and accurate file modifications.
Access diagnostic and connection information through structured URI schemes:
nvim-connections://
: List all active Neovim connections
id
and target
informationnvim-tools://
: Overview of all tools and their connection mappings
nvim-tools://{connection_id}
: List of tools available for a specific connection
Note: Tool registration resources are experimental and may change in future versions.
Diagnostic resources use connection-specific URIs via the
nvim-diagnostics://
scheme:
nvim-diagnostics://{connection_id}/workspace
: All diagnostic messages
across workspace for specific connectionnvim-diagnostics://{connection_id}/buffer/{buffer_id}
: Diagnostics for
specific buffer on specific connection{
"method": "resources/read",
"params": {
"uri": "nvim-connections://"
}
}
{
"method": "resources/read",
"params": {
"uri": "nvim-diagnostics://abc123def456/workspace"
}
}
{
"method": "resources/read",
"params": {
"uri": "nvim-diagnostics://abc123def456/buffer/1"
}
}
All diagnostic resources return structured JSON with diagnostic information including severity levels, messages, file paths, and line/column positions. Connection IDs are deterministic BLAKE3 hashes of the target string for consistent identification across sessions.
The server supports managing multiple concurrent Neovim instances through a multi-connection architecture with several key benefits:
get_targets
to find available Neovim socket pathsconnect
or connect_tcp
to establish connection and
get connection_id
connection_id
parameterconnection_id
in URI patternsdisconnect
when done (connections persist
until explicitly closed)This project uses Nix flakes for reproducible development environments.
# Enter development shell
nix develop .
# Auto-activate with direnv (optional)
echo 'use flake' >.envrc
# Run all tests
cargo test -- --show-output
# Skip integration tests (which require Neovim)
cargo test -- --skip=integration_tests --show-output
# In Nix environment
nix develop . --command cargo test -- --show-output
Note: If already in a Nix shell, omit the nix develop . --command
prefix.
# Build debug version
cargo build
# Build and run debug version
cargo run
# Build and run release version
cargo run --release
# Build and run with custom logging
cargo run -- --log-file ./debug.log --log-level debug
# Build and run with HTTP server mode
cargo run -- --http-port 8080
# Using Nix
nix run .
For local development with lazy.nvim
, create .lazy.lua
in the project root:
return {
{
"linw1995/nvim-mcp",
dir = ".",
opts = {},
},
}