get_buffer_content
Retrieve the content of a Neovim buffer using its file path to enable real-time editor awareness and content access.
Instructions
Get the content of a specific buffer by path
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | The file path of the buffer |
Implementation Reference
- lib/nvim-operations.js:127-149 (handler)Core implementation of the getBufferContent function that searches Neovim instances for the buffer by path and returns its content.export async function getBufferContent(bufferPath) { const instances = await getNvimInstancesInCwd(); for (const { nvim } of instances) { try { const buffers = await nvim.buffers; for (const buf of buffers) { const name = await buf.name; if (name === bufferPath) { const lines = await buf.lines; const content = lines.join("\n"); return content; } } } catch (error) { console.error("Error getting buffer content:", error.message); } } throw new Error(`Buffer not found: ${bufferPath}`); }
- index.js:133-142 (schema)Input schema for the 'get_buffer_content' tool defining the required 'path' parameter.inputSchema: { type: "object", properties: { path: { type: "string", description: "The file path of the buffer", }, }, required: ["path"], },
- index.js:130-143 (registration)Tool registration entry in the MCP server's ListTools response.{ name: "get_buffer_content", description: "Get the content of a specific buffer by path", inputSchema: { type: "object", properties: { path: { type: "string", description: "The file path of the buffer", }, }, required: ["path"], }, },
- index.js:233-243 (handler)MCP server request handler that dispatches 'get_buffer_content' tool calls to the getBufferContent function.if (name === "get_buffer_content") { const content = await getBufferContent(args.path); return { content: [ { type: "text", text: content, }, ], }; }
- index.js:14-18 (registration)Import of the getBufferContent handler from lib/nvim-operations.js.getBufferContent, updateBuffer, reloadBuffer, reloadAllBuffers, } from "./lib/nvim-operations.js";