bruno_validate_collection
Validate Bruno collection structure, syntax, and request files to ensure API testing configurations are correct and error-free.
Instructions
Validate a Bruno collection structure, syntax, and request files
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| collectionPath | Yes | Path to the Bruno collection to validate |
Implementation Reference
- ValidateCollectionHandler class implementing IToolHandler interface, containing getName() returning the tool name and handle() method executing the validation logic using BrunoCLI, input validation, error handling, and formatted text output.export class ValidateCollectionHandler implements IToolHandler { private readonly brunoCLI: IBrunoCLI; constructor(brunoCLI: IBrunoCLI) { this.brunoCLI = brunoCLI; } getName(): string { return 'bruno_validate_collection'; } async handle(args: unknown): Promise<ToolResponse> { const params = ValidateCollectionSchema.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 result = await this.brunoCLI.validateCollection(params.collectionPath); const output: string[] = []; output.push('=== Collection Validation ==='); output.push(''); if (result.valid) { output.push('✅ Collection is valid'); } else { output.push('❌ Collection has errors'); } output.push(''); // Summary output.push('Summary:'); output.push(` bruno.json: ${result.summary.hasBrunoJson ? '✓ Found' : '✗ Missing'}`); output.push(` Total Requests: ${result.summary.totalRequests}`); output.push(` Valid Requests: ${result.summary.validRequests}`); output.push(` Invalid Requests: ${result.summary.invalidRequests}`); output.push(` Environments: ${result.summary.environments}`); output.push(''); // Errors if (result.errors.length > 0) { output.push('Errors:'); result.errors.forEach((err: string) => output.push(` ✗ ${err}`)); output.push(''); } // Warnings if (result.warnings.length > 0) { output.push('Warnings:'); result.warnings.forEach((warn: string) => output.push(` ⚠️ ${warn}`)); output.push(''); } if (result.valid && result.warnings.length === 0) { output.push('🎉 Collection is ready to use!'); } 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 validate collection: ${maskedError}` ); } } }
- Zod schema used in the handler for parsing and validating the tool input parameters.const ValidateCollectionSchema = z.object({ collectionPath: z.string().describe('Path to the Bruno collection to validate') });
- src/index.ts:223-236 (registration)Tool definition in the TOOLS array exported to the MCP server, including name, description, and input schema for protocol compliance.{ name: 'bruno_validate_collection', description: "Validate a Bruno collection's structure and configuration", inputSchema: { type: 'object', properties: { collectionPath: { type: 'string', description: 'Path to the Bruno collection to validate' } }, required: ['collectionPath'] } }
- src/index.ts:297-297 (registration)Registration of the ValidateCollectionHandler instance into the ToolRegistry during server initialization.this.toolRegistry.register(new ValidateCollectionHandler(this.brunoCLI));