Skip to main content
Glama
list-assets.ts•4.46 kB
import { z } from "zod"; import { api } from "../api"; import { formatDate, getAssetStatusText, isAssetMinted, formatAddress } from "../utils"; // Input schema with all filter parameters export const listAssetsInputSchema = z.object({ contractId: z.string().optional().describe("Filter assets by collection ID"), page: z.number().min(1).default(1).describe("Page number (default: 1)"), pageSize: z.number().min(1).max(100).default(20).describe("Number of assets per page (default: 20, max: 100)"), sortBy: z.string().default("createdAt").describe("Sort field (default: createdAt)"), order: z.enum(["asc", "desc"]).default("asc").describe("Sort order (default: asc)"), quickFilter: z.string().optional().describe("Search text to filter assets by title"), }); export interface AssetListResult { success: boolean; data?: { assets: Array<{ id: string; title: string; description?: string; collectionName: string; contractId: string; status: string; statusText: string; isMinted: boolean; mediaType: string; ercContractType: string; currentEditions: number; totalEditions: number; thumbnailUrl?: string; sourceUrl: string; contractAddress?: string; tokenId?: string; openSeaUrl?: string; creatorName: string; creatorAddress: string; currentOwnerName?: string; currentOwnerAddress: string; location?: string; isEncrypted: boolean; isListed: boolean; inTransfer: boolean; createdAt?: string; mintedAt?: string; }>; pagination: { page: number; pageSize: number; total: number; totalPages: number; hasNextPage: boolean; hasPreviousPage: boolean; }; }; error?: string; } export async function listAssets(params: z.infer<typeof listAssetsInputSchema>): Promise<AssetListResult> { try { const response = await api.assets.list({ contractId: params.contractId, page: params.page, pageSize: params.pageSize, sortBy: params.sortBy ?? "createdAt", order: params.order ?? "asc", quickFilter: params.quickFilter, }); if (response.status !== "ok" || !response.ok) { return { success: false, error: response.errorCode || "Failed to load assets", }; } const assetsData = response.ok.data || []; const meta = response.ok.meta; const assets = assetsData.map((asset) => ({ id: asset.id, title: asset.title, description: asset.description || undefined, collectionName: asset.collectionName, contractId: asset.contractId, status: asset.status.toString(), statusText: getAssetStatusText(asset.status), isMinted: isAssetMinted(asset.status), mediaType: asset.mediaType, ercContractType: asset.ercContractType, currentEditions: asset.currentEditions, totalEditions: asset.editions, thumbnailUrl: asset.thumbnailUrl || undefined, sourceUrl: asset.sourceUrl, contractAddress: asset.contractAddress || undefined, tokenId: asset.tokenId || undefined, openSeaUrl: asset.openSeaUrl || undefined, creatorName: asset.creatorName, creatorAddress: formatAddress(asset.creatorAddress), currentOwnerName: asset.currentOwnerName || undefined, currentOwnerAddress: formatAddress(asset.currentOwnerAddress), location: asset.location || undefined, isEncrypted: asset.isEncrypted, isListed: asset.isListed, inTransfer: asset.inTransfer, createdAt: asset.createdAt ? formatDate(asset.createdAt) : undefined, mintedAt: asset.mintedAt ? formatDate(asset.mintedAt) : undefined, })); const pagination = meta ? { page: meta.page, pageSize: meta.pageSize, total: meta.total, totalPages: meta.countPages, hasNextPage: meta.page < meta.countPages, hasPreviousPage: meta.page > 1, } : { page: params.page, pageSize: params.pageSize, total: assets.length, totalPages: 1, hasNextPage: false, hasPreviousPage: false, }; return { success: true, data: { assets, pagination, }, }; } catch (error) { return { success: false, error: error instanceof Error ? error.message : "Unknown error occurred", }; } }

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/xkelxmc/uranium-mcp'

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