Skip to main content
Glama

store_blob

Store data in decentralized storage using base64 encoding or file paths, with configurable retention periods through blockchain verification on the Sui network.

Instructions

Store a blob in Walrus decentralized storage

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dataYesBase64 encoded data or file path to store
epochsNoNumber of epochs to store the blob (default: 5)

Implementation Reference

  • MCP tool handler for 'store_blob': parses arguments using StoreBlobSchema and delegates to walrusClient.storeBlob, returning JSON stringified result
    case 'store_blob': {
      const { data, epochs = 5 } = StoreBlobSchema.parse(args);
      const result = await walrusClient.storeBlob(data, epochs);
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(result, null, 2),
          },
        ],
      };
    }
  • Zod input schema for store_blob tool validation
    const StoreBlobSchema = z.object({
      data: z.string().describe('Base64 encoded data or file path to store'),
      epochs: z.number().optional().describe('Number of epochs to store the blob (default: 5)'),
    });
  • src/index.ts:56-72 (registration)
    Registration of store_blob tool in the listTools response, including name, description, and input schema
    name: 'store_blob',
    description: 'Store a blob in Walrus decentralized storage',
    inputSchema: {
      type: 'object',
      properties: {
        data: {
          type: 'string',
          description: 'Base64 encoded data or file path to store',
        },
        epochs: {
          type: 'number',
          description: 'Number of epochs to store the blob (default: 5)',
          default: 5,
        },
      },
      required: ['data'],
    },
  • Core storeBlob implementation in WalrusClient: handles file paths or base64 data, publishes to Walrus publisher endpoint, parses response into BlobInfo
    async storeBlob(data: string, epochs: number = 5): Promise<BlobInfo> {
      try {
        let blobData: Buffer;
        
        // Check if data is a file path or base64 encoded data
        if (data.startsWith('/') || data.startsWith('./') || data.startsWith('../')) {
          // It's a file path
          blobData = await fs.readFile(data);
        } else {
          // It's base64 encoded data
          blobData = Buffer.from(data, 'base64');
        }
    
        const response = await this.httpClient.put(
          `${this.config.publisherUrl}/v1/store`,
          blobData,
          {
            headers: {
              'Content-Type': 'application/octet-stream',
            },
            params: {
              epochs: epochs.toString(),
            },
          }
        );
    
        if (response.data.newlyCreated) {
          return {
            blobId: response.data.newlyCreated.blobObject.blobId,
            size: response.data.newlyCreated.blobObject.size,
            encodedSize: response.data.newlyCreated.blobObject.encodedSize,
            storageId: response.data.newlyCreated.blobObject.id,
            certified: response.data.newlyCreated.resourceObject ? true : false,
            certifiedEpoch: response.data.newlyCreated.resourceObject?.storage?.startEpoch,
            endEpoch: response.data.newlyCreated.resourceObject?.storage?.endEpoch,
          };
        } else if (response.data.alreadyCertified) {
          return {
            blobId: response.data.alreadyCertified.blobId,
            size: 0, // Size not provided for already certified blobs
            encodedSize: 0,
            storageId: response.data.alreadyCertified.blobId,
            certified: true,
            certifiedEpoch: response.data.alreadyCertified.certifiedEpoch,
            endEpoch: response.data.alreadyCertified.endEpoch,
          };
        }
    
        throw new Error('Unexpected response format from Walrus publisher');
      } catch (error) {
        if (axios.isAxiosError(error)) {
          throw new Error(`Failed to store blob: ${error.response?.data?.error || error.message}`);
        }
        throw new Error(`Failed to store blob: ${error instanceof Error ? error.message : String(error)}`);
      }
    }

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/Mr-Sunglasses/walrus-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server