Skip to main content
Glama
modelcontextprotocol

Filesystem MCP Server

Official

move_file

Move or rename files and directories within allowed paths. Specify source and destination to transfer files between directories or rename them in a single operation, failing if the destination 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
destinationYes
sourceYes

Implementation Reference

  • The handler function for the 'move_file' tool. It validates the source and destination paths, performs the rename operation using Node.js fs.rename, and returns a success message.
    async (args: z.infer<typeof MoveFileArgsSchema>) => { const validSourcePath = await validatePath(args.source); const validDestPath = await validatePath(args.destination); await fs.rename(validSourcePath, validDestPath); const text = `Successfully moved ${args.source} to ${args.destination}`; const contentBlock = { type: "text" as const, text }; return { content: [contentBlock], structuredContent: { content: [contentBlock] } }; }
  • Zod schema defining the input arguments for the move_file tool: source and destination paths.
    const MoveFileArgsSchema = z.object({ source: z.string(), destination: z.string(), });
  • Registration of the 'move_file' tool using server.registerTool, including metadata, inline input schema, and the handler function.
    server.registerTool( "move_file", { title: "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: { source: z.string(), destination: z.string() }, outputSchema: { content: z.string() }, annotations: { readOnlyHint: false, idempotentHint: false, destructiveHint: false } }, async (args: z.infer<typeof MoveFileArgsSchema>) => { const validSourcePath = await validatePath(args.source); const validDestPath = await validatePath(args.destination); await fs.rename(validSourcePath, validDestPath); const text = `Successfully moved ${args.source} to ${args.destination}`; const contentBlock = { type: "text" as const, text }; return { content: [contentBlock], structuredContent: { content: [contentBlock] } }; } );

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/modelcontextprotocol/filesystem'

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