Skip to main content
Glama

delete_items

Remove multiple files or directories at once from the filesystem by specifying their relative paths, streamlining cleanup and organization tasks.

Instructions

Delete multiple specified files or directories.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathsYesAn array of relative paths (files or directories) to delete.

Implementation Reference

  • Main handler function for 'delete_items' tool: validates args, performs deletions on multiple paths concurrently with error handling using Promise.allSettled, processes and sorts results, returns JSON response.
    const handleDeleteItemsFunc = async (args: unknown): Promise<McpToolResponse> => {
      const { paths: pathsToDelete } = parseAndValidateArgs(args);
    
      const safeProcessSingleDeleteOperation = async (relativePath: string): Promise<DeleteResult> => {
         const pathOutput = relativePath.replaceAll('\\', '/');
         try {
           // Call the core logic which might return a DeleteResult or throw
           return await processSingleDeleteOperation(relativePath);
         } catch (error) {
           // Catch errors thrown *before* the try block in processSingleDeleteOperation (like resolvePath)
           // or unexpected errors within it not returning a DeleteResult.
           return handleDeleteError(error, relativePath, pathOutput);
         }
      };
    
      const deletePromises = pathsToDelete.map(safeProcessSingleDeleteOperation);
      const settledResults = await Promise.allSettled(deletePromises);
    
      const outputResults = processSettledResults(settledResults, pathsToDelete);
    
      // Sort results by original path order for predictability
      const originalIndexMap = new Map(pathsToDelete.map((p, i) => [p.replaceAll('\\', '/'), i]));
      outputResults.sort((a, b) => {
        const indexA = originalIndexMap.get(a.path) ?? Infinity;
        const indexB = originalIndexMap.get(b.path) ?? Infinity;
        return indexA - indexB;
      });
    
      return {
        content: [{ type: 'text', text: JSON.stringify(outputResults, null, 2) }],
      };
    };
  • Zod schema defining the input for delete_items: object with 'paths' array of strings (non-empty).
    export const DeleteItemsArgsSchema = z
      .object({
        paths: z
          .array(z.string())
          .min(1, { message: 'Paths array cannot be empty' })
          .describe('An array of relative paths (files or directories) to delete.'),
      })
      .strict();
  • Tool definition export for 'delete_items', specifying name, description, input schema, and handler reference.
    export const deleteItemsToolDefinition = {
      name: 'delete_items',
      description: 'Delete multiple specified files or directories.',
      inputSchema: DeleteItemsArgsSchema,
      handler: handleDeleteItemsFunc,
    };
  • Registration of deleteItemsToolDefinition (imported from './delete-items.js') in the central allToolDefinitions array used to expose tools.
    export const allToolDefinitions: HandlerToolDefinition[] = [
      listFilesToolDefinition,
      statItemsToolDefinition,
      readContentToolDefinition,
      writeContentToolDefinition,
      deleteItemsToolDefinition,
  • Core helper function that resolves path and performs single file/directory deletion using fs.rm (recursive), with root protection and error handling.
    async function processSingleDeleteOperation(relativePath: string): Promise<DeleteResult> {
      const pathOutput = relativePath.replaceAll('\\', '/');
      try {
        const targetPath = await resolvePath(relativePath);
        if (targetPath === PROJECT_ROOT) {
          throw new McpError(ErrorCode.InvalidRequest, 'Deleting the project root is not allowed.');
        }
        await fs.rm(targetPath, { recursive: true, force: false });
        return { path: pathOutput, success: true };
      } catch (error: unknown) {
        // This catch block will now correctly pass McpError or other errors to handleDeleteError
        return handleDeleteError(error, relativePath, pathOutput);
      }
    }
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. It states the tool deletes files/directories, implying a destructive mutation, but lacks details on permissions required, whether deletions are permanent or reversible, error handling (e.g., if some paths don't exist), or rate limits. This is a significant gap for a destructive 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 purpose without redundancy. It is front-loaded and wastes no words, making it highly concise and well-structured.

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 tool's destructive nature, lack of annotations, and no output schema, the description is incomplete. It does not address critical context like safety warnings, return values (e.g., success/failure status), or error conditions, leaving significant gaps for an agent to use it correctly.

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 parameter 'paths' clearly documented in the schema as 'An array of relative paths (files or directories) to delete.' The description adds no additional meaning beyond this, such as path format examples or constraints, so it meets the baseline of 3 where the schema does the heavy lifting.

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 ('Delete') and target ('multiple specified files or directories'), which is specific and unambiguous. However, it does not explicitly differentiate from sibling tools like 'move_items' or 'replace_content' in terms of destructive intent, though the verb 'Delete' inherently implies removal.

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. It does not mention prerequisites (e.g., permissions), exclusions (e.g., cannot delete system files), or sibling tools for related operations like 'move_items' for relocation instead of deletion.

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