Skip to main content
Glama
A-Niranjan

MCP Filesystem Server

by A-Niranjan

bash_pipe

Execute a sequence of Bash commands piped together to combine multiple operations in a single workflow, returning both stdout and stderr outputs.

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
workingDirNoWorking directory for command execution
timeoutNoMaximum execution time in milliseconds (max 60s)
envNoAdditional environment variables for the command

Implementation Reference

  • The primary handler function for the 'bash_pipe' tool. Validates input arguments using BashPipeArgsSchema, executes the piped commands via bashPipe, formats the result with stdout/stderr/exit code, and handles errors.
    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, } }
  • Core implementation of bash_pipe logic: validates each command in the array, joins them with pipe '|', constructs args for bashExecute, and delegates execution.
    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 ) }
  • Zod schema for input validation of the bash_pipe tool, defining required 'commands' array and optional workingDir, timeout, env.
    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/index.ts:363-370 (registration)
    Registration of the 'bash_pipe' tool in the list_tools handler response, specifying name, description, and input 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) as ToolInput, },
  • src/index.ts:761-763 (registration)
    Dispatch handler in the main tool call switch statement that routes 'bash_pipe' calls to the handleBashPipe function.
    case 'bash_pipe': { return await handleBashPipe(a, config) }

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/A-Niranjan/mcp-filesystem'

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