Skip to main content
Glama
marcusquinn

Amazon Order History CSV Download MCP

by marcusquinn

get_amazon_gift_card_balance

Check Amazon gift card balance and view transaction history with pagination support across multiple regions.

Instructions

Get current Amazon gift card balance and transaction history. Returns: current balance, last updated timestamp, and paginated transaction history (date, description, amount, closing balance, type, associated order ID, claim code, serial number). Supports fetching complete history across multiple pages.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
regionYesAmazon region code
max_pagesNoMaximum pages of transaction history to fetch. Default: 10. Set to 0 for unlimited.
fetch_all_pagesNoAutomatically paginate through all available transaction history. Default: true.

Implementation Reference

  • Core handler function that implements the tool logic: navigates to Amazon gift card balance page (/gc/balance), extracts current balance, handles pagination to fetch transaction history up to max_pages, parses transactions with details like orderId, claimCode, serialNumber.
    export async function extractGiftCardData( page: Page, region: string, options: GiftCardExtractionOptions = {}, ): Promise<GiftCardData> { const { maxPages = 10, fetchAllPages = true } = options; const regionConfig = getRegionByCode(region); const currency = regionConfig?.currency || "USD"; const url = getGiftCardPageUrl(region); // Navigate to gift card balance page await page.goto(url, { waitUntil: "domcontentloaded", timeout: 30000 }); // Wait for the balance table to load await page .waitForSelector( 'table.a-bordered tbody tr, [data-testid="gc-balance"], #gc-balance', { timeout: 10000 }, ) .catch(() => {}); // Extract balance (from first row's closing balance, or dedicated element) const balance = await extractBalance(page, currency); // Extract transactions from all pages const allTransactions: GiftCardTransaction[] = []; let pageCount = 0; let hasMorePages = true; while (hasMorePages) { pageCount++; // Extract transactions from current page const pageTransactions = await extractTransactionsFromTable(page, currency); allTransactions.push(...pageTransactions); // Check if we should continue to next page if (!fetchAllPages) { hasMorePages = false; continue; } if (maxPages > 0 && pageCount >= maxPages) { hasMorePages = false; continue; } // Check for and click "Next" pagination button hasMorePages = await goToNextGiftCardPage(page); // Wait for the new page content to load await page.waitForTimeout(500); await page .waitForSelector("table.a-bordered tbody tr", { timeout: 5000 }) .catch(() => {}); } // Deduplicate transactions (in case of overlap between pages) const uniqueTransactions = deduplicateTransactions(allTransactions); return { balance, transactions: uniqueTransactions, region, }; }
  • Tool schema definition including name, description, and inputSchema for parameters: region (required), max_pages, fetch_all_pages.
    { name: "get_amazon_gift_card_balance", description: "Get current Amazon gift card balance and transaction history. Returns: current balance, last updated timestamp, and paginated transaction history (date, description, amount, closing balance, type, associated order ID, claim code, serial number). Supports fetching complete history across multiple pages.", inputSchema: { type: "object", properties: { region: { type: "string", description: "Amazon region code", enum: getRegionCodes(), }, max_pages: { type: "number", description: "Maximum pages of transaction history to fetch. Default: 10. Set to 0 for unlimited.", default: 10, }, fetch_all_pages: { type: "boolean", description: "Automatically paginate through all available transaction history. Default: true.", default: true, }, }, required: ["region"], }, },
  • MCP server tool dispatcher case that validates input, gets browser page, calls extractGiftCardData, formats and returns the result as JSON.
    case "get_amazon_gift_card_balance": { const regionParam = args?.region as string | undefined; const regionError = validateRegion(regionParam, args); if (regionError) return regionError; const region = regionParam!; const currentPage = await getPage(); const maxPages = (args?.max_pages as number) ?? 10; const fetchAllPages = (args?.fetch_all_pages as boolean) ?? true; const giftCardData = await extractGiftCardData(currentPage, region, { maxPages, fetchAllPages, }); return { content: [ { type: "text", text: JSON.stringify( { status: "success", params: { region, maxPages, fetchAllPages, }, balance: giftCardData.balance.balance, lastUpdated: giftCardData.balance.lastUpdated.toISOString(), transactionCount: giftCardData.transactions.length, transactions: giftCardData.transactions.map((t) => ({ date: t.date.toISOString(), description: t.description, amount: t.amount, closingBalance: t.closingBalance, type: t.type, orderId: t.orderId, claimCode: t.claimCode, serialNumber: t.serialNumber, })), }, null, 2, ), }, ], }; }
  • src/index.ts:638-640 (registration)
    Registration of the tools list (including get_amazon_gift_card_balance) for MCP ListToolsRequest.
    server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools }; });
  • TypeScript interface defining the output structure of the gift card data returned by the handler.
    export interface GiftCardData { /** Current gift card balance */ balance: GiftCardBalance; /** Transaction history */ transactions: GiftCardTransaction[]; /** Region this data was extracted from */ region: string; }

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/marcusquinn/amazon-order-history-csv-download-mcp'

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