Skip to main content
Glama

createLink

Generate direct access links for IPFS files stored on Pinata. For public files, create gateway URLs; for private files, produce temporary download links with customizable expiration times.

Instructions

Create a direct access link for a file stored on Pinata IPFS. For public files returns a gateway URL, for private files generates a temporary download link.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cidYesThe CID of the file to create a link for
networkNoWhether the file is on public or private IPFSpublic
expiresNoExpiration time in seconds for private download links (default: 600)

Implementation Reference

  • The createLink tool handler - creates a direct access link for files stored on Pinata IPFS. For public files, it returns a gateway URL. For private files, it generates a temporary download link with configurable expiration time using the Pinata API.
    server.tool(
      "createLink",
      "Create a direct access link for a file stored on Pinata IPFS. For public files returns a gateway URL, for private files generates a temporary download link.",
      {
        cid: z.string().describe("The CID of the file to create a link for"),
        network: z
          .enum(["public", "private"])
          .default("public")
          .describe("Whether the file is on public or private IPFS"),
        expires: z
          .number()
          .default(600)
          .describe(
            "Expiration time in seconds for private download links (default: 600)"
          ),
      },
      async ({ cid, network, expires = 600 }) => {
        try {
          if (!GATEWAY_URL) {
            throw new Error("GATEWAY_URL environment variable is not set");
          }
    
          if (network === "public") {
            const fileUrl = `https://${GATEWAY_URL}/ipfs/${cid}`;
            return {
              content: [
                {
                  type: "text",
                  text: `✅ Public IPFS link:\n${fileUrl}`,
                },
              ],
            };
          } else {
            const filePath = `https://${GATEWAY_URL}/files/${cid}`;
            const apiUrl = `https://api.pinata.cloud/v3/files/private/download_link`;
            const date = Math.floor(new Date().getTime() / 1000);
    
            const payload = {
              url: filePath,
              expires,
              date,
              method: "GET",
            };
    
            const linkResponse = await fetch(apiUrl, {
              method: "POST",
              headers: getHeaders(),
              body: JSON.stringify(payload),
            });
    
            if (!linkResponse.ok) {
              const errorText = await linkResponse.text();
              throw new Error(
                `Failed to create download link: ${linkResponse.status} ${linkResponse.statusText}. Response: ${errorText}`
              );
            }
    
            const linkData = await linkResponse.json();
            const expirationTime = new Date(
              (date + expires) * 1000
            ).toLocaleString();
    
            return {
              content: [
                {
                  type: "text",
                  text: `✅ Private IPFS temporary link:\n${linkData.data}\n\nExpires: ${expirationTime} (${expires} seconds from creation)`,
                },
              ],
            };
          }
        } catch (error) {
          return errorResponse(error);
        }
      }
    );
  • The tool schema definition for createLink - defines the input parameters using Zod validation: cid (required string), network (enum 'public' or 'private', default 'public'), and expires (number, default 600 seconds).
    {
      cid: z.string().describe("The CID of the file to create a link for"),
      network: z
        .enum(["public", "private"])
        .default("public")
        .describe("Whether the file is on public or private IPFS"),
      expires: z
        .number()
        .default(600)
        .describe(
          "Expiration time in seconds for private download links (default: 600)"
        ),
    },

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