Skip to main content
Glama

deleteFile

Remove files from your Pinata IPFS storage by specifying the file ID to manage storage space and content organization.

Instructions

Delete a file from your Pinata account by its ID

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
networkNoWhether the file is in public or private IPFSpublic
idYesThe unique ID of the file to delete

Implementation Reference

  • src/index.ts:293-331 (registration)
    The deleteFile tool is registered here with its schema and handler. It takes parameters for 'network' (public/private IPFS, defaults to public) and 'id' (file ID). The handler makes a DELETE request to the Pinata API to remove the file.
    server.tool(
      "deleteFile",
      "Delete a file from your Pinata account by its ID",
      {
        network: z
          .enum(["public", "private"])
          .default("public")
          .describe("Whether the file is in public or private IPFS"),
        id: z.string().describe("The unique ID of the file to delete"),
      },
      async ({ network, id }) => {
        try {
          const url = `https://api.pinata.cloud/v3/files/${network}/${id}`;
    
          const response = await fetch(url, {
            method: "DELETE",
            headers: getHeaders(),
          });
    
          if (!response.ok) {
            throw new Error(
              `Failed to delete file: ${response.status} ${response.statusText}`
            );
          }
    
          const data = await response.json();
          return {
            content: [
              {
                type: "text",
                text: `✅ File deleted successfully\n\n${JSON.stringify(data, null, 2)}`,
              },
            ],
          };
        } catch (error) {
          return errorResponse(error);
        }
      }
    );
  • Schema definition for deleteFile tool parameters using Zod validation: network (enum: 'public' | 'private', default: 'public') and id (required string).
    {
      network: z
        .enum(["public", "private"])
        .default("public")
        .describe("Whether the file is in public or private IPFS"),
      id: z.string().describe("The unique ID of the file to delete"),
    },
  • Handler function for deleteFile that constructs the API URL, makes a DELETE request to Pinata's v3 files endpoint, and returns a success message with the response data or an error response.
    async ({ network, id }) => {
      try {
        const url = `https://api.pinata.cloud/v3/files/${network}/${id}`;
    
        const response = await fetch(url, {
          method: "DELETE",
          headers: getHeaders(),
        });
    
        if (!response.ok) {
          throw new Error(
            `Failed to delete file: ${response.status} ${response.statusText}`
          );
        }
    
        const data = await response.json();
        return {
          content: [
            {
              type: "text",
              text: `✅ File deleted successfully\n\n${JSON.stringify(data, null, 2)}`,
            },
          ],
        };
      } catch (error) {
        return errorResponse(error);
      }
    }
  • Helper function used by deleteFile handler to get authenticated request headers including the JWT Bearer token for Pinata API authentication.
    const getHeaders = () => {
      if (!PINATA_JWT) {
        throw new Error("PINATA_JWT environment variable is not set");
      }
      return {
        Authorization: `Bearer ${PINATA_JWT}`,
        "Content-Type": "application/json",
      };
    };
  • Helper function for consistent error responses used by deleteFile handler to format errors in a standardized way with isError flag set to true.
    // Helper for consistent error responses
    const errorResponse = (error: unknown) => ({
      content: [
        {
          type: "text" as const,
          text: `Error: ${error instanceof Error ? error.message : String(error)}`,
        },
      ],
      isError: true,
    });

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/PinataCloud/pinata-mcp'

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