Skip to main content
Glama
PWalaGov

Enhanced Directory Context MCP Server

by PWalaGov

rename_file

Rename or move files within directories by specifying old and new paths, with optional overwrite protection for existing files.

Instructions

Rename or move a file

Input Schema

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

Implementation Reference

  • The core handler function implementing the rename_file tool. It destructures arguments, resolves full paths relative to working directory, validates source existence and handles destination overwrite option, ensures target directory exists, performs the rename using fs.rename(), and returns a success message or throws an MCP error on failure.
    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)
    Tool registration entry in the ListToolsRequestSchema handler's tools array. Defines the tool name, description, and input schema for MCP clients to discover and validate calls.
    {
      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'],
      },
    },
  • JSON Schema defining the input parameters for the rename_file tool: old_path (required string), new_path (required string), overwrite (optional boolean with default false).
    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)
    Dispatch case in the CallToolRequestSchema handler's switch statement that routes 'rename_file' tool calls to the handleRenameFile method.
    case 'rename_file':
      return await this.handleRenameFile(args);
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. While 'rename or move' implies a mutation operation, it lacks details on permissions required, error conditions (e.g., if paths don't exist), whether the operation is atomic or reversible, or any rate limits. This is a significant gap for a tool that modifies files.

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 wasted words. It's front-loaded with the core action and resource, making it easy to parse quickly. Every word earns its place by directly conveying the tool's purpose.

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 the complexity of a file mutation tool with no annotations and no output schema, the description is incomplete. It doesn't address behavioral aspects like error handling, permissions, or what the tool returns, leaving gaps that could hinder an AI agent's ability to use it correctly in various contexts.

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 (old_path, new_path, overwrite) with clear descriptions. The description adds no additional meaning beyond what the schema provides, such as path format examples or implications of the overwrite parameter, meeting the baseline for high schema coverage.

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 verb 'rename or move' and resource 'a file', making the purpose immediately understandable. However, it doesn't differentiate this tool from potential alternatives like 'update_file' or 'batch_file_operations' among the sibling tools, which would require more specificity for a perfect score.

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 'update_file' and 'batch_file_operations' available, there's no indication of scenarios where renaming/moving is preferred over other file modification methods, nor any prerequisites or exclusions mentioned.

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

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