Skip to main content
Glama
GUEPARD98

SSH-PowerShell MCP Server

by GUEPARD98

powershell_execute

Execute PowerShell commands locally to automate system administration tasks and streamline Windows management processes.

Instructions

Ejecutar comandos PowerShell localmente

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
commandYesComando PowerShell a ejecutar

Implementation Reference

  • Handler logic for the 'powershell_execute' tool within the CallToolRequestSchema switch statement. Calls executePowerShell and formats the response.
    case 'powershell_execute':
      log('info', `⚡ Ejecutando PowerShell: ${args.command}`);
      const psResult = await executePowerShell(args.command, args.timeout);
      
      return {
        content: [
          {
            type: 'text',
            text: `✅ PowerShell ejecutado:\n\n${psResult.output}`
          }
        ],
        isError: false,
        metadata: {
          tool: 'powershell_execute',
          exitCode: psResult.exitCode,
          executionTime: psResult.executionTime,
          rateLimitInfo: {
            remainingRequests: rateLimiter.getRemainingRequests()
          },
          timestamp: new Date().toISOString()
        }
      };
  • Core helper function that executes PowerShell commands locally, handles stdout/stderr, timeouts, and returns structured results.
    function executePowerShell(command, timeout = null) {
      return new Promise((resolve, reject) => {
        const startTime = Date.now();
        const actualTimeout = timeout || parseInt(process.env.COMMAND_TIMEOUT) || DEFAULT_CONFIG.COMMAND_TIMEOUT;
        
        log('debug', 'Ejecutando comando PowerShell', { command, timeout: actualTimeout });
        
        // Validar comando
        if (!command || typeof command !== 'string') {
          return reject(new Error('Comando PowerShell inválido'));
        }
        
        const psExecutable = getPowerShellExecutable();
        const childProcess = spawn(psExecutable, ['-Command', command], {
          stdio: ['pipe', 'pipe', 'pipe'],
          shell: false // Mejor seguridad sin shell wrapper
        });
        
        let stdout = '';
        let stderr = '';
        let isResolved = false;
        
        childProcess.stdout.on('data', (data) => {
          stdout += data.toString();
        });
        
        childProcess.stderr.on('data', (data) => {
          stderr += data.toString();
        });
        
        childProcess.on('close', (code) => {
          if (isResolved) return;
          isResolved = true;
          
          const executionTime = Date.now() - startTime;
          const result = {
            success: code === 0,
            output: stdout,
            error: stderr || null,
            exitCode: code,
            executionTime
          };
          
          log('debug', 'Comando PowerShell completado', result);
          
          if (code === 0) {
            resolve(result);
          } else {
            reject(result);
          }
        });
        
        childProcess.on('error', (error) => {
          if (isResolved) return;
          isResolved = true;
          
          const result = {
            success: false,
            output: stdout,
            error: error.message,
            exitCode: -1,
            executionTime: Date.now() - startTime
          };
          
          log('error', 'Error ejecutando PowerShell', result);
          reject(result);
        });
        
        // Timeout mejorado
        const timeoutId = setTimeout(() => {
          if (isResolved) return;
          isResolved = true;
          
          try {
            childProcess.kill('SIGKILL');
          } catch (e) {
            log('warn', 'Error matando proceso', e);
          }
          
          const result = {
            success: false,
            output: stdout,
            error: `Timeout de ${actualTimeout}ms excedido`,
            exitCode: -1,
            executionTime: actualTimeout
          };
          
          log('warn', 'Timeout en comando PowerShell', result);
          reject(result);
        }, actualTimeout);
        
        childProcess.on('close', () => clearTimeout(timeoutId));
        childProcess.on('error', () => clearTimeout(timeoutId));
      });
    }
  • src/index.js:432-450 (registration)
    Tool registration in the ListToolsRequestSchema handler, including name, description, and input schema.
    {
      name: 'powershell_execute',
      description: 'Ejecutar comandos PowerShell localmente',
      inputSchema: {
        type: 'object',
        properties: {
          command: {
            type: 'string',
            description: 'Comando PowerShell a ejecutar'
          },
          timeout: {
            type: 'number',
            description: 'Timeout en milisegundos (opcional)'
          }
        },
        required: ['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 states the action ('ejecutar') but lacks critical details: it doesn't specify execution context (e.g., permissions needed, shell environment), potential side effects (e.g., system changes, file modifications), error handling, or output format. For a command execution tool with zero annotation coverage, 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 front-loads the core action and context ('Ejecutar comandos PowerShell localmente'), making it immediately understandable. Every word earns its place without redundancy.

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 the complexity of a command execution tool with no annotations and no output schema, the description is incomplete. It lacks essential context: execution environment details, safety warnings (e.g., destructive commands), output handling, and error scenarios. The agent would struggle to use this tool effectively without guessing behavioral aspects.

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%, with the single parameter 'command' fully documented in the schema. The description adds no additional parameter semantics beyond what the schema provides (e.g., no examples of valid commands, syntax constraints, or security considerations). 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 ('ejecutar') and resource ('comandos PowerShell'), specifying it operates 'localmente'. It distinguishes from sibling tools like ssh_execute by indicating local rather than remote execution. However, it doesn't explicitly differentiate from other potential local command execution tools beyond the sibling context.

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 mentions 'localmente' which implicitly contrasts with SSH-based siblings, but offers no explicit when/when-not criteria, prerequisites, or comparison to other local execution methods. This leaves the agent with minimal usage direction.

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/GUEPARD98/MCP-POWERSHELL'

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