super-shell-mcp
Version:
MCP server for executing shell commands across multiple platforms
157 lines (156 loc) • 5.12 kB
TypeScript
import { EventEmitter } from 'events';
/**
* Command security level classification
*/
export declare enum CommandSecurityLevel {
/** Safe commands that can be executed without approval */
SAFE = "safe",
/** Commands that require approval before execution */
REQUIRES_APPROVAL = "requires_approval",
/** Commands that are explicitly forbidden */
FORBIDDEN = "forbidden"
}
/**
* Command whitelist entry
*/
export interface CommandWhitelistEntry {
/** The command path or name */
command: string;
/** Security level of the command */
securityLevel: CommandSecurityLevel;
/** Allowed arguments (string for exact match, RegExp for pattern match) */
allowedArgs?: Array<string | RegExp>;
/** Description of the command for documentation */
description?: string;
}
/**
* Pending command awaiting approval
*/
export interface PendingCommand {
/** Unique ID for the command */
id: string;
/** The command to execute */
command: string;
/** Arguments for the command */
args: string[];
/** When the command was requested */
requestedAt: Date;
/** Who requested the command */
requestedBy?: string;
/** Resolve function to call when approved */
resolve: (value: {
stdout: string;
stderr: string;
}) => void;
/** Reject function to call when denied */
reject: (reason: Error) => void;
}
/**
* Result of command execution
*/
export interface CommandResult {
/** Standard output from the command */
stdout: string;
/** Standard error from the command */
stderr: string;
}
/**
* Service for securely executing shell commands
*/
export declare class CommandService extends EventEmitter {
/** Shell to use for commands */
private shell;
/** Command whitelist */
private whitelist;
/** Pending commands awaiting approval */
private pendingCommands;
/** Default timeout for command execution in milliseconds */
private defaultTimeout;
/**
* Create a new CommandService
* @param shell The shell to use for commands (default: auto-detected based on platform)
* @param defaultTimeout Default timeout for command execution in milliseconds (default: 30000)
*/
constructor(shell?: string, defaultTimeout?: number);
/**
* Get the current shell being used
* @returns The shell path
*/
getShell(): string;
/**
* Initialize the default command whitelist based on the current platform
*/
private initializeDefaultWhitelist;
/**
* Add a command to the whitelist
* @param entry The command whitelist entry
*/
addToWhitelist(entry: CommandWhitelistEntry): void;
/**
* Remove a command from the whitelist
* @param command The command to remove
*/
removeFromWhitelist(command: string): void;
/**
* Update a command's security level
* @param command The command to update
* @param securityLevel The new security level
*/
updateSecurityLevel(command: string, securityLevel: CommandSecurityLevel): void;
/**
* Get all whitelisted commands
* @returns Array of command whitelist entries
*/
getWhitelist(): CommandWhitelistEntry[];
/**
* Get all pending commands awaiting approval
* @returns Array of pending commands
*/
getPendingCommands(): PendingCommand[];
/**
* Validate if a command and its arguments are allowed
* @param command The command to validate
* @param args The command arguments
* @returns The security level of the command or null if not whitelisted
*/
private validateCommand;
/**
* Execute a shell command
* @param command The command to execute
* @param args Command arguments
* @param options Additional options
* @returns Promise resolving to command output
*/
executeCommand(command: string, args?: string[], options?: {
timeout?: number;
requestedBy?: string;
}): Promise<CommandResult>;
/**
* Queue a command for approval
* @param command The command to queue
* @param args Command arguments
* @param requestedBy Who requested the command
* @returns Promise resolving when command is approved and executed
*/
private queueCommandForApproval;
/**
* Queue a command for approval without waiting for the Promise to resolve
* @param command The command to queue
* @param args Command arguments
* @param requestedBy Who requested the command
* @returns The ID of the queued command
*/
queueCommandForApprovalNonBlocking(command: string, args?: string[], requestedBy?: string): string;
/**
* Approve a pending command
* @param commandId ID of the command to approve
* @returns Promise resolving to command output
*/
approveCommand(commandId: string): Promise<CommandResult>;
/**
* Deny a pending command
* @param commandId ID of the command to deny
* @param reason Reason for denial
*/
denyCommand(commandId: string, reason?: string): void;
}