Skip to main content
Glama

ubuntu_nginx_control

Control Nginx web server on Ubuntu systems via SSH connections. Start, stop, restart, check status, reload configurations, or verify configuration files remotely.

Instructions

Control Nginx web server on Ubuntu

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
connectionIdYesID of an active SSH connection
actionYesAction to perform (start, stop, restart, status, reload, check-config)
sudoNoWhether to run the command with sudo (default: true)

Implementation Reference

  • Main execution logic for controlling Nginx web server (start, stop, restart, status, reload, check-config) via SSH using systemctl and nginx commands.
    async ubuntu_nginx_control(params) { const { connectionId, action, sudo = true } = params; try { const conn = getConnection(connectionMap, connectionId); // Validate action const validActions = ['start', 'stop', 'restart', 'status', 'reload', 'check-config']; if (!validActions.includes(action)) { throw new Error(`Invalid action: ${action}. Valid actions are: ${validActions.join(', ')}`); } let command = ''; const sudoPrefix = sudo ? 'sudo ' : ''; switch (action) { case 'start': case 'stop': case 'restart': case 'status': case 'reload': command = `${sudoPrefix}systemctl ${action} nginx`; break; case 'check-config': command = `${sudoPrefix}nginx -t`; break; } const result = await executeSSHCommand(conn, command); let status = result.code === 0 ? 'success' : 'error'; let message = result.stdout || result.stderr; if (action === 'status') { // Extract status info from systemctl output const isActive = message.includes('Active: active'); status = isActive ? 'active' : 'inactive'; } return { content: [{ type: 'text', text: `Nginx ${action} result: ${status}\n\n${message}` }] }; } catch (error: any) { return { content: [{ type: 'text', text: `Nginx control error: ${error.message}` }], isError: true }; } },
  • Input schema defining parameters for the ubuntu_nginx_control tool: connectionId (required), action (required), sudo (optional).
    ubuntu_nginx_control: { description: 'Control Nginx web server on Ubuntu', inputSchema: { type: 'object', properties: { connectionId: { type: 'string', description: 'ID of an active SSH connection' }, action: { type: 'string', description: 'Action to perform (start, stop, restart, status, reload, check-config)' }, sudo: { type: 'boolean', description: 'Whether to run the command with sudo (default: true)' } }, required: ['connectionId', 'action'] } },
  • src/index.ts:294-296 (registration)
    Handler dispatch logic in the main CallToolRequestSchema handler that routes ubuntu_* tool calls to the corresponding function in ubuntuToolHandlers.
    if (toolName.startsWith('ubuntu_') && ubuntuToolHandlers[toolName]) { return ubuntuToolHandlers[toolName](request.params.arguments); }
  • Creates the list of Ubuntu tools including ubuntu_nginx_control schema for the overridden ListToolsRequestSchema handler.
    // Create array of Ubuntu tools const ubuntuTools = Object.entries(ubuntuToolSchemas).map(([name, schema]) => ({ name, description: schema.description, inputSchema: schema.inputSchema }));
  • Utility function to execute SSH commands with timeout and error handling, used by the tool handler.
    async function executeSSHCommand(conn: Client, command: string, timeout = 60000): Promise<{ code: number; signal: string; stdout: string; stderr: string; }> { return new Promise((resolve, reject) => { // Set up timeout const timeoutId = setTimeout(() => { reject(new Error(`Command execution timed out after ${timeout}ms`)); }, timeout); conn.exec(command, {}, (err: Error | undefined, stream: any) => { if (err) { clearTimeout(timeoutId); return reject(new Error(`Failed to execute command: ${err.message}`)); } let stdout = ''; let stderr = ''; stream.on('close', (code: number, signal: string) => { clearTimeout(timeoutId); resolve({ code, signal, stdout: stdout.trim(), stderr: stderr.trim() }); }); stream.on('data', (data: Buffer) => { stdout += data.toString(); }); stream.stderr.on('data', (data: Buffer) => { stderr += data.toString(); }); }); }); }

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/mixelpixx/SSH-MCP'

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