Skip to main content
Glama
BaseCommandBuilder.ts1.44 kB
/** * Base command builder class for constructing safe shell commands */ import { escapeShellArg } from '../security/commandValidator.js'; /** * Abstract base class for building command strings safely */ export abstract class BaseCommandBuilder { protected command: string; protected args: string[] = []; constructor(command: string) { this.command = command; } /** * Adds a flag (e.g., -r, -i) */ addFlag(flag: string): this { this.args.push(flag); return this; } /** * Adds an option with a value (e.g., -A 3) */ protected addOption(option: string, value: string | number): this { this.args.push(option, String(value)); return this; } /** * Adds a raw argument (will be validated but not escaped) */ protected addArg(arg: string): this { this.args.push(arg); return this; } /** * Adds an escaped argument (for user input) */ protected addEscapedArg(arg: string): this { this.args.push(escapeShellArg(arg)); return this; } /** * Builds the final command arguments array */ build(): { command: string; args: string[] } { return { command: this.command, args: [...this.args], }; } /** * Resets the builder to initial state */ reset(): this { this.args = []; return this; } /** * Gets the current args (for debugging) */ getArgs(): string[] { return [...this.args]; } }

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/bgauryy/local-explorer-mcp'

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