config.pyโข1.5 kB
"""Configuration utilities for POEditor MCP server."""
import os
from dataclasses import dataclass
from typing import Optional
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
@dataclass
class Config:
"""Configuration settings for the POEditor MCP server."""
# POEditor API settings
poeditor_api_token: str
poeditor_api_url: str
# MCP Server settings
server_name: str
version: str
# General settings
log_level: str
default_export_format: str
max_retries: int
request_timeout: int
def get_config() -> Config:
"""Get configuration from environment variables."""
return Config(
poeditor_api_token=os.getenv("POEDITOR_API_TOKEN", ""),
poeditor_api_url=os.getenv("POEDITOR_API_URL", "https://api.poeditor.com/v2/"),
server_name=os.getenv("MCP_SERVER_NAME", "poeditor-mcp"),
version=os.getenv("MCP_SERVER_VERSION", "1.0.0"),
log_level=os.getenv("LOG_LEVEL", "INFO"),
default_export_format=os.getenv("DEFAULT_EXPORT_FORMAT", "json"),
max_retries=int(os.getenv("MAX_RETRIES", "3")),
request_timeout=int(os.getenv("REQUEST_TIMEOUT", "30"))
)
def validate_config(config: Config) -> None:
"""Validate that required configuration is present."""
if not config.poeditor_api_token:
raise ValueError("POEDITOR_API_TOKEN is required")
if not config.poeditor_api_url:
raise ValueError("POEDITOR_API_URL is required")