Skip to main content
Glama
marcusquinn

Amazon Order History CSV Download MCP

by marcusquinn

get_amazon_gift_card_transactions

Retrieve detailed Amazon gift card transaction history including current balance, transaction details, and paginated records for comprehensive tracking.

Instructions

Get Amazon gift card transaction history with full details. Returns: current balance, transaction count, and detailed transactions (date, description, amount, closing balance, transaction type, order ID, claim code, serial number). Supports pagination for complete history.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
regionYesAmazon region code
max_pagesNoMaximum pages of transaction history to fetch. Default: 10. Set to 0 for unlimited.

Implementation Reference

  • Main handler function that implements the tool logic: navigates to Amazon gift card balance page, extracts current balance, paginates through transaction history extracting date, description, amount, closing balance, type, order ID, claim code, serial number for each transaction.
    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,
      };
    }
  • src/index.ts:466-486 (registration)
    Tool registration in the MCP tools list, including name, description, and input schema.
    {
      name: "get_amazon_gift_card_transactions",
      description:
        "Get Amazon gift card transaction history with full details. Returns: current balance, transaction count, and detailed transactions (date, description, amount, closing balance, transaction type, order ID, claim code, serial number). Supports pagination for complete history.",
      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,
          },
        },
        required: ["region"],
      },
  • MCP server request handler for the tool call: validates input, calls extractGiftCardData, formats output using helper, returns JSON response.
    case "get_amazon_gift_card_transactions": {
      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;
    
      // Extract gift card transactions
      const giftCardData = await extractGiftCardData(currentPage, region, {
        maxPages,
        fetchAllPages: true,
      });
    
      // Convert to export format using shared helper
      const exportData = formatGiftCardDataForExport(giftCardData);
    
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify(
              {
                status: "success",
                params: {
                  region,
                  maxPages,
                },
                ...exportData,
              },
              null,
              2,
            ),
          },
        ],
      };
    }
  • Helper function to format GiftCardData into the JSON export structure used by the tool response.
    function formatGiftCardDataForExport(
      giftCardData: GiftCardData,
    ): GiftCardExportData {
      return {
        balance: {
          amount: giftCardData.balance.balance.amount,
          currency: giftCardData.balance.balance.currency,
          formatted: giftCardData.balance.balance.formatted,
        },
        lastUpdated: giftCardData.balance.lastUpdated.toISOString(),
        region: giftCardData.region,
        transactionCount: giftCardData.transactions.length,
        transactions: giftCardData.transactions.map((t) => ({
          date: t.date.toISOString(),
          description: t.description,
          amount: {
            amount: t.amount.amount,
            currency: t.amount.currency,
            currencySymbol: t.amount.currencySymbol,
            formatted: t.amount.formatted,
          },
          closingBalance: {
            amount: t.closingBalance.amount,
            currency: t.closingBalance.currency,
            currencySymbol: t.closingBalance.currencySymbol,
            formatted: t.closingBalance.formatted,
          },
          type: t.type,
          orderId: t.orderId,
          claimCode: t.claimCode,
          serialNumber: t.serialNumber,
        })),
      };
    }
  • TypeScript interface defining the output structure (schema) for 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;
    }
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It effectively describes key behaviors: it returns detailed transaction data (listing specific fields like date, amount, order ID), supports pagination, and implies it fetches historical data. However, it lacks information on authentication requirements, rate limits, error handling, or whether it's a read-only operation, which are important for a tool accessing sensitive transaction data.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is front-loaded with the core purpose in the first sentence, followed by specific return details and pagination support. Every sentence adds value without redundancy, making it efficient and easy to parse for an AI agent.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of a transaction history tool with no annotations and no output schema, the description does well by specifying return values (balance, count, detailed fields) and pagination behavior. However, it lacks details on authentication, error cases, or data freshness, which are important for completeness in this context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with both parameters ('region' and 'max_pages') well-documented in the schema (including enum values and default). The description adds no additional parameter semantics beyond what the schema provides, such as explaining region implications or pagination details. Baseline 3 is appropriate since the schema handles the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Get Amazon gift card transaction history with full details') and resource ('Amazon gift card'), distinguishing it from siblings like 'get_amazon_gift_card_balance' (which only retrieves balance) and 'export_amazon_transactions_csv' (which exports to CSV). It explicitly mentions the scope ('full details' and 'complete history'), making the purpose unambiguous.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context by specifying it retrieves 'transaction history with full details' and 'supports pagination for complete history,' which helps differentiate it from tools like 'get_amazon_gift_card_balance' (balance-only) or export tools. However, it does not explicitly state when not to use this tool or name specific alternatives, such as for summary vs. detailed data.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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