Skip to main content
Glama
A-Niranjan

MCP Filesystem Server

by A-Niranjan

move_file

Move or rename files and directories within allowed paths. This tool transfers files between directories or renames them in place, failing if the destination already exists.

Instructions

Move or rename files and directories. 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
sourceYesSource path of the file or directory to move
destinationYesDestination path where to move the file or directory

Implementation Reference

  • The main execution logic for the 'move_file' tool. Parses input arguments using the schema, validates both source and destination paths against allowed directories, creates the destination parent directory if necessary, performs the file/directory move using fs.rename, logs the operation, and returns a success message.
    case 'move_file': { const parsed = MoveFileArgsSchema.safeParse(a) if (!parsed.success) { throw new FileSystemError(`Invalid arguments for ${name}`, 'INVALID_ARGS', undefined, { errors: parsed.error.format(), }) } const validSourcePath = await validatePath(parsed.data.source, config) const validDestPath = await validatePath(parsed.data.destination, config) // Ensure the destination parent directory exists const destDir = path.dirname(validDestPath) await fs.mkdir(destDir, { recursive: true }) await fs.rename(validSourcePath, validDestPath) await logger.debug(`Moved file from ${validSourcePath} to ${validDestPath}`) endMetric() return { content: [ { type: 'text', text: `Successfully moved ${parsed.data.source} to ${parsed.data.destination}`, }, ], } }
  • Zod schema defining the expected input structure for the move_file tool: source (string) and destination (string) paths.
    const MoveFileArgsSchema = z.object({ source: z.string().describe('Source path of the file or directory to move'), destination: z.string().describe('Destination path where to move the file or directory'), })
  • src/index.ts:297-305 (registration)
    Tool registration in the ListTools handler response. Specifies the tool name, detailed description of functionality and limitations, and converts the Zod schema to JSON schema for the MCP protocol.
    { name: 'move_file', description: 'Move or rename files and directories. 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: zodToJsonSchema(MoveFileArgsSchema) as ToolInput, },

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/A-Niranjan/mcp-filesystem'

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