Skip to main content
Glama

bash_pipe

Execute a sequence of Bash commands piped together on the MCP Filesystem Server. Combine commands for advanced processing, with results capturing both stdout and stderr.

Instructions

Execute a sequence of Bash commands piped together. Allows for powerful command combinations with pipes. Results include both stdout and stderr.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
commandsYesArray of commands to pipe together
envNoAdditional environment variables for the command
timeoutNoMaximum execution time in milliseconds (max 60s)
workingDirNoWorking directory for command execution

Implementation Reference

  • Main handler for bash_pipe tool: validates arguments using BashPipeArgsSchema, calls bashPipe core function, formats output with stdout/stderr/exit code, logs, and returns MCP response or error.
    export async function handleBashPipe(args: any, config: Config) { const endMetric = metrics.startOperation('bash_pipe') try { // Validate arguments const parsed = BashPipeArgsSchema.safeParse(args) if (!parsed.success) { throw new FileSystemError(`Invalid arguments for bash_pipe`, 'INVALID_ARGS', undefined, { errors: parsed.error.format(), }) } // Execute the command const result = await bashPipe(parsed.data, config) // Format the response const formattedResponse = formatCommandResult(result, parsed.data.commands.join(' | ')) await logger.debug(`Bash pipe executed`, { commands: parsed.data.commands, exitCode: result.exitCode, }) endMetric() return { content: [ { type: 'text', text: formattedResponse, }, ], } } catch (error) { metrics.recordError('bash_pipe') if (error instanceof FileSystemError) { await logger.error(`Error in bash_pipe:`, error.toJSON()) return { content: [{ type: 'text', text: `Error: ${error.message}` }], isError: true, } } const errorMessage = error instanceof Error ? error.message : String(error) await logger.error(`Unexpected error in bash_pipe:`, { error }) return { content: [{ type: 'text', text: `Error: ${errorMessage}` }], isError: true, } }
  • Tool registration object defining name 'bash_pipe', description, and input schema (converted from Zod schema).
    name: 'bash_pipe', description: 'Execute a sequence of Bash commands piped together. ' + 'Allows for powerful command combinations with pipes. ' + 'Results include both stdout and stderr.', inputSchema: zodToJsonSchema(BashPipeArgsSchema), }, ]
  • Zod schema defining input arguments for bash_pipe: array of commands (required), optional workingDir, timeout (default 30s max 60s), and env vars.
    export const BashPipeArgsSchema = z.object({ commands: z.array(z.string()).min(1).describe('Array of commands to pipe together'), workingDir: z.string().optional().describe('Working directory for command execution'), timeout: z .number() .int() .positive() .max(60000) .optional() .default(30000) .describe('Maximum execution time in milliseconds (max 60s)'), env: z.record(z.string()).optional().describe('Additional environment variables for the command'), })
  • Core bash_pipe implementation: validates each command for safety, joins them with ' | ', and delegates execution to bashExecute helper.
    export async function bashPipe( args: z.infer<typeof BashPipeArgsSchema>, config: Config ): Promise<{ stdout: string; stderr: string; exitCode: number }> { // Validate each command for (const command of args.commands) { validateCommand(command) } // Validate working directory if provided args.workingDir ? await validatePath(args.workingDir, config) : process.cwd() // Construct the piped command const pipedCommand = args.commands.join(' | ') // Use bash to execute the piped command return bashExecute( { command: pipedCommand, workingDir: args.workingDir, timeout: args.timeout, env: args.env, }, config ) }

Other Tools

Related 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/gabrielmaialva33/mcp-filesystem'

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