Skip to main content
Glama

safe_rename

Rename Python symbols across files with type safety. Use apply=True to execute changes after verification.

Instructions

Rename symbol across project. Set apply=True to execute.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYes
lineYes
columnYes
new_nameYes
applyNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The 'safe_rename' tool implementation which renames a symbol in a file and optionally applies the changes. It is decorated with @mcp.tool().
    async def safe_rename(
        file_path: str, line: int, column: int, new_name: str, apply: bool = False
    ) -> str:
        """Rename symbol across project. Set apply=True to execute."""
        client = _get_client()
    
        path = Path(file_path).resolve()
        if not path.exists():
            return _error(f"File not found: {file_path}")
    
        try:
            await client.open_document(path)
    
            workspace_edit = await client.rename_symbol(
                path, line - 1, column - 1, new_name
            )
    
            if not workspace_edit:
                return _not_found(f"Cannot rename at {path.name}:{line}:{column}")
    
            all_edits = workspace_edit.get_all_edits()
            total_edits = sum(len(e) for e in all_edits.values())
    
            if not apply:
                preview = []
                for uri, edits in all_edits.items():
                    edit_path = _uri_to_path(uri)
                    for e in edits:
                        text_preview = e.new_text[:80].replace("\n", "\\n") if e.new_text else "(delete)"
                        preview.append({
                            "file": edit_path.name,
                            "line": e.range.start.line + 1,
                            "column": e.range.start.character + 1,
                            "new_text": text_preview
                        })
                return _ok({
                    "preview": True,
                    "new_name": new_name,
                    "edits_count": total_edits,
                    "files_count": len(all_edits),
                    "edits": preview
                })
    
            applied_files = []
            for uri, edits in all_edits.items():
                file_to_edit = _uri_to_path(uri)
                if file_to_edit.exists():
                    new_content = _apply_edits_to_file(file_to_edit, edits)
                    file_to_edit.write_text(new_content, encoding="utf-8")
                    applied_files.append(file_to_edit.name)
    
            return _ok({
                "applied": True,
                "new_name": new_name,
                "modified_files": applied_files
            })
    
        except Exception as e:
            return _error(str(e))
Behavior3/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It effectively communicates the dry-run behavior (requiring apply=True to execute), but fails to explain what 'safe' implies (atomicity, reversibility, conflict detection) or what the output contains when previewing vs applying.

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

Conciseness4/5

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

The description is extremely concise with two short sentences and zero redundancy. The information is front-loaded with the action first. However, given the complexity (5 parameters, 0% schema coverage), this brevity crosses into under-specification.

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

Completeness2/5

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

Given five parameters with zero schema descriptions and no annotations, the description is insufficient. It documents only one optional parameter (apply) while leaving four required parameters (file_path, line, column, new_name) undocumented, creating major operational gaps for an agent attempting to invoke the tool.

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

Parameters2/5

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

Schema description coverage is 0%, requiring the description to compensate. While it clarifies the 'apply' parameter's purpose (execution toggle), it completely omits semantic context for the other four parameters (file_path, line, column, new_name), leaving critical required inputs undocumented.

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

Purpose4/5

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

The description uses a specific verb ('Rename') and clear resource scope ('symbol across project'), accurately conveying the tool's purpose. However, it does not explicitly differentiate this tool from siblings like 'apply_code_action' or 'get_edit_preview' that might also perform refactoring operations.

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 provides critical guidance that 'apply=True' is required to execute, revealing a dry-run vs execution pattern. However, it lacks explicit guidance on when to choose this tool over alternatives like 'apply_code_action' or prerequisites such as ensuring the file exists in the project.

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/qinsehm1128/mcp-ty'

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