Skip to main content
Glama
MausRundung

Project Explorer MCP Server

by MausRundung

rename_file

Rename or move files and directories in a single operation. Works across directories for easy relocation. Fails if destination already exists to prevent overwrites. Both paths must be within allowed directories.

Instructions

Rename or move a file or directory. Can move files between directories and rename them in a single operation. If the destination exists, the operation will fail. Works across different directories and can be used for simple renaming within the same directory. Both source and destination must be within allowed directories.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
oldPathYesCurrent path of the file or directory to rename
newPathYesNew path for the file or directory

Implementation Reference

  • The main handler function that executes the rename_file tool logic. It resolves paths, validates they are within allowed directories, checks source exists and destination doesn't, creates destination parent directory if needed, then performs the rename/move using fs.renameSync.
    export async function handleRenameFile(args: any, allowedDirectories: string[]) {
      const { oldPath, newPath } = args;
    
      if (!oldPath || !newPath) {
        throw new McpError(ErrorCode.InvalidParams, "Both oldPath and newPath are required");
      }
    
      // Resolve to absolute paths
      const resolvedOldPath = path.resolve(oldPath);
      const resolvedNewPath = path.resolve(newPath);
    
      // Check if source is within allowed directories
      const isOldPathAllowed = allowedDirectories.some(dir => {
        const normalizedDir = path.resolve(dir).replace(/\\/g, '/');
        const normalizedOldPath = resolvedOldPath.replace(/\\/g, '/');
        return normalizedOldPath === normalizedDir || normalizedOldPath.startsWith(normalizedDir + '/');
      });
    
      // Check if destination is within allowed directories
      const isNewPathAllowed = allowedDirectories.some(dir => {
        const normalizedDir = path.resolve(dir).replace(/\\/g, '/');
        const normalizedNewPath = resolvedNewPath.replace(/\\/g, '/');
        return normalizedNewPath === normalizedDir || normalizedNewPath.startsWith(normalizedDir + '/');
      });
    
      if (!isOldPathAllowed) {
        throw new McpError(ErrorCode.InvalidParams, `Source path "${resolvedOldPath}" is not within allowed directories`);
      }
    
      if (!isNewPathAllowed) {
        throw new McpError(ErrorCode.InvalidParams, `Destination path "${resolvedNewPath}" is not within allowed directories`);
      }
    
      try {
        // Check if source exists
        if (!fs.existsSync(resolvedOldPath)) {
          throw new McpError(ErrorCode.InvalidParams, `Source path "${resolvedOldPath}" does not exist`);
        }
    
        // Check if destination already exists
        if (fs.existsSync(resolvedNewPath)) {
          throw new McpError(ErrorCode.InvalidParams, `Destination path "${resolvedNewPath}" already exists`);
        }
    
        // Ensure destination directory exists
        const destDir = path.dirname(resolvedNewPath);
        if (!fs.existsSync(destDir)) {
          fs.mkdirSync(destDir, { recursive: true });
        }
    
        // Perform the rename/move operation
        fs.renameSync(resolvedOldPath, resolvedNewPath);
    
        const message = `# File/Directory Rename/Move Successful\n\nāœ… Successfully renamed/moved "${oldPath}" to "${newPath}"\n\n**Details:**\n- Source: ${resolvedOldPath}\n- Destination: ${resolvedNewPath}\n- Operation: ${path.dirname(resolvedOldPath) === path.dirname(resolvedNewPath) ? 'Rename' : 'Move'}`;
        
        return {
          content: [
            {
              type: "text",
              text: message
            }
          ]
        };
    
      } catch (error: any) {
        if (error instanceof McpError) {
          throw error;
        }
        
        throw new McpError(
          ErrorCode.InternalError,
          `Failed to rename file: ${error.message}`
        );
      }
    }
  • The tool definition including name ('rename_file'), description, and inputSchema (requires oldPath and newPath strings).
    export const renameFileTool = {
      name: "rename_file",
      description: "Rename or move a file or directory. Can move files between directories and rename them in a single operation. If the destination exists, the operation will fail. Works across different directories and can be used for simple renaming within the same directory. Both source and destination must be within allowed directories.",
      inputSchema: {
        type: "object",
        properties: {
          oldPath: {
            type: "string",
            description: "Current path of the file or directory to rename"
          },
          newPath: {
            type: "string", 
            description: "New path for the file or directory"
          }
        },
        required: ["oldPath", "newPath"],
        additionalProperties: false
      }
    };
  • src/index.ts:33-44 (registration)
    The tool is registered in the ListToolsRequestSchema handler, returning renameFileTool in the tools array.
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      return {
        tools: [
          exploreProjectTool,
          listAllowedTool,
          searchTool,
          renameFileTool,
          deleteFileTool,
          checkOutdatedTool
        ]
      };
    });
  • src/index.ts:62-63 (registration)
    The tool handler routing in CallToolRequestSchema: when the tool name is 'rename_file', it calls handleRenameFile(args, ALLOWED_DIRECTORIES).
    case "rename_file":
      return await handleRenameFile(args, ALLOWED_DIRECTORIES);
  • The RenameResult interface defining the return shape for a rename operation.
    export interface RenameResult {
      success: boolean;
      oldPath: string;
      newPath: string;
      message: string;
    }
Behavior4/5

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

No annotations provided, so the description carries full burden. It discloses that the operation fails if destination exists, works across directories, and requires paths within allowed directories, providing good behavioral insight.

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?

Description is 5 sentences, front-loads the main action, and every sentence contributes value. No redundant or extraneous text.

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?

Covers purpose, constraints, and behavior. Lacks mention of return values (no output schema) but sufficient for a file rename tool. Sibling tools provide context.

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

Parameters4/5

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

Schema coverage is 100% with parameter descriptions. The description adds context such as the constraint 'Both source and destination must be within allowed directories' and failure condition, enhancing understanding beyond the schema.

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 description clearly states the tool renames/moves files or directories, specifying it can move between directories and rename in one operation. It distinguishes from siblings like delete_file and search_files by focusing on renaming/moving.

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 usage for renaming or moving files/directories and mentions failure if destination exists and path constraints, but does not explicitly state when not to use or suggest alternative tools among siblings.

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/MausRundung/mcp-explorer'

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