get_current_buffer
Retrieve the currently active Neovim buffer content to enable real-time editor awareness and direct in-editor updates through MCP integration.
Instructions
Get the currently active buffer in Neovim
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- lib/nvim-operations.js:67-90 (handler)Core handler function that connects to a Neovim instance in the current directory and retrieves the path and content of the currently active buffer.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:123-130 (registration)Registration of the 'get_current_buffer' tool in the MCP server's list of tools, including its name, description, and input schema (no parameters required).{ name: "get_current_buffer", description: "Get the currently active buffer in Neovim", inputSchema: { type: "object", properties: {}, }, },
- index.js:227-248 (handler)Dispatch handler in the MCP CallToolRequestSchema that invokes getCurrentBuffer() and formats the response as MCP tool content.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}`, }, ], }; }