bruno_list_environments
Retrieve all available environments from a Bruno collection to manage different API configurations and testing scenarios.
Instructions
List all available environments in a Bruno collection
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| collectionPath | Yes | Path to the Bruno collection |
Implementation Reference
- The handle() method of ListEnvironmentsHandler executes the tool logic: validates input, lists environments using brunoCLI.listEnvironments(), formats output with variable previews (masking secrets), and returns text content.async handle(args: unknown): Promise<ToolResponse> { const params = ListEnvironmentsSchema.parse(args); // Validate collection path const validation = await validateToolParameters({ collectionPath: params.collectionPath }); if (!validation.valid) { throw new McpError( ErrorCode.InvalidParams, `Invalid collection path: ${validation.errors.join(', ')}` ); } try { const environments = await this.brunoCLI.listEnvironments(params.collectionPath); const output: string[] = []; if (environments.length === 0) { output.push('No environments found in this collection.'); output.push(''); output.push('Environments are stored in the "environments" directory with .bru extension.'); } else { output.push(`Found ${environments.length} environment(s):\n`); environments.forEach((env) => { output.push(`• ${env.name}`); output.push(` Path: ${env.path}`); if (env.variables && Object.keys(env.variables).length > 0) { output.push(` Variables: ${Object.keys(env.variables).length}`); // Show first few variables as preview const varEntries = Object.entries(env.variables).slice(0, 3); varEntries.forEach(([key, value]) => { // Mask potential secrets in output const displayValue = key.toLowerCase().includes('password') || key.toLowerCase().includes('secret') || key.toLowerCase().includes('token') || key.toLowerCase().includes('key') ? '***' : value.length > 50 ? value.substring(0, 47) + '...' : value; output.push(` - ${key}: ${displayValue}`); }); if (Object.keys(env.variables).length > 3) { output.push(` ... and ${Object.keys(env.variables).length - 3} more`); } } output.push(''); }); } return { content: [ { type: 'text', text: output.join('\n') } as TextContent ] }; } catch (error) { const maskedError = error instanceof Error ? maskSecretsInError(error) : error; throw new McpError( ErrorCode.InternalError, `Failed to list environments: ${maskedError}` ); } }
- The full ListEnvironmentsHandler class defining the tool handler, including getName() returning 'bruno_list_environments' and the handle() method.export class ListEnvironmentsHandler implements IToolHandler { private readonly brunoCLI: IBrunoCLI; constructor(brunoCLI: IBrunoCLI) { this.brunoCLI = brunoCLI; } getName(): string { return 'bruno_list_environments'; } async handle(args: unknown): Promise<ToolResponse> { const params = ListEnvironmentsSchema.parse(args); // Validate collection path const validation = await validateToolParameters({ collectionPath: params.collectionPath }); if (!validation.valid) { throw new McpError( ErrorCode.InvalidParams, `Invalid collection path: ${validation.errors.join(', ')}` ); } try { const environments = await this.brunoCLI.listEnvironments(params.collectionPath); const output: string[] = []; if (environments.length === 0) { output.push('No environments found in this collection.'); output.push(''); output.push('Environments are stored in the "environments" directory with .bru extension.'); } else { output.push(`Found ${environments.length} environment(s):\n`); environments.forEach((env) => { output.push(`• ${env.name}`); output.push(` Path: ${env.path}`); if (env.variables && Object.keys(env.variables).length > 0) { output.push(` Variables: ${Object.keys(env.variables).length}`); // Show first few variables as preview const varEntries = Object.entries(env.variables).slice(0, 3); varEntries.forEach(([key, value]) => { // Mask potential secrets in output const displayValue = key.toLowerCase().includes('password') || key.toLowerCase().includes('secret') || key.toLowerCase().includes('token') || key.toLowerCase().includes('key') ? '***' : value.length > 50 ? value.substring(0, 47) + '...' : value; output.push(` - ${key}: ${displayValue}`); }); if (Object.keys(env.variables).length > 3) { output.push(` ... and ${Object.keys(env.variables).length - 3} more`); } } output.push(''); }); } return { content: [ { type: 'text', text: output.join('\n') } as TextContent ] }; } catch (error) { const maskedError = error instanceof Error ? maskSecretsInError(error) : error; throw new McpError( ErrorCode.InternalError, `Failed to list environments: ${maskedError}` ); } } }
- Zod schema for input validation in the handler.const ListEnvironmentsSchema = z.object({ collectionPath: z.string().describe('Path to the Bruno collection') });
- src/index.ts:294-294 (registration)Registration of ListEnvironmentsHandler instance in ToolRegistry.this.toolRegistry.register(new ListEnvironmentsHandler(this.brunoCLI));
- src/index.ts:173-186 (schema)Tool definition in TOOLS array including name, description, and inputSchema for MCP protocol.{ name: 'bruno_list_environments', description: 'List all environments in a Bruno collection', inputSchema: { type: 'object', properties: { collectionPath: { type: 'string', description: 'Path to the Bruno collection' } }, required: ['collectionPath'] } },