Skip to main content
Glama

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

TableJSON Schema
NameRequiredDescriptionDefault
nameYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • 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.
  • 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)
  • 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,
    ]
  • 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]()
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the burden. It clearly states this is a descriptive, non-destructive operation by using 'Describe'. It lists what the output covers, but does not mention error handling or behavior for invalid preset names.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Single sentence with no filler. Front-loaded with purpose and itemized aspects. Every word adds value.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the simplicity of the tool (one parameter, descriptive output) and presence of an output schema, the description adequately covers the tool's function. However, it could mention that the preset must exist or reference list_presets for discoverability.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must clarify the parameter. It states 'named preset', indicating the 'name' parameter refers to a preset identifier, but it does not specify expected format (e.g., exact match) or relationship to other tools.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The verb 'Describe' and resource 'named preset' is clear. It lists specific aspects of a preset (exclude names count, exclude patterns, etc.), which distinguishes it from siblings like 'list_presets' that list available presets without explaining their effects.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies use when understanding a specific preset's details, but it does not explicitly state when to use this tool versus alternatives like 'list_presets' or 'generate_pyobfus_config'. No exclusions or prerequisites are mentioned.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

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/zhurong2020/pyobfus'

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