Skip to main content
Glama

execute_command

Run commands on a connected VPS via SSH to automate server setup, manage services, configure domains, or integrate CI/CD pipelines.

Instructions

Execute a command on the connected VPS

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
commandYesCommand to execute

Implementation Reference

  • Handler function for the 'execute_command' MCP tool. Validates input using Zod, checks SSH connection, executes the command via SSHService, and returns formatted stdout/stderr/exit code.
    private async handleExecuteCommand( args: unknown ): Promise<{ content: Array<{ type: 'text'; text: string }> }> { if (!this.sshService) { throw new Error('SSH connection not established. Please connect first.'); } const { command } = z.object({ command: z.string() }).parse(args); const result = await this.sshService.executeCommand(command); return { content: [ { type: 'text', text: `Command: ${command}\nExit Code: ${result.exitCode}\nOutput:\n${result.stdout}\n${result.stderr ? `Error:\n${result.stderr}` : ''}`, }, ], }; }
  • JSON schema definition for the 'execute_command' tool input, requiring a 'command' string, provided in ListTools response.
    { name: 'execute_command', description: 'Execute a command on the connected VPS', inputSchema: { type: 'object', properties: { command: { type: 'string', description: 'Command to execute' }, }, required: ['command'], }, },
  • Registration/dispatch in the CallToolRequestSchema handler switch statement, routing 'execute_command' calls to the handler.
    case 'execute_command': return await this.handleExecuteCommand(args);
  • Core helper method in SSHService that executes the SSH command using node-ssh library and returns CommandResult with stdout, stderr, exitCode.
    async executeCommand(command: string): Promise<CommandResult> { if (!this.isConnected) { throw new Error('SSH connection not established'); } try { logger.debug('Executing command', { command }); const result = await this.ssh.execCommand(command); const commandResult: CommandResult = { success: result.code === 0, stdout: result.stdout, stderr: result.stderr, exitCode: result.code || 0, }; if (commandResult.success) { logger.debug('Command executed successfully', { command, exitCode: commandResult.exitCode, }); } else { logger.warn('Command execution failed', { command, exitCode: commandResult.exitCode, stderr: commandResult.stderr, }); } return commandResult; } catch (error) { logger.error('Error executing command', { command, error: error instanceof Error ? error.message : 'Unknown error', }); return { success: false, stdout: '', stderr: error instanceof Error ? error.message : 'Unknown error', exitCode: -1, }; }

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/oxy-Op/DevPilot'

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