Skip to main content
Glama

updateFile

Modify metadata for existing Pinata files by updating file names and custom key-value pairs to organize content on IPFS.

Instructions

Update metadata for an existing file on Pinata including name and key-value pairs

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
networkNoWhether the file is in public or private storagepublic
idYesThe unique ID of the file to update
nameNoNew name for the file
keyvaluesNoMetadata key-value pairs to update

Implementation Reference

  • src/index.ts:249-291 (registration)
    The updateFile tool is registered with the MCP server, allowing updates to file metadata including name and key-value pairs on Pinata IPFS storage.
    server.tool(
      "updateFile",
      "Update metadata for an existing file on Pinata including name and key-value pairs",
      {
        network: z
          .enum(["public", "private"])
          .default("public")
          .describe("Whether the file is in public or private storage"),
        id: z.string().describe("The unique ID of the file to update"),
        name: z.string().optional().describe("New name for the file"),
        keyvalues: z
          .record(z.any())
          .optional()
          .describe("Metadata key-value pairs to update"),
      },
      async ({ network, id, name, keyvalues }) => {
        try {
          const url = `https://api.pinata.cloud/v3/files/${network}/${id}`;
    
          const payload: { name?: string; keyvalues?: Record<string, unknown> } =
            {};
          if (name) payload.name = name;
          if (keyvalues) payload.keyvalues = keyvalues;
    
          const response = await fetch(url, {
            method: "PUT",
            headers: getHeaders(),
            body: JSON.stringify(payload),
          });
    
          if (!response.ok) {
            throw new Error(
              `Failed to update file: ${response.status} ${response.statusText}`
            );
          }
    
          const data = await response.json();
          return successResponse(data);
        } catch (error) {
          return errorResponse(error);
        }
      }
    );
  • Handler function that executes the updateFile logic by sending a PUT request to the Pinata API with optional name and keyvalues metadata updates.
    async ({ network, id, name, keyvalues }) => {
      try {
        const url = `https://api.pinata.cloud/v3/files/${network}/${id}`;
    
        const payload: { name?: string; keyvalues?: Record<string, unknown> } =
          {};
        if (name) payload.name = name;
        if (keyvalues) payload.keyvalues = keyvalues;
    
        const response = await fetch(url, {
          method: "PUT",
          headers: getHeaders(),
          body: JSON.stringify(payload),
        });
    
        if (!response.ok) {
          throw new Error(
            `Failed to update file: ${response.status} ${response.statusText}`
          );
        }
    
        const data = await response.json();
        return successResponse(data);
      } catch (error) {
        return errorResponse(error);
      }
    }
  • Zod schema defining the input parameters for updateFile: network (public/private), id (required), name (optional), and keyvalues (optional).
    {
      network: z
        .enum(["public", "private"])
        .default("public")
        .describe("Whether the file is in public or private storage"),
      id: z.string().describe("The unique ID of the file to update"),
      name: z.string().optional().describe("New name for the file"),
      keyvalues: z
        .record(z.any())
        .optional()
        .describe("Metadata key-value pairs to update"),
  • Helper function that formats successful API responses into the standard MCP content format with JSON stringified data.
    // Helper for consistent success responses
    const successResponse = (data: unknown) => ({
      content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }],
    });
  • Helper function that formats error responses into the standard MCP content format with error message and isError flag.
    // 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