"""Configuration for Standards MCP Server."""
from pathlib import Path
from pydantic_settings import BaseSettings, SettingsConfigDict
from pydantic import Field
class ServerConfig(BaseSettings):
"""Standards MCP Server configuration.
Configuration values can be set via environment variables.
"""
model_config = SettingsConfigDict(
env_file=".env",
env_file_encoding="utf-8",
extra="ignore"
)
# Server identity
server_name: str = Field(default="standards-mcp-server", alias="MCP_SERVER_NAME")
server_version: str = Field(default="0.1.0", alias="MCP_SERVER_VERSION")
# Transport
transport: str = Field(default="stdio", alias="MCP_TRANSPORT")
port: int = Field(default=8080, alias="MCP_PORT")
host: str = Field(default="0.0.0.0", alias="MCP_HOST")
# Logging
log_level: str = Field(default="INFO", alias="MCP_LOG_LEVEL")
# Standards location
standards_path: Path = Field(
default=Path("docs/standards"),
alias="STANDARDS_PATH"
)
# Reference implementations location
reference_implementations_path: Path = Field(
default=Path("reference-implementations"),
alias="REFERENCE_IMPLEMENTATIONS_PATH"
)
# OpenTelemetry
otel_enabled: bool = Field(default=True, alias="OTEL_ENABLED")
otel_endpoint: str | None = Field(default=None, alias="OTEL_EXPORTER_OTLP_ENDPOINT")
otel_service_name: str = Field(default="standards-mcp-server", alias="OTEL_SERVICE_NAME")
def get_standards_root(self) -> Path:
"""Get the absolute path to standards directory."""
if self.standards_path.is_absolute():
return self.standards_path
# Try relative to current working directory
cwd_path = Path.cwd() / self.standards_path
if cwd_path.exists():
return cwd_path
# Try relative to this file (for development)
file_path = Path(__file__).parent.parent.parent.parent / self.standards_path
if file_path.exists():
return file_path
return self.standards_path
def get_reference_implementations_root(self) -> Path:
"""Get the absolute path to reference implementations directory."""
if self.reference_implementations_path.is_absolute():
return self.reference_implementations_path
# Try relative to current working directory
cwd_path = Path.cwd() / self.reference_implementations_path
if cwd_path.exists():
return cwd_path
# Try relative to this file (for development)
file_path = Path(__file__).parent.parent.parent.parent / self.reference_implementations_path
if file_path.exists():
return file_path
return self.reference_implementations_path
def get_config() -> ServerConfig:
"""Get server configuration singleton."""
return ServerConfig()