Skip to main content
Glama

move_items

Move or rename multiple files and directories efficiently by specifying source and destination paths in a structured array.

Instructions

Move or rename multiple specified files/directories.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
operationsYesArray of {source, destination} objects.

Implementation Reference

  • Core handler function implementing the logic for the 'move_items' tool: parses input, processes multiple move operations concurrently using Promise.allSettled, handles results, sorts them to maintain original order, and formats the JSON response.
    export const handleMoveItemsFuncCore = async (
      args: unknown,
      dependencies: MoveItemsDependencies,
    ): Promise<McpToolResponse> => {
      const { operations } = parseAndValidateArgs(args);
    
      const movePromises = operations.map((op) =>
        processSingleMoveOperation({ op }, dependencies), // Pass dependencies
      );
      const settledResults = await Promise.allSettled(movePromises);
    
      const outputResults = processSettledResults(settledResults, operations);
    
      // Sort results based on the original order
      const originalIndexMap = new Map(operations.map((op, i) => [op.source.replaceAll('\\', '/'), i]));
      outputResults.sort((a, b) => {
        const indexA = originalIndexMap.get(a.source) ?? Infinity;
        const indexB = originalIndexMap.get(b.source) ?? Infinity;
        return indexA - indexB;
      });
    
      return {
        content: [{ type: 'text', text: JSON.stringify(outputResults, undefined, 2) }],
      };
    };
  • Zod schemas for move operation and the overall input arguments for the 'move_items' tool, enforcing structure and validation.
    export const MoveOperationSchema = z
      .object({
        source: z.string().describe('Relative path of the source.'),
        destination: z.string().describe('Relative path of the destination.'),
      })
      .strict();
    
    export const MoveItemsArgsSchema = z
      .object({
        operations: z
          .array(MoveOperationSchema)
          .min(1, { message: 'Operations array cannot be empty' })
          .describe('Array of {source, destination} objects.'),
      })
      .strict();
  • Definition object for the 'move_items' tool, including name, description, input schema, and reference to the handler function.
    export const moveItemsToolDefinition = {
      name: 'move_items',
      description: 'Move or rename multiple specified files/directories.',
      inputSchema: MoveItemsArgsSchema,
      handler: handleMoveItemsFunc, // Use the wrapper
    };
  • Central registration of all MCP tools in the 'allToolDefinitions' array, including the 'move_items' tool.
    // Use our more specific type to avoid naming conflicts
    export const allToolDefinitions: HandlerToolDefinition[] = [
      listFilesToolDefinition,
      statItemsToolDefinition,
      readContentToolDefinition,
      writeContentToolDefinition,
      deleteItemsToolDefinition,
      createDirectoriesToolDefinition,
      chmodItemsToolDefinition,
      chownItemsToolDefinition,
      moveItemsToolDefinition,
      copyItemsToolDefinition,
      searchFilesToolDefinition,
      replaceContentToolDefinition,
      {
        name: 'apply_diff',
        description: 'Apply diffs to files',
        inputSchema: applyDiffInputSchema,
        handler: async (args: unknown): Promise<McpToolResponse> => {
          const validatedArgs = applyDiffInputSchema.parse(args);
          const result: ApplyDiffOutput = await handleApplyDiff(validatedArgs.changes, {
            readFile: async (path: string) => fs.promises.readFile(path, 'utf8'),
            writeFile: async (path: string, content: string) =>
              fs.promises.writeFile(path, content, 'utf8'),
            path,
            projectRoot: process.cwd(),
          });
          return {
            content: [
              {
                type: 'text',
                text: JSON.stringify(
                  {
                    success: result.success,
                    results: result.results,
                  },
                  undefined,
                  2,
                ),
              },
            ],
          };
        },
      },
    ];
  • Helper function that processes a single move operation: validates, resolves paths, checks source, ensures destination directory, performs rename, and handles errors.
    async function processSingleMoveOperation(
      params: ProcessSingleMoveParams,
      dependencies: MoveItemsDependencies, // Inject dependencies
    ): Promise<MoveResult> {
      const { op } = params;
    
      // Validate operation parameters
      const validationResult = validateMoveOperation(op);
      if (validationResult) return validationResult;
    
      const sourceRelative = op.source;
      const destinationRelative = op.destination;
      const sourceOutput = sourceRelative.replaceAll('\\', '/');
      const destOutput = destinationRelative.replaceAll('\\', '/');
    
      try {
        // Safely resolve paths using injected dependency
        const sourceAbsolute = await dependencies.resolvePath(sourceRelative);
        const destinationAbsolute = await dependencies.resolvePath(destinationRelative);
    
        if (sourceAbsolute === dependencies.PROJECT_ROOT) { // Use injected dependency
          return {
            source: sourceOutput,
            destination: destOutput,
            success: false,
            error: 'Moving the project root is not allowed.',
          };
        }
    
        // Check source existence using injected dependency
        const sourceCheckResult = await checkSourceExists(
          {
            sourceAbsolute,
            sourceRelative,
            sourceOutput,
            destOutput,
          },
          dependencies, // Pass dependencies
        );
        // Ensure we return immediately if source check fails (No change needed here, already correct)
        if (sourceCheckResult) return sourceCheckResult;
        // Perform the move using injected dependency
        return await performMoveOperation(
          {
            sourceAbsolute,
            destinationAbsolute,
            sourceOutput,
            destOutput,
          },
          dependencies, // Pass dependencies
        );
      } catch (error) {
        const specialErrorResult = handleSpecialMoveErrors(error, sourceOutput, destOutput);
        if (specialErrorResult) return specialErrorResult;
    
        return handleMoveError({
          error,
          sourceRelative,
          destinationRelative,
          sourceOutput,
          destOutput,
        });
      }
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool can 'move or rename' items, implying mutation, but doesn't address critical aspects like permissions required, whether operations are atomic or batched, error handling, or what happens if destinations already exist. This leaves significant gaps for a mutation tool.

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 that directly states the tool's function without unnecessary words. It's front-loaded with the core action and target, making it easy to parse quickly.

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?

For a mutation tool with no annotations and no output schema, the description is incomplete. It lacks details on behavioral traits (e.g., overwrite behavior, error responses), usage context compared to siblings, and output expectations, making it inadequate for safe and effective tool invocation.

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%, with the 'operations' parameter fully documented in the schema as an array of source-destination objects. The description adds no additional parameter semantics beyond what the schema provides, such as path format examples or batch size limits, 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 action ('Move or rename') and target ('multiple specified files/directories'), providing a specific verb+resource combination. However, it doesn't explicitly distinguish this tool from sibling tools like 'copy_items' or 'rename_items' (if such existed), which would require more precise differentiation.

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 like 'copy_items' (for copying instead of moving) or 'rename_items' (if available). There's no mention of prerequisites, constraints, or typical use cases, leaving the agent with minimal contextual direction.

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

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

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