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
| Name | Required | Description | Default |
|---|---|---|---|
| commands | Yes | Array of commands to pipe together | |
| env | No | Additional environment variables for the command | |
| timeout | No | Maximum execution time in milliseconds (max 60s) | |
| workingDir | No | Working directory for command execution |
Implementation Reference
- src/bash/tools/index.ts:109-159 (handler)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, } }
- src/bash/tools/index.ts:33-40 (registration)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), }, ]
- src/utils/bash/bash_tools.ts:85-97 (schema)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'), })
- src/utils/bash/bash_tools.ts:200-224 (helper)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 ) }