Skip to main content
Glama
marcusquinn

Amazon Order History CSV Download MCP

by marcusquinn

export_amazon_gift_cards_csv

Export Amazon gift card transaction history to CSV for tracking usage and reconciling balances across 16 regional sites.

Instructions

Export Amazon gift card transaction history to CSV file. CSV columns: Date, Description, Amount, Closing Balance, Type (credit/debit), Order ID, Claim Code, Serial Number, Region. Useful for tracking gift card usage and reconciling balances.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
regionYesAmazon region code
output_pathNoFull path to save CSV file. Defaults to ~/Downloads/amazon-{region}-gift-cards-{date}.csv
max_pagesNoMaximum pages of transaction history to fetch. Default: 10. Set to 0 for unlimited.

Implementation Reference

  • src/index.ts:439-464 (registration)
    Tool registration in MCP tools array, including name, description, and input schema (region required, output_path and max_pages optional).
    {
      name: "export_amazon_gift_cards_csv",
      description:
        "Export Amazon gift card transaction history to CSV file. CSV columns: Date, Description, Amount, Closing Balance, Type (credit/debit), Order ID, Claim Code, Serial Number, Region. Useful for tracking gift card usage and reconciling balances.",
      inputSchema: {
        type: "object",
        properties: {
          region: {
            type: "string",
            description: "Amazon region code",
            enum: getRegionCodes(),
          },
          output_path: {
            type: "string",
            description:
              "Full path to save CSV file. Defaults to ~/Downloads/amazon-{region}-gift-cards-{date}.csv",
          },
          max_pages: {
            type: "number",
            description:
              "Maximum pages of transaction history to fetch. Default: 10. Set to 0 for unlimited.",
            default: 10,
          },
        },
        required: ["region"],
      },
  • Input schema defining parameters for the tool: region (required, enum of Amazon regions), optional output_path and max_pages.
    inputSchema: {
      type: "object",
      properties: {
        region: {
          type: "string",
          description: "Amazon region code",
          enum: getRegionCodes(),
        },
        output_path: {
          type: "string",
          description:
            "Full path to save CSV file. Defaults to ~/Downloads/amazon-{region}-gift-cards-{date}.csv",
        },
        max_pages: {
          type: "number",
          description:
            "Maximum pages of transaction history to fetch. Default: 10. Set to 0 for unlimited.",
          default: 10,
        },
      },
      required: ["region"],
    },
  • Main tool handler in MCP call switch: validates input, fetches gift card data, formats for CSV, determines output path, exports CSV, returns success/error with file info and balance.
    case "export_amazon_gift_cards_csv": {
      const regionParam = args?.region as string | undefined;
      const regionError = validateRegion(regionParam, args);
      if (regionError) return regionError;
      const region = regionParam!;
    
      const currentPage = await getPage();
      const outputPath = args?.output_path as string | undefined;
      const maxPages = (args?.max_pages as number) ?? 10;
    
      // Extract gift card transactions
      const giftCardData = await extractGiftCardData(currentPage, region, {
        maxPages,
        fetchAllPages: true,
      });
    
      // Convert to CSV format using shared helper
      const csvData = formatGiftCardDataForCSV(giftCardData);
    
      // Generate output path
      const today = new Date().toISOString().split("T")[0];
      const finalPath = getOutputPath(outputPath, "gift-cards", region, {
        endDate: today,
      });
    
      // Export to CSV
      const exportResult = await exportGiftCardTransactionsCSV(
        csvData,
        finalPath,
      );
    
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify(
              {
                status: exportResult.success ? "success" : "error",
                params: {
                  region,
                  maxPages,
                },
                balance: giftCardData.balance.balance,
                transactionCount: giftCardData.transactions.length,
                filePath: exportResult.filePath,
                rowCount: exportResult.rowCount,
                error: exportResult.error,
              },
              null,
              2,
            ),
          },
        ],
      };
    }
  • Transforms nested GiftCardData into flat array of GiftCardTransactionCSVData for CSV export, adding region to each row.
    function formatGiftCardDataForCSV(
      giftCardData: GiftCardData,
    ): GiftCardTransactionCSVData[] {
      return giftCardData.transactions.map((t) => ({
        date: t.date,
        description: t.description,
        amount: t.amount,
        closingBalance: t.closingBalance,
        type: t.type,
        orderId: t.orderId,
        claimCode: t.claimCode,
        serialNumber: t.serialNumber,
        region: giftCardData.region,
      }));
    }
    
    // Handle list tools request
  • Exports the formatted gift card transactions to CSV file using predefined columns (GIFT_CARD_CSV_COLUMNS), handles errors, returns result with row count.
    export async function exportGiftCardTransactionsCSV(
      transactions: GiftCardTransactionCSVData[],
      outputPath: string,
    ): Promise<ExportResult> {
      try {
        const csv = toCSVWithColumns(transactions, GIFT_CARD_CSV_COLUMNS);
        await writeFile(outputPath, csv, "utf-8");
    
        return {
          success: true,
          filePath: outputPath,
          rowCount: transactions.length,
        };
      } catch (error) {
        return {
          success: false,
          filePath: outputPath,
          rowCount: 0,
          error: String(error),
        };
      }
    }
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 describes what the tool does (export to CSV) and lists the CSV columns, which helps understand the output format. However, it doesn't mention authentication requirements, rate limits, whether it's a read-only operation, or potential side effects like file system changes. The description adds some value but leaves important behavioral aspects unspecified.

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 perfectly concise with two sentences that each serve distinct purposes: the first states the core functionality and output format, the second provides usage context. Every word earns its place with no redundancy or unnecessary elaboration.

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 tool's moderate complexity (export operation with 3 parameters), no annotations, and no output schema, the description does a good job covering the essentials: what it does, what the output contains, and when to use it. However, it doesn't address authentication requirements or potential limitations (like pagination behavior implied by max_pages parameter), which would be helpful given the lack of annotations.

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

Parameters4/5

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

Schema description coverage is 100%, so the schema already documents all three parameters thoroughly. The description doesn't add any parameter-specific information beyond what's in the schema, but with complete schema coverage and only 3 parameters, this is acceptable. The baseline would be 3, but the description's clarity about the overall purpose and output format elevates it slightly.

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 ('Export Amazon gift card transaction history to CSV file') and distinguishes it from siblings by focusing on gift cards rather than items, orders, shipments, or general transactions. It explicitly mentions the resource (Amazon gift cards) and output format (CSV).

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 about when to use this tool ('Useful for tracking gift card usage and reconciling balances'), which differentiates it from siblings like get_amazon_gift_card_transactions (which likely returns data without exporting). However, it doesn't explicitly state when NOT to use it or name specific alternatives for different scenarios.

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