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
| Name | Required | Description | Default |
|---|---|---|---|
| cid | Yes | The content ID (CID) of the private file | |
| expires | No | Expiration time in seconds (default: 600 = 10 minutes) |
Implementation Reference
- src/index.ts:450-504 (handler)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); } } ); - src/index.ts:100-108 (helper)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", }; }; - src/index.ts:110-119 (helper)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, });