Skip to main content
Glama
config.py3.08 kB
""" 配置管理模块 处理配置文件加载和验证 """ import json import os import logging from pathlib import Path from typing import Dict, Any, List class ConfigManager: """配置管理器""" def __init__(self, config_path: str = None): self.config_path = config_path or os.getenv('EXCEL_MCP_CONFIG', 'config.json') self.config = self._load_config() def _load_config(self) -> Dict[str, Any]: """加载配置文件""" try: with open(self.config_path, 'r', encoding='utf-8') as f: config = json.load(f) return config except FileNotFoundError: logging.warning(f"配置文件 {self.config_path} 不存在,使用默认配置") return self._get_default_config() except json.JSONDecodeError as e: logging.error(f"配置文件解析错误: {e}") return self._get_default_config() def _get_default_config(self) -> Dict[str, Any]: """获取默认配置""" return { "server": { "name": "excel-mcp", "version": "1.0.0", "transport": "stdio" }, "excel": { "max_file_size": "100MB", "supported_formats": [".xlsx", ".xls", ".csv"], "backup_enabled": True, "temp_dir": "./temp" }, "security": { "allowed_paths": ["./data", "~/Documents", "~/Desktop"], "forbidden_extensions": [".exe", ".bat", ".cmd"], "max_memory_usage": "512MB" }, "logging": { "level": "INFO", "file": "./logs/excel_mcp.log", "max_size": "10MB", "backup_count": 5 } } def get(self, key: str, default: Any = None) -> Any: """获取配置值""" keys = key.split('.') value = self.config for k in keys: if isinstance(value, dict) and k in value: value = value[k] else: return default return value def get_allowed_paths(self) -> List[str]: """获取允许访问的路径列表""" paths = self.get('security.allowed_paths', []) # 展开用户目录 expanded_paths = [] for path in paths: expanded_path = Path(path).expanduser().resolve() expanded_paths.append(str(expanded_path)) return expanded_paths def get_supported_formats(self) -> List[str]: """获取支持的文件格式""" return self.get('excel.supported_formats', ['.xlsx', '.xls']) def is_backup_enabled(self) -> bool: """是否启用备份""" return self.get('excel.backup_enabled', True) def get_temp_dir(self) -> Path: """获取临时目录""" temp_dir = Path(self.get('excel.temp_dir', './temp')) temp_dir.mkdir(exist_ok=True) return temp_dir

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/xuhongxin/excel-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server