Skip to main content
Glama

MCP Learning Project

by BerdTan
config.pyโ€ข5.98 kB
""" Configuration management for the MCP Learning Project. This module handles all application configuration including environment variables, database settings, server settings, and module configurations. """ import os from pathlib import Path from typing import List, Optional from pydantic import BaseSettings, Field, validator class Settings(BaseSettings): """ Application settings loaded from environment variables and configuration files. This class uses Pydantic for automatic validation and type conversion. """ # Database Configuration database_url: str = Field( default="sqlite:///./data/database/mcp_learning.db", description="Database connection URL" ) database_echo: bool = Field( default=False, description="Enable SQLAlchemy echo mode for debugging" ) # Server Configuration host: str = Field( default="0.0.0.0", description="Server host address" ) port: int = Field( default=8000, description="Server port number" ) debug: bool = Field( default=True, description="Enable debug mode" ) log_level: str = Field( default="INFO", description="Logging level" ) # Security Configuration secret_key: str = Field( default="your-secret-key-here-change-this-in-production", description="Secret key for JWT tokens and encryption" ) api_key_header: str = Field( default="X-API-Key", description="HTTP header name for API key authentication" ) # Module Configuration module_auto_reload: bool = Field( default=True, description="Enable automatic module reloading" ) module_timeout: int = Field( default=30, description="Module execution timeout in seconds" ) # Web Interface Configuration web_enabled: bool = Field( default=True, description="Enable web interface" ) web_host: str = Field( default="0.0.0.0", description="Web interface host address" ) web_port: int = Field( default=3000, description="Web interface port number" ) cors_origins: List[str] = Field( default=["http://localhost:3000"], description="Allowed CORS origins" ) # External API Configuration openai_api_key: Optional[str] = Field( default=None, description="OpenAI API key for AI features" ) weather_api_key: Optional[str] = Field( default=None, description="Weather API key for weather features" ) # File Storage Configuration upload_dir: str = Field( default="./data/uploads", description="Directory for file uploads" ) max_file_size: int = Field( default=10485760, # 10MB description="Maximum file size in bytes" ) # Logging Configuration log_file: str = Field( default="./data/logs/app.log", description="Log file path" ) log_format: str = Field( default="json", description="Log format (json or text)" ) @validator("database_url") def validate_database_url(cls, v: str) -> str: """Validate database URL format.""" if not v: raise ValueError("Database URL cannot be empty") return v @validator("port", "web_port") def validate_port(cls, v: int) -> int: """Validate port number range.""" if not (1 <= v <= 65535): raise ValueError("Port must be between 1 and 65535") return v @validator("log_level") def validate_log_level(cls, v: str) -> str: """Validate log level.""" valid_levels = ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] if v.upper() not in valid_levels: raise ValueError(f"Log level must be one of: {valid_levels}") return v.upper() @validator("upload_dir") def validate_upload_dir(cls, v: str) -> str: """Ensure upload directory exists.""" upload_path = Path(v) upload_path.mkdir(parents=True, exist_ok=True) return str(upload_path.absolute()) class Config: """Pydantic configuration.""" env_file = ".env" env_file_encoding = "utf-8" case_sensitive = False # Global settings instance _settings: Optional[Settings] = None def get_settings() -> Settings: """ Get the global settings instance. Returns: Settings: The application settings Note: This function creates a singleton instance of Settings to ensure consistent configuration across the application. """ global _settings if _settings is None: _settings = Settings() return _settings def reload_settings() -> Settings: """ Reload settings from environment variables and configuration files. Returns: Settings: The reloaded application settings Note: This function is useful for testing or when you need to reload configuration without restarting the application. """ global _settings _settings = Settings() return _settings # Create necessary directories def create_directories() -> None: """Create necessary directories for the application.""" settings = get_settings() # Create data directories data_dirs = [ Path("./data"), Path("./data/database"), Path("./data/logs"), Path("./data/uploads"), Path("./data/cache"), ] for dir_path in data_dirs: dir_path.mkdir(parents=True, exist_ok=True) # Initialize directories when module is imported create_directories()

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/BerdTan/mcpharness'

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