Skip to main content
Glama

createPrivateDownloadLink

Generate temporary download links to access private IPFS files from Pinata, with customizable expiration times for secure sharing.

Instructions

Generate a temporary download link for accessing a private IPFS file from Pinata

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cidYesThe content ID (CID) of the private file
expiresNoExpiration time in seconds (default: 600 = 10 minutes)

Implementation Reference

  • Complete implementation of createPrivateDownloadLink tool - includes registration, schema definition (cid string, expires number with default 600), and handler logic that generates temporary download links for private IPFS files via Pinata API
    server.tool(
      "createPrivateDownloadLink",
      "Generate a temporary download link for accessing a private IPFS file from Pinata",
      {
        cid: z.string().describe("The content ID (CID) of the private file"),
        expires: z
          .number()
          .default(600)
          .describe("Expiration time in seconds (default: 600 = 10 minutes)"),
      },
      async ({ cid, expires }) => {
        try {
          if (!GATEWAY_URL) {
            throw new Error("GATEWAY_URL environment variable is not set");
          }
    
          const apiUrl = `https://api.pinata.cloud/v3/files/private/download_link`;
          const url = `https://${GATEWAY_URL}/files/${cid}`;
          const date = Math.floor(new Date().getTime() / 1000);
    
          const payload = {
            url,
            expires,
            date,
            method: "GET",
          };
    
          const response = await fetch(apiUrl, {
            method: "POST",
            headers: getHeaders(),
            body: JSON.stringify(payload),
          });
    
          if (!response.ok) {
            throw new Error(
              `Failed to create download link: ${response.status} ${response.statusText}`
            );
          }
    
          const data = await response.json();
          const expirationTime = new Date((date + expires) * 1000).toLocaleString();
    
          return {
            content: [
              {
                type: "text",
                text: `✅ Private download link created!\n\nURL: ${data.data}\n\nExpires: ${expirationTime} (${expires} seconds from creation)`,
              },
            ],
          };
        } catch (error) {
          return errorResponse(error);
        }
      }
    );
  • getHeaders() helper function that constructs authentication headers for Pinata API requests using the PINATA_JWT environment variable
    const getHeaders = () => {
      if (!PINATA_JWT) {
        throw new Error("PINATA_JWT environment variable is not set");
      }
      return {
        Authorization: `Bearer ${PINATA_JWT}`,
        "Content-Type": "application/json",
      };
    };
  • errorResponse() helper function that formats error responses consistently across all tools
    // 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