Skip to main content
Glama
qpd-v

MCP-Delete

by qpd-v

delete_file

Remove a file from the specified path using the MCP-Delete server. Supports both relative and absolute paths to ensure accurate and safe file deletion.

Instructions

Delete a file at the specified path (supports both relative and absolute paths)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesPath to the file to delete (relative to working directory or absolute)

Implementation Reference

  • Handler for the delete_file tool. Resolves the input path to possible locations, checks if the file exists, deletes it using fs.promises.unlink, and returns success or throws appropriate MCP errors.
    case "delete_file": {
      const inputPath = String(request.params.arguments?.path);
      if (!inputPath) {
        throw new McpError(
          ErrorCode.InvalidParams,
          "File path is required"
        );
      }
      
      // Try multiple potential paths
      const pathsToTry = [
        inputPath, // Original path
        isAbsolute(inputPath) ? inputPath : resolve(process.cwd(), inputPath), // Relative to process.cwd()
        isAbsolute(inputPath) ? inputPath : resolve('c:/mcpnfo', inputPath), // Relative to mcpnfo
      ];
    
      // Try each path
      let fileFound = false;
      let foundPath = '';
      for (const path of pathsToTry) {
        if (existsSync(path)) {
          fileFound = true;
          foundPath = path;
          break;
        }
      }
    
      if (!fileFound) {
        throw new McpError(
          ErrorCode.InvalidParams,
          `File not found: ${inputPath}\nTried paths:\n${pathsToTry.join('\n')}`
        );
      }
    
      try {
        await unlink(foundPath);
        return {
          content: [{
            type: "text",
            text: `Successfully deleted file: ${inputPath}`
          }]
        };
      } catch (err) {
        const error = err as Error;
        throw new McpError(
          ErrorCode.InternalError,
          `Failed to delete file ${inputPath}: ${error.message}\nTried paths:\n${pathsToTry.join('\n')}`
        );
      }
    }
  • src/index.ts:37-50 (registration)
    Registers the "delete_file" tool in the ListTools response, including its name, description, and input schema.
    {
      name: "delete_file",
      description: "Delete a file at the specified path (supports both relative and absolute paths)",
      inputSchema: {
        type: "object",
        properties: {
          path: {
            type: "string",
            description: "Path to the file to delete (relative to working directory or absolute)"
          }
        },
        required: ["path"]
      }
    }
  • Input schema definition for the delete_file tool, specifying a required 'path' string property.
    inputSchema: {
      type: "object",
      properties: {
        path: {
          type: "string",
          description: "Path to the file to delete (relative to working directory or absolute)"
        }
      },
      required: ["path"]
    }
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/qpd-v/mcp-delete'

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