Skip to main content
Glama
PWalaGov

Enhanced Directory Context MCP Server

by PWalaGov

rename_file

Rename or move files by specifying old and new paths; optionally overwrite existing files. Part of the Enhanced Directory Context MCP Server for advanced file management operations.

Instructions

Rename or move a file

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
new_pathYesNew file path
old_pathYesCurrent file path
overwriteNoOverwrite if destination exists

Implementation Reference

  • The core handler function that performs the file rename/move operation using fs.rename, including existence checks, directory creation, and overwrite handling.
    async handleRenameFile(args) { const { old_path, new_path, overwrite = false } = args; const oldFullPath = path.resolve(this.workingDirectory, old_path); const newFullPath = path.resolve(this.workingDirectory, new_path); try { // Check if source exists await fs.access(oldFullPath); // Check if destination exists try { await fs.access(newFullPath); if (!overwrite) { throw new Error('Destination file already exists. Set overwrite=true to replace it.'); } } catch (error) { // Destination doesn't exist, which is fine } // Ensure destination directory exists const destDir = path.dirname(newFullPath); await fs.mkdir(destDir, { recursive: true }); // Rename/move file await fs.rename(oldFullPath, newFullPath); return { content: [ { type: 'text', text: `File renamed/moved: ${old_path} → ${new_path}`, }, ], }; } catch (error) { throw new McpError(ErrorCode.InternalError, `Failed to rename file: ${error.message}`); } }
  • server.js:295-317 (registration)
    Registers the 'rename_file' tool in the ListToolsRequestSchema response, including name, description, and input schema.
    { name: 'rename_file', description: 'Rename or move a file', inputSchema: { type: 'object', properties: { old_path: { type: 'string', description: 'Current file path', }, new_path: { type: 'string', description: 'New file path', }, overwrite: { type: 'boolean', description: 'Overwrite if destination exists', default: false, }, }, required: ['old_path', 'new_path'], }, },
  • Input schema defining parameters for the rename_file tool: old_path (required), new_path (required), overwrite (optional boolean).
    inputSchema: { type: 'object', properties: { old_path: { type: 'string', description: 'Current file path', }, new_path: { type: 'string', description: 'New file path', }, overwrite: { type: 'boolean', description: 'Overwrite if destination exists', default: false, }, }, required: ['old_path', 'new_path'], },
  • server.js:485-486 (registration)
    Tool dispatch in the CallToolRequestSchema handler switch statement.
    case 'rename_file': return await this.handleRenameFile(args);
  • Invocation of handleRenameFile within the batch_file_operations tool.
    result = await this.handleRenameFile(params);

Other Tools

Related 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/PWalaGov/File-Control-MCP'

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