config.pyβ’4.63 kB
"""
MCP Stock Details Server Configuration
"""
import os
from typing import Any, Dict, List
from pydantic import Field
from pydantic_settings import BaseSettings, SettingsConfigDict
class Settings(BaseSettings):
"""Application settings with modern Pydantic configuration"""
model_config = SettingsConfigDict(
env_file=".env",
env_file_encoding="utf-8",
extra="ignore"
)
# Server Configuration
server_name: str = Field(default="mcp-stock-details", description="Server name")
server_version: str = Field(default="1.0.0", description="Server version")
debug: bool = Field(default=False, description="Debug mode")
# Database Configuration
database_url: str = Field(
default="postgresql://localhost:5432/stock_details",
description="Database connection URL"
)
redis_url: str = Field(
default="redis://localhost:6379/0",
description="Redis connection URL"
)
# External API Configuration
dart_api_key: str = Field(default="", description="DART OpenAPI key")
krx_api_key: str = Field(default="", description="KRX API key")
fnguide_api_key: str = Field(default="", description="FnGuide API key")
# Cache Configuration
cache_ttl: int = Field(default=3600, description="Cache TTL in seconds")
cache_enabled: bool = Field(default=True, description="Enable caching")
# Logging Configuration
log_level: str = Field(default="INFO", description="Logging level")
log_format: str = Field(
default="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
description="Log format string"
)
# Global settings instance
settings = Settings()
def get_settings() -> Settings:
"""Get application settings"""
return settings
def get_tools_config() -> Dict[str, Any]:
"""Get MCP tools configuration"""
return {
"get_company_overview": {
"description": "Get comprehensive company overview including basic info, business segments, and key metrics",
"parameters": {
"company_code": {
"type": "string",
"description": "Company stock code (e.g., '005930' for Samsung Electronics)"
},
"include_subsidiaries": {
"type": "boolean",
"description": "Include information about subsidiaries",
"default": False
}
}
},
"get_financial_statements": {
"description": "Get detailed financial statements and ratios",
"parameters": {
"company_code": {
"type": "string",
"description": "Company stock code"
},
"period": {
"type": "string",
"description": "Time period (1Y, 3Y, 5Y)",
"default": "3Y"
},
"statement_type": {
"type": "string",
"description": "Type of statement (all, income, balance, cashflow)",
"default": "all"
}
}
}
}
def get_logging_config() -> Dict[str, Any]:
"""Get logging configuration"""
return {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"default": {
"format": settings.log_format,
"datefmt": "%Y-%m-%d %H:%M:%S"
},
"json": {
"format": "%(asctime)s %(name)s %(levelname)s %(message)s",
"class": "pythonjsonlogger.jsonlogger.JsonFormatter"
}
},
"handlers": {
"console": {
"class": "logging.StreamHandler",
"level": settings.log_level,
"formatter": "default",
"stream": "ext://sys.stdout"
},
"file": {
"class": "logging.handlers.RotatingFileHandler",
"level": settings.log_level,
"formatter": "json",
"filename": "logs/mcp-stock-details.log",
"maxBytes": 10485760, # 10MB
"backupCount": 5
}
},
"loggers": {
"mcp_stock_details": {
"level": settings.log_level,
"handlers": ["console", "file"],
"propagate": False
}
},
"root": {
"level": settings.log_level,
"handlers": ["console"]
}
}