Skip to main content
Glama

bruno_validate_environment

Validate environment files in Bruno collections to ensure proper configuration and prevent errors in API testing workflows.

Instructions

Validate an environment file in a Bruno collection

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
collectionPathYesPath to the Bruno collection
environmentNameYesName of the environment to validate

Implementation Reference

  • Core handler function that parses input, validates parameters, executes BrunoCLI.validateEnvironment, formats output with status, masked variables, errors, and warnings, and returns MCP-formatted response.
    async handle(args: unknown): Promise<ToolResponse> {
      const params = ValidateEnvironmentSchema.parse(args);
    
      // Validate collection path and environment name
      const validation = await validateToolParameters({
        collectionPath: params.collectionPath,
        requestName: params.environmentName // Reuse request validation for env name
      });
    
      if (!validation.valid) {
        throw new McpError(
          ErrorCode.InvalidParams,
          `Invalid parameters: ${validation.errors.join(', ')}`
        );
      }
    
      try {
        const result = await this.brunoCLI.validateEnvironment(
          params.collectionPath,
          params.environmentName
        );
    
        const output: string[] = [];
        output.push(`=== Environment Validation: ${params.environmentName} ===`);
        output.push('');
    
        if (!result.exists) {
          output.push(`❌ Status: Not Found`);
          output.push('');
          output.push('Errors:');
          result.errors.forEach((err: string) => output.push(`  • ${err}`));
        } else if (!result.valid) {
          output.push(`❌ Status: Invalid`);
          output.push('');
          output.push('Errors:');
          result.errors.forEach((err: string) => output.push(`  • ${err}`));
        } else {
          output.push(`✅ Status: Valid`);
          output.push('');
    
          if (result.variables && Object.keys(result.variables).length > 0) {
            output.push(`Variables: ${Object.keys(result.variables).length}`);
            output.push('');
    
            Object.entries(result.variables).forEach(([key, value]) => {
              // Mask sensitive values
              const displayValue = key.toLowerCase().includes('password') ||
                                   key.toLowerCase().includes('secret') ||
                                   key.toLowerCase().includes('token') ||
                                   key.toLowerCase().includes('key')
                ? '*** (masked)'
                : value;
              output.push(`  ${key}: ${displayValue}`);
            });
            output.push('');
          }
        }
    
        if (result.warnings.length > 0) {
          output.push('Warnings:');
          result.warnings.forEach((warn: string) => output.push(`  ⚠️  ${warn}`));
        }
    
        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 environment: ${maskedError}`
        );
      }
    }
  • Zod schema for validating the tool's input parameters: collectionPath and environmentName.
    const ValidateEnvironmentSchema = z.object({
      collectionPath: z.string().describe('Path to the Bruno collection'),
      environmentName: z.string().describe('Name of the environment to validate')
    });
  • src/index.ts:295-295 (registration)
    Registers the ValidateEnvironmentHandler instance with the ToolRegistry for tool execution dispatching.
    this.toolRegistry.register(new ValidateEnvironmentHandler(this.brunoCLI));
  • Tool definition in the TOOLS array including name, description, and inputSchema for MCP tool listing.
    {
      name: 'bruno_validate_environment',
      description: 'Validate an environment file in a Bruno collection',
      inputSchema: {
        type: 'object',
        properties: {
          collectionPath: {
            type: 'string',
            description: 'Path to the Bruno collection'
          },
          environmentName: {
            type: 'string',
            description: 'Name of the environment to validate'
          }
        },
        required: ['collectionPath', 'environmentName']
      }
  • src/index.ts:284-298 (registration)
    The registerToolHandlers method that instantiates and registers all tool handlers including ValidateEnvironmentHandler.
    private registerToolHandlers(): void {
      const container = getContainer();
      const perfManager = container.get<PerformanceManager>(ServiceKeys.PERFORMANCE_MANAGER);
    
      // Register all tool handlers
      this.toolRegistry.register(new RunRequestHandler(this.brunoCLI));
      this.toolRegistry.register(new RunCollectionHandler(this.brunoCLI));
      this.toolRegistry.register(new ListRequestsHandler(this.brunoCLI));
      this.toolRegistry.register(new HealthCheckHandler(this.brunoCLI, this.configLoader, perfManager));
      this.toolRegistry.register(new DiscoverCollectionsHandler(this.brunoCLI));
      this.toolRegistry.register(new ListEnvironmentsHandler(this.brunoCLI));
      this.toolRegistry.register(new ValidateEnvironmentHandler(this.brunoCLI));
      this.toolRegistry.register(new GetRequestDetailsHandler(this.brunoCLI));
      this.toolRegistry.register(new ValidateCollectionHandler(this.brunoCLI));
    }

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/jcr82/bruno-mcp-server'

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