46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
from typing import Literal
|
|
|
|
from pydantic import Field
|
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
|
|
_ENV_FILE = ".env"
|
|
|
|
|
|
class DatabaseConfig(BaseSettings):
|
|
model_config = SettingsConfigDict(env_prefix="DB_", env_file=_ENV_FILE, extra="ignore")
|
|
|
|
host: str = "127.0.0.1"
|
|
port: int = 3306
|
|
user: str = "root"
|
|
password: str = ""
|
|
database: str = ""
|
|
pool_min: int = 1
|
|
pool_max: int = 10
|
|
connect_timeout: int = 30
|
|
|
|
|
|
class QueryConfig(BaseSettings):
|
|
model_config = SettingsConfigDict(env_prefix="QUERY_", env_file=_ENV_FILE, extra="ignore")
|
|
|
|
max_rows: int = 1000
|
|
timeout_seconds: int = 30
|
|
allow_write: bool = False
|
|
|
|
|
|
class ServerConfig(BaseSettings):
|
|
model_config = SettingsConfigDict(env_prefix="MCP_", env_file=_ENV_FILE, extra="ignore")
|
|
|
|
transport: Literal["stdio", "http"] = "stdio"
|
|
host: str = "127.0.0.1"
|
|
port: int = 8000
|
|
# LOG_LEVEL has no MCP_ prefix so it's declared with an explicit alias
|
|
log_level: str = Field(default="INFO", validation_alias="LOG_LEVEL")
|
|
|
|
|
|
class Config(BaseSettings):
|
|
model_config = SettingsConfigDict(env_file=_ENV_FILE, extra="ignore")
|
|
|
|
database: DatabaseConfig = Field(default_factory=DatabaseConfig)
|
|
query: QueryConfig = Field(default_factory=QueryConfig)
|
|
server: ServerConfig = Field(default_factory=ServerConfig)
|