explain_preset
Explains the changes a named preset applies, including exclude names count, exclude patterns, preserve_param_names, and docstring handling settings.
Instructions
Describe what a named preset changes: exclude names count, exclude patterns, preserve_param_names, docstring handling.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- pyobfus_mcp/pyobfus_mcp/tools.py:184-223 (handler)The main implementation of explain_preset. Accepts a preset name, calls ObfuscationConfig.get_preset(name) to load the preset config, and returns a dict with status, preset name, level, exclude_names_count, exclude_patterns, preserve_param_names, remove_docstrings, string_encoding, and an ai_hint with the CLI command to apply the preset.
def explain_preset(name: str) -> Dict[str, Any]: """Describe what a named preset changes compared to balanced. Returns the concrete exclude_names count, preserve_param_names, remove_docstrings flag, and any framework-specific exclude patterns so an AI agent can explain the preset to the user before applying it. Args: name: Preset name (e.g. "fastapi", "pydantic", "safe"). Returns: Dict with keys: status, preset, level, exclude_names_count, exclude_patterns, preserve_param_names, remove_docstrings, ai_hint. """ try: from pyobfus.config import ObfuscationConfig except ImportError as e: return _error("PyobfusNotInstalled", str(e), "pip install pyobfus") try: cfg = ObfuscationConfig.get_preset(name) except ValueError as e: return _error("UnknownPreset", str(e), "Call list_presets to see valid names.") return { "status": "success", "preset": name.lower(), "level": cfg.level, "exclude_names_count": len(cfg.exclude_names), "exclude_patterns": list(cfg.exclude_patterns), "preserve_param_names": cfg.preserve_param_names, "remove_docstrings": cfg.remove_docstrings, "string_encoding": cfg.string_encoding, "ai_hint": ( f"Apply with: pyobfus src/ -o dist/ --preset {name.lower()}" if cfg.level == "community" else f"'{name}' is a Pro preset. Start a free trial: pyobfus-trial start" ), } - The docstring of explain_preset defines the input (name: str) and output schema. Input: a preset name string. Output: a dict with keys: status, preset, level, exclude_names_count, exclude_patterns, preserve_param_names, remove_docstrings, ai_hint.
def explain_preset(name: str) -> Dict[str, Any]: """Describe what a named preset changes compared to balanced. Returns the concrete exclude_names count, preserve_param_names, remove_docstrings flag, and any framework-specific exclude patterns so an AI agent can explain the preset to the user before applying it. Args: name: Preset name (e.g. "fastapi", "pydantic", "safe"). Returns: Dict with keys: status, preset, level, exclude_names_count, exclude_patterns, preserve_param_names, remove_docstrings, ai_hint. - pyobfus_mcp/pyobfus_mcp/server.py:111-119 (registration)MCP tool registration for explain_preset. Uses @app.tool(name='explain_preset') with a description, and the handler function _explain delegates to the pure implementation explain_preset(name).
@app.tool( name="explain_preset", description=( "Describe what a named preset changes: exclude names count, " "exclude patterns, preserve_param_names, docstring handling." ), ) def _explain(name: str) -> Dict[str, Any]: return explain_preset(name) - pyobfus_mcp/pyobfus_mcp/server.py:136-144 (registration)Backwards-compat export: explain_preset is included in the tool_functions list for test harnesses.
# Backwards-compat export: some test harnesses look for a `tool_functions` # list. Provide one that enumerates the underlying callable implementations. tool_functions = [ check_obfuscation_risks, generate_pyobfus_config, unmap_stack_trace, list_presets, explain_preset, ] - pyobfus/config.py:584-625 (helper)ObfuscationConfig.get_preset(name) resolves a preset name to an ObfuscationConfig instance by looking up the name in a dictionary of classmethod factory functions and calling the matching one.
@classmethod def get_preset(cls, name: str) -> "ObfuscationConfig": """ Get a preset configuration by name. Args: name: Preset name. Available: - Community: safe, balanced, aggressive - Framework: fastapi, django, flask, pydantic, click, sqlalchemy - Pro: trial, commercial, library, maximum Returns: ObfuscationConfig with preset settings Raises: ValueError: If preset name is unknown """ presets: Dict[str, Callable[[], "ObfuscationConfig"]] = { # Community "safe": cls.preset_safe, "balanced": cls.preset_balanced, "aggressive": cls.preset_aggressive, # Framework-aware (community, no Pro required) "fastapi": cls.preset_fastapi, "django": cls.preset_django, "flask": cls.preset_flask, "pydantic": cls.preset_pydantic, "click": cls.preset_click, "sqlalchemy": cls.preset_sqlalchemy, # Pro "trial": cls.preset_trial, "commercial": cls.preset_commercial, "library": cls.preset_library, "maximum": cls.preset_maximum, } name_lower = name.lower() if name_lower not in presets: available = ", ".join(sorted(presets.keys())) raise ValueError(f"Unknown preset '{name}'. Available presets: {available}") return presets[name_lower]()