Skip to main content
Glama

vim_buffer

Retrieve buffer contents with line numbers from Neovim for efficient text editing and code management.

Instructions

Get buffer contents with line numbers

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filenameNoOptional file name to view a specific buffer

Implementation Reference

  • src/index.ts:74-97 (registration)
    Registration of the 'vim_buffer' MCP tool, including schema, description, and inline handler function that delegates to NeovimManager.getBufferContents and formats output.
      "vim_buffer",
      "Get buffer contents with line numbers",
      { filename: z.string().optional().describe("Optional file name to view a specific buffer") },
      async ({ filename }) => {
        try {
          const bufferContents = await neovimManager.getBufferContents(filename);
          return {
            content: [{
              type: "text",
              text: Array.from(bufferContents.entries())
                .map(([lineNum, lineText]) => `${lineNum}: ${lineText}`)
                .join('\n')
            }]
          };
        } catch (error) {
          return {
            content: [{
              type: "text",
              text: error instanceof Error ? error.message : 'Error getting buffer contents'
            }]
          };
        }
      }
    );
  • Core handler logic in NeovimManager.getBufferContents: connects to Neovim instance, selects target buffer (by filename or current), retrieves all lines, and returns Map of line number to line content.
    public async getBufferContents(filename?: string): Promise<Map<number, string>> {
      try {
        const nvim = await this.connect();
        let buffer;
        
        if (filename) {
          // Find buffer by filename
          const buffers = await nvim.buffers;
          let targetBuffer = null;
          
          for (const buf of buffers) {
            const bufName = await buf.name;
            if (bufName === filename || bufName.endsWith(filename)) {
              targetBuffer = buf;
              break;
            }
          }
          
          if (!targetBuffer) {
            throw new NeovimValidationError(`Buffer not found: ${filename}`);
          }
          buffer = targetBuffer;
        } else {
          buffer = await nvim.buffer;
        }
        
        const lines = await buffer.lines;
        const lineMap = new Map<number, string>();
    
        lines.forEach((line: string, index: number) => {
          lineMap.set(index + 1, line);
        });
    
        return lineMap;
      } catch (error) {
        if (error instanceof NeovimValidationError) {
          throw error;
        }
        console.error('Error getting buffer contents:', error);
        return new Map();
      }
    }
  • Input schema using Zod: optional filename parameter to specify which buffer to retrieve.
    { filename: z.string().optional().describe("Optional file name to view a specific buffer") },
  • Helper method connect() used by getBufferContents to establish Neovim connection via socket.
    private async connect(): Promise<Neovim> {
      const socketPath = process.env.NVIM_SOCKET_PATH || '/tmp/nvim';
      this.validateSocketPath(socketPath);
      
      try {
        return attach({
          socket: socketPath
        });
      } catch (error) {
        console.error('Error connecting to Neovim:', error);
        throw new NeovimConnectionError(socketPath, error as Error);
      }
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It states what the tool does but doesn't disclose behavioral traits like whether it's read-only, if it requires specific buffer states, what happens with invalid filenames, or how it handles multiple buffers. The description is minimal and lacks operational context.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise (one short phrase) and front-loaded with the core purpose. Every word earns its place, with no wasted text or unnecessary elaboration.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations and no output schema, the description is incomplete for a tool that presumably returns buffer contents. It doesn't explain what format the output takes (e.g., text, structured data), how errors are handled, or what 'buffer contents' entails beyond line numbers. For a tool with 1 parameter and no structured safety hints, more context is needed.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents the optional 'filename' parameter. The description doesn't add any meaning beyond what the schema provides, such as explaining what 'buffer contents' includes or how line numbers are formatted. Baseline 3 is appropriate when schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Get buffer contents') and what is returned ('with line numbers'), making the purpose immediately understandable. However, it doesn't explicitly differentiate from sibling tools like 'vim_status' or 'vim_file_open' which might also provide buffer-related information.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives. With siblings like 'vim_buffer_save', 'vim_buffer_switch', 'vim_edit', and 'vim_file_open', the description doesn't indicate whether this is for viewing current buffers, specific buffers, or how it differs from other buffer-related operations.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

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/bigcodegen/mcp-neovim-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server