Skip to main content
Glama

shell_lsusb

List USB devices connected to the system using the lsusb command through the Shell-MCP server, providing device identification and connection details.

Instructions

List USB devices

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
argsNoCommand arguments

Implementation Reference

  • Configuration entry for 'shell.lsusb' that registers the tool named 'lsusb' in the MCP server. Defines the underlying shell command, description, allowed arguments for validation, and execution timeout.
    'shell.lsusb': {
      command: 'lsusb',
      description: 'List USB devices',
      allowedArgs: [
        '-v',     // verbose
        '-t',     // tree
        '-d',     // device
        '-s',     // bus/device number
        '--help'
      ],
      timeout: 2000
    },
  • Generic MCP tool call handler that processes calls to 'lsusb' (mapped from tool name to 'shell.lsusb' config) by validating, executing via CommandExecutor, collecting output, and returning as text content.
    this.server.setRequestHandler(CallToolRequestSchema, async (request, extra: unknown) => {
      const ext = extra as Extra;
      if (!request.params?.name) {
        throw new ToolError('MISSING_COMMAND', 'Command name is required');
      }
      
      const command = String(request.params.name);
      const fullCommand = command.startsWith('shell.') ? command : `shell.${command}`;
      
      if (!(fullCommand in allowedCommands)) {
        throw new ToolError('COMMAND_NOT_FOUND', 'Command not found', { command });
      }
      
      const config = allowedCommands[fullCommand];
      const args = Array.isArray(request.params.arguments?.args)
        ? request.params.arguments.args.map(String)
        : [];
    
      const context: CommandContext = {
        requestId: ext.id || 'unknown',
        command,
        args,
        timeout: config.timeout,
        workDir: config.workDir,
        env: config.env
      };
    
      this.logger.info('Starting command execution', context);
    
      try {
        this.validator.validateCommand(command, args);
        
        this.logger.debug('Command validation passed', {
          ...context,
          config
        });
    
        const stream = await this.executor.execute(command, args, {
          timeout: config.timeout,
          cwd: config.workDir,
          env: config.env
        });
    
        ext.onCancel?.(() => {
          this.logger.info('Received cancel request', context);
          this.executor.interrupt();
        });
    
        const output = await this.collectOutput(stream);
    
        this.logger.info('Command execution completed', {
          ...context,
          outputLength: output.length
        });
    
        return {
          content: [{
            type: "text",
            text: output
          }]
        };
    
      } catch (error) {
        this.logger.error('Command execution failed', {
          ...context,
          error: error instanceof Error ? error.message : String(error),
          stack: error instanceof Error ? error.stack : undefined
        });
        
        throw new ToolError(
          'EXECUTION_FAILED',
          `Command execution failed: ${error instanceof Error ? error.message : String(error)}`,
          context
        );
      }
    });
  • Executes the shell command by spawning 'lsusb' (strips 'shell.' prefix) with arguments, handles streaming output, timeouts, caching, and security validation.
    async execute(
      command: string,
      args: string[] = [],
      options: ExecuteOptions = {}
    ): Promise<{ stdout: Readable }> {
      const commandKey = `${command} ${args.join(' ')}`;
      
      try {
        // Check security
        await this.securityChecker.validateCommand(command, args, options);
    
        // Check cache
        const cached = this.cache.get(commandKey);
        if (cached) {
          this.logger.debug('Using cached command result', { command, args });
          return this.createStreamFromCache(cached);
        }
    
        // Remove 'shell.' prefix for execution
        const baseCommand = command.replace('shell.', '');
    
        // Execute command
        this.logger.debug('Starting command execution', { command, args, options });
        const childProcess = spawn(baseCommand, args, {
          stdio: ['ignore', 'pipe', 'pipe'],
          timeout: options.timeout,
          cwd: options.cwd,
          env: {
            ...process.env,
            ...options.env
          },
          signal: options.signal
        });
    
        this.currentProcess = childProcess;
    
        // Error handling
        childProcess.on('error', (error: Error) => {
          this.logger.error('Command execution error', {
            command,
            args,
            error: error.message
          });
          throw new ToolError(
            'PROCESS_ERROR',
            'Command execution error',
            { command, args, error: error.message }
          );
        });
    
        // Timeout handling
        if (options.timeout) {
          setTimeout(() => {
            if (childProcess.exitCode === null) {
              this.logger.warn('Command execution timeout', {
                command,
                args,
                timeout: options.timeout
              });
              childProcess.kill();
              throw new ToolError(
                'TIMEOUT',
                'Command execution timeout',
                { command, args, timeout: options.timeout }
              );
            }
          }, options.timeout);
        }
    
        if (!childProcess.stdout) {
          throw new ToolError(
            'STREAM_ERROR',
            'Unable to get command output stream',
            { command, args }
          );
        }
    
        // Monitor process status
        childProcess.on('exit', (code, signal) => {
          this.logger.debug('Command execution completed', {
            command,
            args,
            exitCode: code,
            signal
          });
        });
    
        return {
          stdout: childProcess.stdout
        };
    
      } catch (error) {
        this.logger.error('Command execution failed', {
          command,
          args,
          error: error instanceof Error ? error.message : String(error)
        });
        
        throw new ToolError(
          'EXECUTION_ERROR',
          'Command execution failed',
          { 
            command, 
            args, 
            error: error instanceof Error ? error.message : String(error)
          }
        );
      }
    }
  • Dynamically generates the input schema for the 'lsusb' tool during listTools request, using description from config and standard args array schema.
    tools.push({
      name: toolName,
      description: config.description,
      inputSchema: {
        type: "object",
        properties: {
          args: {
            type: "array",
            items: { type: "string" },
            description: "Command arguments"
          }
        }
      }
    });
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. 'List USB devices' implies a read-only operation but doesn't specify output format, whether it requires special permissions, potential side effects, or how it handles errors. For a shell tool with zero annotation coverage, this leaves significant gaps.

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 perfectly concise at three words, front-loaded with the essential information. There's zero waste or unnecessary elaboration, making it immediately scannable and understandable.

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 no annotations, no output schema, and a single parameter with good schema coverage, the description is incomplete. It doesn't address what the tool returns, error conditions, or behavioral characteristics needed for a shell command tool. The minimal description leaves too many questions unanswered.

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?

The schema has 100% description coverage for its single parameter ('args' with description 'Command arguments'), so the baseline is 3. The tool description doesn't add any parameter-specific information beyond what's in the schema, but doesn't need to compensate for gaps either.

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 'List USB devices' clearly states the verb ('List') and resource ('USB devices'), making the purpose immediately understandable. It distinguishes this tool from siblings like shell_ls (general listing) or shell_lspci (PCI devices), though it doesn't explicitly mention this differentiation.

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. There's no mention of prerequisites, when it's appropriate versus other listing tools, or any context about its specific use case beyond the basic purpose.

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/kevinwatt/shell-mcp'

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