Skip to main content
Glama
MausRundung

Project Explorer MCP Server

by MausRundung

rename_file

Change file or directory names and locations within allowed project paths. Move items between directories or rename them in place while preventing overwrites of existing destinations.

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 performs the file rename/move operation, including validation, permission checks within allowed directories, existence checks, and 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}`
        );
      }
    }
  • Defines the tool metadata including name, description, and input schema for oldPath and newPath parameters.
    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)
    Registers the renameFileTool as part of the list of available tools served in response to ListToolsRequestSchema.
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      return {
        tools: [
          exploreProjectTool,
          listAllowedTool,
          searchTool,
          renameFileTool,
          deleteFileTool,
          checkOutdatedTool
        ]
      };
    });
  • src/index.ts:62-63 (registration)
    Dispatches calls to the 'rename_file' tool to the handleRenameFile handler function.
    case "rename_file":
      return await handleRenameFile(args, ALLOWED_DIRECTORIES);
Behavior4/5

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

With no annotations provided, the description carries the full burden and does well by disclosing key behavioral traits: it's a mutation operation (rename/move), failure condition (if destination exists), scope (works across directories, within allowed directories), and constraints (both paths must be within allowed directories). It doesn't cover aspects like permissions or error details, but provides solid operational context.

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 appropriately sized and front-loaded, with the core purpose stated first ('Rename or move a file or directory'). Each sentence adds necessary information without redundancy, such as operational details and constraints, making it efficient and well-structured.

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?

Given the tool's moderate complexity (mutation with constraints), no annotations, and no output schema, the description is mostly complete. It covers purpose, behavior, and constraints, but lacks details on return values or error handling. For a mutation tool without structured output, it does well but has minor gaps.

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 both parameters (oldPath and newPath) adequately. The description adds minimal value beyond the schema by implying the relationship between parameters (oldPath as source, newPath as destination) but doesn't provide additional syntax or format details. Baseline 3 is appropriate.

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's purpose with specific verbs ('rename or move') and resources ('file or directory'), distinguishing it from siblings like delete_file (deletion) and search_files (searching). It precisely defines the dual functionality in a single operation.

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

Usage Guidelines4/5

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

The description provides clear context on when to use this tool (for renaming/moving files/directories) and mentions constraints like failure if destination exists and allowed directories. However, it lacks explicit guidance on when not to use it or direct alternatives among siblings (e.g., no comparison to delete_file for removal).

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