Skip to main content
Glama

vim_command

Execute Vim commands directly within the MCP server, enabling integration of Vim’s native text editing workflows and optional shell command execution for enhanced productivity.

Instructions

Execute Vim commands with optional shell command support

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
commandYesVim command to execute (use ! prefix for shell commands if enabled)

Implementation Reference

  • src/index.ts:99-134 (registration)
    MCP server.tool registration for 'vim_command', including description, input schema, and thin handler wrapper
    server.tool(
      "vim_command",
      "Execute Vim commands with optional shell command support",
      { command: z.string().describe("Vim command to execute (use ! prefix for shell commands if enabled)") },
      async ({ command }) => {
        try {
          // Check if this is a shell command
          if (command.startsWith('!')) {
            const allowShellCommands = process.env.ALLOW_SHELL_COMMANDS === 'true';
            if (!allowShellCommands) {
              return {
                content: [{
                  type: "text",
                  text: "Shell command execution is disabled. Set ALLOW_SHELL_COMMANDS=true environment variable to enable shell commands."
                }]
              };
            }
          }
    
          const result = await neovimManager.sendCommand(command);
          return {
            content: [{
              type: "text",
              text: result
            }]
          };
        } catch (error) {
          return {
            content: [{
              type: "text",
              text: error instanceof Error ? error.message : 'Error executing command'
            }]
          };
        }
      }
    );
  • Zod input schema defining the 'command' parameter for vim_command tool
    { command: z.string().describe("Vim command to execute (use ! prefix for shell commands if enabled)") },
  • Tool handler function: checks for shell command permission and delegates execution to NeovimManager.sendCommand, with error handling and MCP response formatting
    async ({ command }) => {
      try {
        // Check if this is a shell command
        if (command.startsWith('!')) {
          const allowShellCommands = process.env.ALLOW_SHELL_COMMANDS === 'true';
          if (!allowShellCommands) {
            return {
              content: [{
                type: "text",
                text: "Shell command execution is disabled. Set ALLOW_SHELL_COMMANDS=true environment variable to enable shell commands."
              }]
            };
          }
        }
    
        const result = await neovimManager.sendCommand(command);
        return {
          content: [{
            type: "text",
            text: result
          }]
        };
      } catch (error) {
        return {
          content: [{
            type: "text",
            text: error instanceof Error ? error.message : 'Error executing command'
          }]
        };
      }
    }
  • Core helper method in NeovimManager that implements the actual Vim command execution via Neovim API, handles shell commands (! prefix), captures output and errors using execute() and errmsg
    public async sendCommand(command: string): Promise<string> {
      if (!command || command.trim().length === 0) {
        throw new NeovimValidationError('Command cannot be empty');
      }
    
      try {
        const nvim = await this.connect();
    
        // Remove leading colon if present
        const normalizedCommand = command.startsWith(':') ? command.substring(1) : command;
    
        // Handle shell commands (starting with !)
        if (normalizedCommand.startsWith('!')) {
          if (process.env.ALLOW_SHELL_COMMANDS !== 'true') {
            return 'Shell command execution is disabled. Set ALLOW_SHELL_COMMANDS=true environment variable to enable shell commands.';
          }
    
          const shellCommand = normalizedCommand.substring(1).trim();
          if (!shellCommand) {
            throw new NeovimValidationError('Shell command cannot be empty');
          }
          
          try {
            // Execute the command and capture output directly
            const output = await nvim.eval(`system('${shellCommand.replace(/'/g, "''")}')`);
            if (output) {
              return String(output).trim();
            }
            return 'No output from command';
          } catch (error) {
            console.error('Shell command error:', error);
            const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
            throw new NeovimCommandError(`!${shellCommand}`, errorMessage);
          }
        }
    
        // For regular Vim commands
        await nvim.setVvar('errmsg', '');
        
        // Execute the command and capture its output using the execute() function
        const output = await nvim.call('execute', [normalizedCommand]);
        
        // Check for errors
        const vimerr = await nvim.getVvar('errmsg');
        if (vimerr) {
          console.error('Vim error:', vimerr);
          throw new NeovimCommandError(normalizedCommand, String(vimerr));
        }
    
        // Return the actual command output if any
        return output ? String(output).trim() : 'Command executed (no output)';
      } catch (error) {
        if (error instanceof NeovimCommandError || error instanceof NeovimValidationError) {
          throw error;
        }
        console.error('Error sending command:', error);
        throw new NeovimCommandError(command, error instanceof Error ? error.message : 'Unknown error');
      }
    }
Behavior2/5

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

With no annotations provided, the description carries full burden but lacks behavioral details. It mentions shell command support via '! prefix', which adds some context, but doesn't disclose critical traits like whether commands are read-only or destructive, error handling, execution environment, or output format. This is inadequate for a tool that executes commands, leaving significant gaps in understanding its behavior.

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 with a single sentence that directly states the purpose and key feature (shell command support). It's front-loaded and wastes no words, making it easy to parse quickly without 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 the complexity of executing Vim commands (which can range from safe reads to destructive writes) and the lack of annotations and output schema, the description is incomplete. It doesn't address safety, permissions, or what the tool returns, leaving the agent with insufficient information to use it effectively in context with many sibling tools.

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 single 'command' parameter with its description. The description adds minimal value by reiterating the command focus and hinting at shell usage, but doesn't provide additional syntax examples, constraints, or semantic context beyond what's in the schema. Baseline 3 is appropriate as the schema handles 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 verb ('Execute') and resource ('Vim commands'), specifying the action. It distinguishes from siblings like vim_edit or vim_search by focusing on raw command execution rather than specific operations, though it doesn't explicitly contrast with tools like vim_buffer or vim_macro that might also involve commands.

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?

The description provides minimal guidance, mentioning 'optional shell command support' which hints at a use case, but offers no explicit when-to-use rules, prerequisites, or alternatives. It doesn't clarify when to choose this over sibling tools like vim_edit for editing or vim_search for searching, leaving usage ambiguous.

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