44 lines
1.0 KiB
Python
44 lines
1.0 KiB
Python
from functools import cache
|
|
from pathlib import Path
|
|
from typing import Literal
|
|
|
|
from pydantic import BaseModel
|
|
from pydantic import DirectoryPath
|
|
from pydantic import Field
|
|
from pydantic_settings import BaseSettings
|
|
from pydantic_settings import SettingsConfigDict
|
|
|
|
DEFAULT_ENV_FILE = Path(".env").resolve()
|
|
_REPO_ROOT = Path(__file__).resolve().parents[2]
|
|
|
|
|
|
class Mounts(BaseModel):
|
|
docs: str = "/docs"
|
|
mcp: str = "/mcp"
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
"""Runtime settings for the HTTP MCP and docs server."""
|
|
|
|
model_config = SettingsConfigDict(
|
|
env_file=DEFAULT_ENV_FILE,
|
|
env_prefix="PERSONAL_MCP_",
|
|
extra="ignore",
|
|
)
|
|
|
|
debug: bool = False
|
|
log_level: str = "info"
|
|
mounts: Mounts = Field(default_factory=Mounts)
|
|
mcp_transport: Literal["http", "sse"] = "http"
|
|
site_dir: DirectoryPath = Field(default=_REPO_ROOT / "site")
|
|
|
|
|
|
@cache
|
|
def get_settings(**overrides) -> Settings:
|
|
return Settings(**overrides)
|
|
|
|
|
|
def refresh_settings(**overrides):
|
|
get_settings.cache_clear()
|
|
return get_settings(**overrides)
|