move_file
Move or rename files and directories between locations. Specify source and destination paths to transfer files or change names in a single operation.
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
| Name | Required | Description | Default |
|---|---|---|---|
| source | Yes | ||
| destination | Yes |
Implementation Reference
- src/filesystem/index.ts:594-604 (handler)The handler function for the 'move_file' tool. It validates the source and destination paths using validatePath, then uses Node.js fs.rename to perform the move operation. Finally, it 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: text } }; }
- src/filesystem/index.ts:128-131 (schema)Zod schema defining the input arguments for the move_file tool: source and destination paths as strings. Used for type inference in the handler.const MoveFileArgsSchema = z.object({ source: z.string(), destination: z.string(), });
- src/filesystem/index.ts:578-605 (registration)Registration of the 'move_file' tool using server.registerTool, including title, description, inline inputSchema, outputSchema, annotations, and the inline 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: text } }; } );