"""Configuration management for the Tool Search MCP Server."""
import os
from typing import Optional
from dotenv import load_dotenv
# Load environment variables from .env file
load_dotenv()
class Config:
"""Server configuration loaded from environment variables."""
# Authentication
API_KEY: Optional[str] = os.getenv("API_KEY")
# Search settings
EMBEDDING_MODEL: str = os.getenv("EMBEDDING_MODEL", "all-MiniLM-L6-v2")
MAX_SEARCH_RESULTS: int = int(os.getenv("MAX_SEARCH_RESULTS", "5"))
REGEX_PATTERN_MAX_LENGTH: int = int(os.getenv("REGEX_PATTERN_MAX_LENGTH", "200"))
# Server settings
PORT: int = int(os.getenv("PORT", "8000"))
HOST: str = os.getenv("HOST", "0.0.0.0")
STDIO_MODE_ONLY: bool = os.getenv("STDIO_MODE_ONLY", "false").lower() == "true"
# BM25 tuning parameters
BM25_K1: float = float(os.getenv("BM25_K1", "0.9"))
BM25_B: float = float(os.getenv("BM25_B", "0.4"))
# Heroku detection
@classmethod
def is_heroku(cls) -> bool:
"""Check if running on Heroku."""
return os.getenv("DYNO") is not None
@classmethod
def is_one_off_dyno(cls) -> bool:
"""Check if running as a one-off Heroku dyno."""
dyno = os.getenv("DYNO", "")
return dyno.startswith("run.")
# Global config instance
config = Config()