Skip to main content
Glama

delete_file

Remove files or directories from the system by specifying a path, with options for recursive deletion and error handling.

Instructions

Delete a file or directory

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesPath to delete
recursiveNoDelete directories recursively
forceNoIgnore errors

Implementation Reference

  • The implementation of the delete file functionality.
    async function deleteFileImpl(input: DeleteFileInput): Promise<ToolResult> {
      try {
        const absolutePath = path.resolve(input.path);
    
        // Check what type of path this is
        const stats = await fs.stat(absolutePath);
    
        if (stats.isDirectory()) {
          if (!input.recursive) {
            // Check if directory is empty
            const entries = await fs.readdir(absolutePath);
            if (entries.length > 0) {
              return {
                isError: true,
                content: [
                  {
                    type: 'text',
                    text: JSON.stringify({
                      code: 'DIRECTORY_NOT_EMPTY',
                      message: `Directory is not empty and recursive is false: ${input.path}`,
                    }),
                  },
                ],
              };
            }
          }
    
          await fs.rm(absolutePath, { recursive: input.recursive, force: input.force });
        } else {
          await fs.unlink(absolutePath);
        }
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify({
  • Registration of the 'delete_file' tool in the MCP server.
    server.tool(
      'delete_file',
      'Delete a file or directory',
      {
        path: z.string().describe('Path to delete'),
        recursive: z.boolean().optional().describe('Delete directories recursively'),
        force: z.boolean().optional().describe('Ignore errors'),
      },
      async (args) => {
        const input = DeleteFileInputSchema.parse(args);
        return await deleteFileImpl(input);
      }
    );
  • Schema definition for the delete_file tool input.
    export const DeleteFileInputSchema = z.object({
      path: z.string().describe('Path to delete'),
      recursive: z.boolean().default(false).describe('Delete directories recursively'),
      force: z.boolean().default(false).describe('Ignore errors'),
    });
Behavior2/5

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

With no annotations provided, the description carries full burden but only states the basic action. It doesn't disclose critical behavioral traits: whether deletion is permanent or reversible, permission requirements, error handling (beyond the 'force' parameter), or effects on linked resources. For a destructive tool, this is a significant gap.

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 with zero wasted words. It's front-loaded with the core action and resource, making it immediately scannable and appropriately sized for the tool's complexity.

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 destructive tool with no annotations and no output schema, the description is incomplete. It lacks information on return values (e.g., success confirmation or error details), side effects, and safety considerations, which are crucial 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%, so parameters are fully documented in the schema. The description adds no semantic context beyond implying 'path' targets the item to delete. It doesn't explain parameter interactions (e.g., 'recursive' for directories) or practical usage, but the schema provides adequate baseline.

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 resource ('a file or directory'), making the purpose immediately understandable. It distinguishes from siblings like 'move_file' or 'copy_file' by specifying deletion. However, it doesn't explicitly differentiate from all destructive operations like 'remove' or 'unlink' if they existed.

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 doesn't mention prerequisites (e.g., file must exist), when not to use it (e.g., for read-only files), or compare with similar tools like 'move_file' 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

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/mcp-tool-shop-org/mcp-file-forge'

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