Skip to main content
Glama

proc_sudo

Execute commands with sudo privileges on remote servers via SSH to perform administrative tasks securely.

Instructions

Executes a command with sudo privileges

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sessionIdYesSSH session ID
commandYesCommand to execute with sudo
passwordNoSudo password
cwdNoWorking directory

Implementation Reference

  • The `execSudo` function handles the execution of commands with sudo privileges, including path/password handling and sudo-specific error checks.
    export async function execSudo(
      sessionId: string,
      command: string,
      password?: string,
      cwd?: string,
      timeoutMs?: number
    ): Promise<ExecResult> {
      logger.debug('Executing sudo command', { sessionId, command, cwd, timeoutMs });
    
      const session = sessionManager.getSession(sessionId);
      if (!session) {
        throw new Error(`Session ${sessionId} not found or expired`);
      }
    
      const osInfo = await sessionManager.getOSInfo(sessionId);
    
      if (osInfo.platform === 'windows') {
        throw createSudoError(
          'Sudo is not supported on Windows hosts',
          'Use an elevated session instead of sudo commands'
        );
      }
    
      const timer = createTimer();
    
      try {
        const fullCommand = buildSudoCommand(command, osInfo, password, cwd);
    
        // Execute with optional timeout
        let result;
        if (timeoutMs) {
          result = await Promise.race([
            session.ssh.execCommand(fullCommand),
            new Promise<never>((_, reject) =>
              setTimeout(() => reject(createTimeoutError(
                `Sudo command timed out after ${timeoutMs}ms`,
                'Increase timeout or optimize the command'
              )), timeoutMs)
            )
          ]);
        } else {
          result = await session.ssh.execCommand(fullCommand);
        }
    
        // Check if sudo failed due to password issues
        if (result.code !== 0 && result.stderr) {
          const stderrLower = result.stderr.toLowerCase();
          if (stderrLower.includes('password') ||
            stderrLower.includes('authentication') ||
            stderrLower.includes('sorry')) {
            throw createSudoError(
              'Sudo authentication failed',
              'Provide a valid sudo password or ensure NOPASSWD is configured'
            );
          }
        }
    
        const execResult: ExecResult = {
          code: result.code || 0,
          stdout: result.stdout || '',
          stderr: result.stderr || '',
          durationMs: timer.elapsed()
        };
    
        logger.debug('Sudo command execution completed', {
          sessionId,
          code: execResult.code,
          durationMs: execResult.durationMs
        });
    
        return execResult;
    
      } catch (error) {
        if ((error as any)?.code === ErrorCode.ETIMEOUT) {
          throw error;
        }
        if (error instanceof Error && error.message.includes('sudo')) {
          throw error;
        }
    
        logger.error('Sudo command execution failed', { sessionId, command, error });
        throw wrapError(error, ErrorCode.ENOSUDO, 'Failed to execute sudo command on remote system');
      }
    }
  • src/mcp.ts:417-424 (registration)
    Registration of the 'proc_sudo' tool handler within the MCP server's request handler switch statement.
    case 'proc_sudo': {
      const params = SudoSchema.parse(args);
      const result = await execSudo(params.sessionId, params.command, params.password, params.cwd, params.timeoutMs);
      // Add safety warning (never blocks, only warns)
      const resultWithWarning = addSafetyWarningToResult(params.command, result);
      logger.info('Sudo command executed', { sessionId: params.sessionId, command: redactSensitiveData(params.command) });
      return { content: [{ type: 'text', text: JSON.stringify(resultWithWarning, null, 2) }] };
    }
  • Definition of the 'proc_sudo' tool's input schema in the MCP server.
      name: 'proc_sudo',
      description: 'Executes a command with sudo privileges',
      inputSchema: {
        type: 'object',
        properties: {
          sessionId: { type: 'string', description: 'SSH session ID' },
          command: { type: 'string', description: 'Command to execute with sudo' },
          password: { type: 'string', description: 'Sudo password' },
          cwd: { type: 'string', description: 'Working directory' }
        },
        required: ['sessionId', 'command']
      }
    },
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions 'sudo privileges' which implies elevated permissions, but fails to describe critical behaviors: whether it requires authentication (password parameter hints at this but isn't explicit), potential security implications, error handling, or output format. For a tool that executes privileged commands, this is a significant gap in transparency.

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 a single, efficient sentence with zero wasted words. It's front-loaded with the core functionality and appropriately sized for what it conveys.

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?

For a tool that executes privileged commands with 4 parameters and no annotations or output schema, the description is incomplete. It doesn't address security considerations, error conditions, output expectations, or relationship to sibling tools. Given the complexity and potential risks of sudo execution, more contextual information would be valuable.

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 all four parameters thoroughly. The description adds no additional parameter semantics beyond what's in the schema (e.g., it doesn't explain sudo password requirements or command execution context). Baseline 3 is appropriate when the 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 verb 'executes' and the resource 'a command with sudo privileges', making the purpose unambiguous. However, it doesn't differentiate from its sibling 'proc_exec' which executes commands without sudo privileges, missing an opportunity for explicit sibling distinction.

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 no guidance on when to use this tool versus alternatives like 'proc_exec' (for non-sudo commands) or other execution tools. There's no mention of prerequisites (e.g., requiring an established SSH session) or typical use cases, leaving the agent to infer usage from context alone.

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

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/oaslananka/mcp-ssh-tool'

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