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
| Name | Required | Description | Default |
|---|---|---|---|
| cid | Yes | The CID of the file to create a link for | |
| network | No | Whether the file is on public or private IPFS | public |
| expires | No | Expiration time in seconds for private download links (default: 600) |
Implementation Reference
- src/index.ts:506-581 (handler)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); } } ); - src/index.ts:509-521 (schema)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)" ), },