Skip to main content
Glama

rename_file

Rename files or folders using Language Server Protocol capabilities to update references across your codebase automatically.

Instructions

Rename a file or folder using LSP rename capabilities

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
oldPathYesCurrent path of the file or folder
newPathYesNew path for the file or folder
languageNoProgramming language (typescript, javascript, python, etc.)typescript

Implementation Reference

  • Core handler function that implements the logic for renaming files or directories, using filesystem operations with LSP integration for files.
    export async function renameFile(args: RenameFileArgs, clientManager: LSPClientManager) {
      const { oldPath, newPath, language = 'typescript' } = args;
      const workspaceRoot = findWorkspaceRoot(oldPath);
    
      try {
        // Check if paths exist
        await fs.access(oldPath);
    
        const isDirectory = (await fs.stat(oldPath)).isDirectory();
    
        if (isDirectory) {
          // For directories, perform file system rename and update imports
          await fs.rename(oldPath, newPath);
    
          // Find all files that might import from the renamed directory
          const references = await findDirectoryReferences(oldPath, workspaceRoot);
    
          return {
            content: [
              {
                type: 'text',
                text: `Successfully renamed directory from ${oldPath} to ${newPath}. Found ${references.length} files that may need import updates.`,
              },
            ],
          };
        } else {
          // For files, use LSP if possible, otherwise fallback to filesystem
          try {
            const client = await clientManager.getOrCreateLSPClient(language, workspaceRoot);
    
            // Open the file in LSP
            const fileContent = await fs.readFile(oldPath, 'utf-8');
            await clientManager.sendLSPNotification(client, 'textDocument/didOpen', {
              textDocument: {
                uri: `file://${oldPath}`,
                languageId: language,
                version: 1,
                text: fileContent,
              },
            });
    
            // Try to get workspace edit for file rename
            // Note: Not all LSP servers support file renaming
            await fs.rename(oldPath, newPath);
    
            return {
              content: [
                {
                  type: 'text',
                  text: `Successfully renamed file from ${oldPath} to ${newPath}`,
                },
              ],
            };
          } catch (_lspError) {
            // Fallback to filesystem rename
            await fs.rename(oldPath, newPath);
    
            return {
              content: [
                {
                  type: 'text',
                  text: `File renamed from ${oldPath} to ${newPath} (LSP rename not available, imports may need manual updates)`,
                },
              ],
            };
          }
        }
      } catch (error) {
        throw new Error(`Failed to rename: ${error instanceof Error ? error.message : String(error)}`);
      }
    }
  • src/server.ts:43-65 (registration)
    Tool registration in the ListTools handler, defining name 'rename_file', description, and input schema.
    {
      name: 'rename_file',
      description: 'Rename a file or folder using LSP rename capabilities',
      inputSchema: {
        type: 'object',
        properties: {
          oldPath: {
            type: 'string',
            description: 'Current path of the file or folder',
          },
          newPath: {
            type: 'string',
            description: 'New path for the file or folder',
          },
          language: {
            type: 'string',
            description: 'Programming language (typescript, javascript, python, etc.)',
            default: 'typescript',
          },
        },
        required: ['oldPath', 'newPath'],
      },
    },
  • src/server.ts:212-213 (registration)
    Registration of the call handler for 'rename_file' tool in the switch statement of CallToolRequest.
    case 'rename_file':
      return await renameFile(args as unknown as RenameFileArgs, this.clientManager);
  • TypeScript interface defining the input arguments for the rename_file tool.
    export interface RenameFileArgs {
      oldPath: string;
      newPath: string;
      language?: string;
    }
  • src/server.ts:5-5 (registration)
    Import of the renameFile handler function.
    import { renameFile } from './commands/renameFile.js';
Behavior2/5

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

No annotations are provided, so the description carries full burden. It mentions 'LSP rename capabilities' which hints at Language Server Protocol integration, but doesn't disclose critical behavioral traits: whether this requires specific permissions, if it's destructive (renaming typically is), what happens on failure, or any rate limits. For a mutation tool with zero annotation coverage, this is inadequate.

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?

The description is a single, efficient sentence with zero waste. It's appropriately sized and front-loaded, stating the core purpose immediately. Every word earns its place without unnecessary elaboration.

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 this is a mutation tool with no annotations and no output schema, the description is incomplete. It doesn't explain what the tool returns, error conditions, or behavioral implications. The mention of 'LSP rename capabilities' adds some context but doesn't compensate for the missing safety and response information needed for a destructive operation.

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 100%, so the schema already documents all three parameters thoroughly. The description adds no additional parameter semantics beyond what's in the schema. It doesn't explain parameter relationships, constraints, or usage patterns. Baseline 3 is appropriate when the schema does the heavy lifting.

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 clearly states the action ('rename') and resource ('file or folder'), and specifies the mechanism ('using LSP rename capabilities'). However, it doesn't explicitly differentiate from sibling tools like 'rename_symbol' or 'move_function', which appear related. The purpose is specific but lacks sibling distinction.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. With sibling tools like 'rename_symbol', 'move_function', and 'find_references', there's no indication of when this tool is appropriate versus those other options. No prerequisites, exclusions, or contextual usage information is provided.

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/sminnee/lsp-mcp'

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