mcpserver.nvim

calebfroese/mcpserver.nvim

3.2

If you are the rightful owner of mcpserver.nvim and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

A Neovim plugin that implements an MCP (Model Context Protocol) server, allowing external MCP clients to interact with Neovim through a Unix socket.

Tools
1
Resources
0
Prompts
0

mcpserver.nvim

A Neovim plugin that implements an MCP (Model Context Protocol) server, allowing external MCP clients to interact with Neovim through a Unix socket.

Features

  • get_buffer_content: Fetch the contents of the current buffer

Installation

Using lazy.nvim:

{
  dir = "/path/to/mcpserver.nvim", -- Use your local path
  -- Server starts automatically on VimEnter
}

Usage

Neovim Plugin

Manual Control

Start the MCP server:

:MCPServerStart

Stop the MCP server:

:MCPServerStop
Get Socket Path
local mcpserver = require('mcpserver')
local socket_path = mcpserver.get_socket_path()
print(socket_path) -- e.g., "/tmp/nvim-mcp-server-12345.sock"
Socket Location

The server creates a unique Unix socket at /tmp/nvim-mcp-server-<PID>.sock where <PID> is the Neovim process ID. This allows multiple Neovim instances to run MCP servers simultaneously.

Standalone MCP Server

For use with external MCP clients that communicate via stdio:

# Auto-detect running Neovim instance
lua standalone.lua

# Specify Neovim socket path
lua standalone.lua /tmp/nvim-mcp-server-12345.sock

The standalone server:

  • Communicates via stdio (JSON-RPC over stdin/stdout)
  • Auto-detects running Neovim MCP server sockets
  • Forwards requests to the Neovim instance
  • Works with any MCP client that supports stdio transport

Available Tools

get_buffer_content

Returns JSON with:

  • filename: Path to the current buffer file
  • content: Full text content of the buffer
  • line_count: Number of lines in the buffer

MCP Client Usage

Direct Socket Connection

Connect to the Unix socket at /tmp/nvim-mcp-server-<PID>.sock and use standard MCP protocol:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "get_buffer_content",
    "arguments": {}
  }
}

Stdio Connection

Use the standalone server for stdio-based MCP clients:

echo '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"get_buffer_content","arguments":{}}}' | lua standalone.lua

Development

The plugin structure:

  • lua/mcpserver/init.lua: Core MCP server implementation
  • lua/mcpserver/tools.lua: Tool implementations
  • plugin/mcpserver.lua: Plugin setup and commands
  • standalone.lua: Standalone MCP server for stdio communication

Requirements

  • Neovim with Lua support
  • For standalone mode: netcat (nc) for Unix socket communication