execute_command
Execute commands on a VPS to manage services, configure domains, set up SSL certificates, and deploy applications via SSH connections.
Instructions
Execute a command on the connected VPS
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| command | Yes | Command to execute |
Implementation Reference
- src/services/mcp-server.ts:290-308 (handler)The main handler function for the MCP 'execute_command' tool. It validates the input arguments, checks if SSH is connected, executes the command using SSHService, and formats the response with stdout, stderr, and 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}` : ''}`, }, ], }; }
- src/services/mcp-server.ts:137-143 (schema)Input schema definition for the 'execute_command' tool, specifying the required 'command' string parameter.inputSchema: { type: 'object', properties: { command: { type: 'string', description: 'Command to execute' }, }, required: ['command'], },
- src/services/mcp-server.ts:163-164 (registration)Registration of the 'execute_command' tool handler in the CallToolRequestSchema switch statement.case 'execute_command': return await this.handleExecuteCommand(args);
- src/services/mcp-server.ts:135-144 (registration)Tool definition and registration in the ListToolsRequestSchema response, including name, description, and schema.name: 'execute_command', description: 'Execute a command on the connected VPS', inputSchema: { type: 'object', properties: { command: { type: 'string', description: 'Command to execute' }, }, required: ['command'], }, },
- src/services/ssh-service.ts:57-98 (helper)Core helper function that performs the actual SSH command execution using node-ssh library, handling connection check, execution, logging, and error handling.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, }; }