Skip to main content
Glama
laktek
by laktek

get_buffer_content

Retrieve content from Neovim buffers by specifying file paths to access and work with in-editor text directly through the MCP server.

Instructions

Get the content of a specific buffer by path

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesThe file path of the buffer

Implementation Reference

  • The core handler function that retrieves the content of a specific Neovim buffer by its path. It iterates through Neovim instances and their buffers to find a matching path and returns the joined lines as a string.
    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}`);
    }
  • The input schema definition for the 'get_buffer_content' tool, specifying a required 'path' string parameter.
    {
      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:250-259 (registration)
    The registration and dispatch logic in the CallToolRequestSchema handler that invokes getBufferContent for the 'get_buffer_content' tool name and formats the response.
    if (name === "get_buffer_content") {
      const content = await getBufferContent(args.path);
      return {
        content: [
          {
            type: "text",
            text: content,
          },
        ],
      };

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