Skip to content

Conversation

nmveeresh
Copy link
Collaborator

@nmveeresh nmveeresh commented Sep 24, 2025

PR Summary: Enhanced Configuration Validation and Schema Export

Epic / Issue - #285

Overview

This PR implements comprehensive configuration validation and schema export capabilities for MCP Gateway. It provides operators with machine-readable configuration metadata and enforces stronger runtime validation for environment inputs, surfacing actionable errors early.


Key Changes

1. JSON Schema Export (mcpgateway/config.py)

  • Added generate_settings_schema() function to export the Pydantic model schema.
  • Enhanced CLI with --schema flag to emit machine-readable configuration metadata.
  • Enables automated validation in CI/CD pipelines.

2. Strengthened Field Validation

  • Replaced string fields with Literal types for finite option sets (e.g., log_level, cache_type, transport_type).
  • Added HttpUrl validation for URL fields (APP_DOMAIN, FEDERATION_PEERS).
  • Implemented PositiveInt constraints for numeric ranges (e.g., PORT: 1-65535).
  • Added SecretStr for sensitive fields to prevent accidental logging.
  • Enhanced validators with clear error messages to stop misconfigured environments early.

3. Dedicated Environment Validation CLI (mcpgateway/scripts/validate_env.py)

  • Standalone validation script with detection of weak/default secrets and other security warnings.
  • Integrated into existing make check-env workflow.
  • Supports validation of custom .env file paths.
  • Provides actionable error messages with field-specific details.

4. Enhanced Makefile Integration

  • Updated make check-env to use the new validation script for .env.example.
  • Added make check-env-dev for validating development .env files.
  • Fully integrated validation into existing developer workflows.

Testing & Documentation

  • Unit tests cover:
    • Schema export
    • CLI environment validation (valid/invalid cases)
    • Field-specific validation (URLs, enums, numeric ranges, secrets)
  • Documentation added in docs/docs/operations/config-validation.md with usage examples and best practices.

@nmveeresh nmveeresh marked this pull request as ready for review September 25, 2025 07:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant