Files
local-mcp/app/config.py
2026-03-27 03:58:57 +08:00

63 lines
1.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
app/config.py
Runtime configuration loaded from environment variables with sensible defaults.
"""
from __future__ import annotations
import os
from dataclasses import dataclass, field
@dataclass
class Settings:
# Server
host: str = "0.0.0.0"
http_port: int = 8000
# Database
db_path: str = "data/local_mcp.sqlite3"
# Logging
log_level: str = "INFO"
# MCP / queue behaviour (runtime-editable values are stored in DB; these are defaults for first run)
default_wait_seconds: int = 10
default_empty_response: str = ""
agent_stale_after_seconds: int = 30
# MCP server name
mcp_server_name: str = "local-mcp"
# MCP transport — stateless=True means no session IDs, survives server restarts.
# Set MCP_STATELESS=false to use stateful sessions (needed for multi-turn MCP flows).
mcp_stateless: bool = True
def _parse_bool(value: str, default: bool) -> bool:
if value.lower() in ("1", "true", "yes", "on"):
return True
if value.lower() in ("0", "false", "no", "off"):
return False
return default
def load_settings() -> Settings:
"""Load settings from environment variables, falling back to defaults."""
return Settings(
host=os.getenv("HOST", "0.0.0.0"),
http_port=int(os.getenv("HTTP_PORT", "8000")),
db_path=os.getenv("DB_PATH", "data/local_mcp.sqlite3"),
log_level=os.getenv("LOG_LEVEL", "INFO"),
default_wait_seconds=int(os.getenv("DEFAULT_WAIT_SECONDS", "10")),
default_empty_response=os.getenv("DEFAULT_EMPTY_RESPONSE", ""),
agent_stale_after_seconds=int(os.getenv("AGENT_STALE_AFTER_SECONDS", "30")),
mcp_server_name=os.getenv("MCP_SERVER_NAME", "local-mcp"),
mcp_stateless=_parse_bool(os.getenv("MCP_STATELESS", "true"), default=True),
)
# Singleton imported and used throughout the app
settings: Settings = load_settings()