"""CLI utilities that don't require MCP dependencies."""
import json
from pathlib import Path
from typing import Optional
from .config import Config, ConfigManager
def create_example_config(path: str) -> None:
"""Create an example configuration file."""
try:
config_path = Path(path)
config = Config()
ConfigManager.save_config(config, config_path)
print(f"Example configuration created at: {config_path}")
# Add comments to the config file
with open(config_path, 'r') as f:
content = f.read()
commented_content = '''// File System MCP Server Configuration
// This file configures the behavior of the MCP server
{
// Directory where backup files are stored
"backup_directory": "./.mcp_backups",
// Maximum file size for read operations (in bytes)
"max_file_size": 10485760,
// Maximum recursion depth for directory listing
"max_recursion_depth": 10,
// Allowed file extensions (null = all allowed)
"allowed_extensions": null,
// Protected paths that cannot be modified
"protected_paths": [
"/etc",
"/usr",
"/bin",
"/System"
],
// Enable automatic backup creation
"enable_backups": true,
// Logging level
"log_level": "INFO"
}'''
# Write the commented version
with open(config_path, 'w') as f:
f.write(commented_content)
print("\nConfiguration options:")
print("- backup_directory: Where backup files are stored")
print("- max_file_size: Maximum file size for read operations")
print("- max_recursion_depth: Limit for recursive directory listing")
print("- allowed_extensions: Restrict file types (null = all allowed)")
print("- protected_paths: Directories that cannot be modified")
print("- enable_backups: Whether to create backups before modifications")
print("- log_level: Logging verbosity (DEBUG, INFO, WARNING, ERROR, CRITICAL)")
except Exception as e:
print(f"Error creating example config: {e}")
raise
def validate_config(config_path: Optional[str]) -> None:
"""Validate configuration and report issues."""
try:
config = ConfigManager.load_config(config_path)
issues = ConfigManager.validate_paths(config)
print("Configuration validation results:")
print(f"Config file: {config_path or 'config.json'}")
print(f"Backup directory: {config.backup_directory}")
print(f"Max file size: {config.max_file_size:,} bytes")
print(f"Max recursion depth: {config.max_recursion_depth}")
print(f"Allowed extensions: {config.allowed_extensions or 'All'}")
print(f"Protected paths: {len(config.protected_paths)} paths")
print(f"Backups enabled: {config.enable_backups}")
print(f"Log level: {config.log_level}")
if issues:
print("\nIssues found:")
for issue in issues:
print(f" ⚠️ {issue}")
return False
else:
print("\n✅ Configuration is valid")
return True
except Exception as e:
print(f"❌ Configuration validation failed: {e}")
raise