Skip to main content
Glama
laktek
by laktek

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
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • 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: {},
      },
    },
  • 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}`,
          },
        ],
      };
    }

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