Skip to main content
Glama

list_refactorings

Read-onlyIdempotent

Browse available code refactoring patterns by language or category to improve software structure and maintainability.

Instructions

List available refactorings with their parameter contracts.

Returns the catalog of available refactorings from all enabled backends, optionally filtered by language and/or category.

Args: language: Filter by language (e.g., 'python'). If not specified, returns all. category: Filter by Fowler category (e.g., 'composing_methods')

Returns: TOON-formatted string containing refactoring specifications.

Categories: - composing_methods: Extract/inline methods, variables - moving_features: Move methods/fields between classes - organizing_data: Encapsulation, type codes - simplifying_conditionals: Guard clauses, polymorphism - simplifying_method_calls: Rename, add/remove parameters - dealing_with_generalization: Pull up/push down, inheritance

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
languageNo
categoryNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The core logic implementation of the `list_refactorings` tool, which collects and filters refactoring specifications from available adapters.
    async def list_refactorings(params: ListRefactoringsInput) -> str:
        """List available refactorings with their parameter contracts.
    
        Returns the catalog of available refactorings from all enabled backends,
        optionally filtered by language and/or category.
    
        Args:
            params: Input parameters for filtering
    
        Returns:
            TOON-formatted string with refactoring specifications
        """
        # Get adapters based on language filter
        if params.language:
            adapter = get_adapter(params.language)
            if adapter is None:
                return encode_toon({
                    "error": f"Language '{params.language}' not available",
                    "available_languages": list(get_available_adapters().keys()),
                })
            adapters = {params.language: adapter}
        else:
            adapters = get_available_adapters()
    
        if not adapters:
            return encode_toon({
                "error": "No language backends available",
                "hint": "Install molting-cli for Python support: pip install molting-cli",
            })
    
        # Collect refactorings from all adapters
        all_refactorings: list[dict[str, Any]] = []
    
        for language, adapter in adapters.items():
            for spec in adapter.list_refactorings():
                # Apply category filter
                if params.category:
                    try:
                        filter_category = RefactoringCategory(params.category)
                        if spec.category != filter_category:
                            continue
                    except ValueError:
                        return encode_toon({
                            "error": f"Invalid category: '{params.category}'",
                            "valid_categories": [c.value for c in RefactoringCategory],
                        })
    
                # Format parameters as comma-separated string
                param_names = ",".join(p.name for p in spec.params if p.required)
                optional_params = [p.name for p in spec.params if not p.required]
                if optional_params:
                    param_names += f" [optional: {','.join(optional_params)}]"
    
                all_refactorings.append({
                    "name": spec.name,
                    "language": language,
                    "category": spec.category.value,
                    "params": param_names,
                    "description": spec.description,
                })
    
        # Build response
        response: dict[str, Any] = {
            "total": len(all_refactorings),
            "languages": list(adapters.keys()),
        }
    
        if params.category:
            response["filtered_by_category"] = params.category
    
        response["refactorings"] = all_refactorings
    
        return encode_toon(response)
  • Input validation schema for the `list_refactorings` tool using Pydantic.
    class ListRefactoringsInput(BaseModel):
        """Input for listing refactorings."""
    
        model_config = ConfigDict(str_strip_whitespace=True)
    
        language: str | None = Field(
            default=None,
            description="Filter by language (e.g., 'python'). If not specified, returns all.",
        )
        category: str | None = Field(
            default=None,
            description="Filter by Fowler category (e.g., 'composing_methods')",
        )
  • Registration of the `list_refactorings` tool within the MCP server definition.
    @mcp.tool(
        name="list_refactorings",
        annotations={
            "title": "List Available Refactorings",
            "readOnlyHint": True,
            "destructiveHint": False,
            "idempotentHint": True,
            "openWorldHint": False,
        },
    )
    async def list_refactorings(
        language: Optional[str] = None,
        category: Optional[str] = None,
    ) -> str:
        """List available refactorings with their parameter contracts.
    
        Returns the catalog of available refactorings from all enabled backends,
        optionally filtered by language and/or category.
    
        Args:
            language: Filter by language (e.g., 'python'). If not specified, returns all.
            category: Filter by Fowler category (e.g., 'composing_methods')
    
        Returns:
            TOON-formatted string containing refactoring specifications.
    
        Categories:
            - composing_methods: Extract/inline methods, variables
            - moving_features: Move methods/fields between classes
            - organizing_data: Encapsulation, type codes
            - simplifying_conditionals: Guard clauses, polymorphism
            - simplifying_method_calls: Rename, add/remove parameters
            - dealing_with_generalization: Pull up/push down, inheritance
        """
        params = ListRefactoringsInput(language=language, category=category)
        return await _list_refactorings(params)

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/marshally/mcp-refactoring'

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