Skip to main content
Glama

update_buffer

Modify Neovim buffer content directly from the MCP server to reflect changes immediately in the editor.

Instructions

Update the content of a buffer in Neovim. Changes appear immediately in the editor.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesThe file path of the buffer to update
contentYesThe new content for the buffer

Implementation Reference

  • The core handler function that locates the Neovim buffer by path across instances and updates its content by setting new lines.
    export async function updateBuffer(bufferPath, newContent) { 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 = newContent.split("\n"); await buf.setLines(lines, { start: 0, end: -1 }); return { success: true, path: bufferPath }; } } } catch (error) { console.error("Error updating buffer:", error.message); } } throw new Error(`Buffer not found: ${bufferPath}`); }
  • The tool schema definition provided in the ListTools response, specifying the input parameters 'path' and 'content'.
    { name: "update_buffer", description: "Update the content of a buffer in Neovim. Changes appear immediately in the editor.", inputSchema: { type: "object", properties: { path: { type: "string", description: "The file path of the buffer to update", }, content: { type: "string", description: "The new content for the buffer", }, }, required: ["path", "content"], }, },
  • index.js:262-271 (registration)
    The registration and dispatch logic within the CallToolRequestHandler that matches the tool name and invokes the updateBuffer function.
    if (name === "update_buffer") { const result = await updateBuffer(args.path, args.content); return { content: [ { type: "text", text: `Successfully updated buffer: ${result.path}`, }, ], };

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