Skip to main content
Glama

shell_lspci

List PCI devices on your system to identify hardware components and troubleshoot connectivity issues.

Instructions

List PCI devices

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
argsNoCommand arguments

Implementation Reference

  • MCP CallToolRequestSchema handler for shell_lspci: converts tool name to allowlist key, retrieves lspci command config, validates args, executes via executor, streams stdout output.
    server.setRequestHandler(CallToolRequestSchema, async (request) => {
      try {
        const command = String(request.params?.name || '');
        const fullCommand = `shell.${command.replace('shell_', '')}`;  // Replace shell_ back to shell.
        
        if (!(fullCommand in allowedCommands)) {
          return {
            content: [{ type: "text", text: `Unknown command: ${command}` }],
            isError: true
          };
        }
        
        const actualCommand = allowedCommands[fullCommand].command;
        const args = Array.isArray(request.params?.arguments?.args)
          ? request.params.arguments.args.map(String)
          : [];
      
        validator.validateCommand(actualCommand, args);
        const stream = await executor.execute(actualCommand, args);
      
        return {
          content: [{
            type: "text",
            text: await new Promise((resolve, reject) => {
              const chunks: Buffer[] = [];
              stream.stdout.on('data', (chunk: Buffer) => chunks.push(chunk));
              stream.stdout.on('end', () => resolve(Buffer.concat(chunks).toString()));
              stream.stdout.on('error', reject);
            })
          }]
        };
      } catch (error) {
        return {
          content: [{ 
            type: "text", 
            text: `Command execution failed: ${error instanceof Error ? error.message : String(error)}` 
          }],
          isError: true
        };
      }
    });
  • src/index.ts:27-44 (registration)
    Registers the shell_lspci tool (transforms 'shell.lspci' key to 'shell_lspci' name) with description and input schema in ListToolsRequestSchema handler.
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      const tools = Object.entries(allowedCommands).map(([name, config]) => ({
        name: name.replace('shell.', 'shell_'),  // Replace shell. with shell_
        description: config.description,
        inputSchema: {
          type: "object",
          properties: {
            args: {
              type: "array",
              items: { type: "string" },
              description: "Command arguments"
            }
          }
        }
      }));
      return { tools };
    });
  • Schema/configuration for shell.lspci tool: maps to 'lspci' command, provides description, allowed arguments, and timeout.
    'shell.lspci': {
      command: 'lspci',
      description: 'List PCI devices',
      allowedArgs: [
        '-v',     // verbose
        '-k',     // kernel drivers
        '-mm',    // machine readable
        '-nn',    // show vendor/device codes
        '--help'
      ],
      timeout: 2000
    },
  • Core execution handler: spawns child_process for lspci command with args, handles timeout/signal, returns stdout stream.
    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)
          }
        );
      }
    }
  • Validates command and arguments against allowlist config before execution.
    validateCommand(
      command: string, 
      args: string[] = [], 
      options: CommandOptions = {}
    ): void {
      console.log('Validating command:', {
        command,
        args,
        baseCommand: command.replace('shell.', ''),
        fullCommand: `shell.${command.replace('shell.', '')}`,
        config: allowedCommands[`shell.${command.replace('shell.', '')}`]
      });
    
      const baseCommand = command.replace('shell.', '');
      
      if (!(`shell.${baseCommand}` in allowedCommands)) {
        throw new Error(`Command not allowed: ${command}`);
      }
      
      const config = allowedCommands[`shell.${baseCommand}`];
      
      const allowedArgs = config.allowedArgs || [];
      
      console.log('Checking args:', {
        allowedArgs,
        hasWildcard: allowedArgs.includes('*')
      });
    
      args.forEach(arg => {
        if (arg.startsWith('-')) {
          if (!allowedArgs.includes(arg)) {
            console.log('Invalid option:', arg);
            throw new Error(`Invalid argument: ${arg}`);
          }
        }
        else if (!allowedArgs.includes('*')) {
          console.log('Path not allowed:', arg);
          throw new Error(`Invalid argument: ${arg}`);
        } else {
          // 檢查路徑參數
          this.validatePath(arg);
        }
      });
      
      // 檢查超時設定
      if (options.timeout && options.timeout > securityConfig.defaultTimeout) {
        throw new Error(`Timeout exceeds maximum allowed value`);
      }
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure but offers minimal information. It states what the tool does ('List PCI devices') but doesn't describe how it behaves—such as output format, error handling, permissions required, or whether it's read-only or has side effects. This leaves significant gaps for an agent to understand the tool's operation.

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 extremely concise at just three words ('List PCI devices'), with zero wasted language. It's front-loaded and directly communicates the core function without unnecessary elaboration, making it efficient and easy to parse.

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 with no annotations and no output schema, the description is insufficiently complete. It lacks details on behavioral traits, output format, and usage context, which are critical for an agent to invoke it correctly. While the purpose is clear, the overall context needed for effective tool use is missing.

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 input schema has 100% description coverage, with the 'args' parameter documented as 'Command arguments'. The description adds no additional parameter semantics beyond this, as it doesn't explain what arguments are valid or provide examples. Given the high schema coverage, a baseline score of 3 is appropriate, as the schema handles the parameter documentation adequately.

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 PCI devices' clearly states the tool's function with a specific verb ('List') and resource ('PCI devices'), making the purpose immediately understandable. However, it doesn't explicitly differentiate from sibling tools like 'shell_lsusb' (which lists USB devices), missing an opportunity for full 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. It doesn't mention when to choose 'shell_lspci' over other system information tools like 'shell_ls' or 'shell_lsusb', nor does it specify any prerequisites or exclusions for its use.

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