Skip to main content
Glama

get_current_buffer

Retrieve the currently active Neovim buffer content for real-time editing and Claude integration.

Instructions

Get the currently active buffer in Neovim

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Core handler function that connects to Neovim instances in the current directory, retrieves the current buffer's path and content.
    export async function getCurrentBuffer() { const instances = await getNvimInstancesInCwd(); if (instances.length === 0) { return null; } // Use the first instance found const { nvim } = instances[0]; try { const currentBuf = await nvim.buffer; const bufName = await currentBuf.name; const lines = await currentBuf.lines; const content = lines.join("\n"); return { path: bufName, content, }; } catch (error) { throw error; } }
  • index.js:122-130 (registration)
    Registers the 'get_current_buffer' tool in the ListToolsRequestSchema handler, including name, description, and empty input schema.
    { name: "get_current_buffer", description: "Get the currently active buffer in Neovim", inputSchema: { type: "object", properties: {}, }, }, {
  • Dispatches the tool call for 'get_current_buffer' in the CallToolRequestSchema handler, invokes getCurrentBuffer, and formats the MCP response.
    if (name === "get_current_buffer") { const current = await getCurrentBuffer(); if (!current) { return { content: [ { type: "text", text: "No Neovim instance found in current directory", }, ], }; } return { content: [ { type: "text", text: `Current buffer: ${current.path}\n\n${current.content}`, }, ], }; }
  • Helper function to find and connect to Neovim instances running in the current working directory, used by getCurrentBuffer.
    export async function getNvimInstancesInCwd() { const cwd = process.cwd(); const sockets = await findNvimSockets(); const instances = []; for (const socketPath of sockets) { try { const nvim = attach({ socket: socketPath }); const instanceCwd = await nvim.call("getcwd", []); // Check if this nvim instance is in our current directory if (instanceCwd === cwd || instanceCwd.startsWith(cwd + "/")) { instances.push({ socket: socketPath, cwd: instanceCwd, nvim, }); } // Note: We don't quit non-matching instances, just skip them } catch (error) { // Failed to connect to this socket, skip it continue; } } return instances; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/laktek/nvim-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server