Skip to main content
Glama
marcusquinn

Amazon Order History CSV Download MCP

by marcusquinn

export_amazon_transactions_csv

Export Amazon payment transactions to CSV for record-keeping or analysis. Extracts transaction details including date, order ID, amount, and payment method from order history.

Instructions

Export Amazon payment transactions to CSV file. Extracts transaction data from each order's detail page. CSV columns include: date, order ID, amount, payment method, card info. For faster bulk transaction export, consider get_amazon_transactions which scrapes the dedicated transactions page.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
regionYesAmazon region code
yearNoYear to export (defaults to current year)
start_dateNoStart date in ISO format (YYYY-MM-DD)
end_dateNoEnd date in ISO format (YYYY-MM-DD)
output_pathNoFull path to save CSV file. Defaults to ~/Downloads/amazon-{region}-transactions-{year}-{date}.csv
max_ordersNoMaximum number of orders to process

Implementation Reference

  • src/index.ts:345-381 (registration)
    Tool registration entry defining the tool name, description, input schema (region, dates, output_path, max_orders), and requirements.
    {
      name: "export_amazon_transactions_csv",
      description:
        "Export Amazon payment transactions to CSV file. Extracts transaction data from each order's detail page. CSV columns include: date, order ID, amount, payment method, card info. For faster bulk transaction export, consider get_amazon_transactions which scrapes the dedicated transactions page.",
      inputSchema: {
        type: "object",
        properties: {
          region: {
            type: "string",
            description: "Amazon region code",
            enum: getRegionCodes(),
          },
          year: {
            type: "number",
            description: "Year to export (defaults to current year)",
          },
          start_date: {
            type: "string",
            description: "Start date in ISO format (YYYY-MM-DD)",
          },
          end_date: {
            type: "string",
            description: "End date in ISO format (YYYY-MM-DD)",
          },
          output_path: {
            type: "string",
            description:
              "Full path to save CSV file. Defaults to ~/Downloads/amazon-{region}-transactions-{year}-{date}.csv",
          },
          max_orders: {
            type: "number",
            description: "Maximum number of orders to process",
          },
        },
        required: ["region"],
      },
    },
  • Primary handler for the tool: validates region, fetches orders enabling transaction extraction, exports transactions to CSV using exportTransactionsCSV, computes timing estimates, and returns structured result with file path and counts.
    case "export_amazon_transactions_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 year = args?.year as number | undefined;
      const startDate = args?.start_date as string | undefined;
      const endDate = args?.end_date as string | undefined;
      const maxOrders = args?.max_orders as number | undefined;
      const outputPath = getOutputPath(
        args?.output_path as string | undefined,
        "transactions",
        region,
        { year, startDate, endDate },
      );
    
      const fetchResult = await fetchOrders(currentPage, amazonPlugin, {
        region,
        year,
        startDate,
        endDate,
        includeItems: false,
        includeShipments: false,
        includeTransactions: true,
        maxOrders,
      });
    
      const timeEstimate = estimateExtractionTime(fetchResult.orders.length, {
        includeItems: false,
        includeShipments: false,
      });
    
      const exportResult = await exportTransactionsCSV(
        fetchResult.transactions,
        outputPath,
      );
    
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify(
              {
                status: exportResult.success ? "success" : "error",
                params: {
                  region,
                  year,
                  startDate,
                  endDate,
                  maxOrders,
                  outputPath,
                },
                filePath: exportResult.filePath,
                rowCount: exportResult.rowCount,
                error: exportResult.error,
                fetchErrors: fetchResult.errors,
                timing: {
                  orderCount: fetchResult.orders.length,
                  transactionCount: fetchResult.transactions.length,
                  estimate: timeEstimate.formattedEstimate,
                  warnings: timeEstimate.warnings,
                  recommendations: timeEstimate.recommendations,
                },
              },
              null,
              2,
            ),
          },
        ],
      };
    }
  • Helper function that converts Transaction array to CSV using predefined TRANSACTION_CSV_COLUMNS and writes to the specified output file path.
    export async function exportTransactionsCSV(
      transactions: Transaction[],
      outputPath: string,
    ): Promise<ExportResult> {
      try {
        const csv = toCSVWithColumns(transactions, TRANSACTION_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),
        };
      }
    }
  • Helper function to generate or use provided output file path in ~/Downloads with formatted filename like amazon-{region}-transactions-{year}-{date}.csv.
    export function getOutputPath(
      outputPath: string | undefined,
      exportType: "orders" | "items" | "shipments" | "transactions" | "gift-cards",
      region: string,
      options?: {
        year?: number;
        startDate?: string;
        endDate?: string;
      },
    ): string {
      if (outputPath) {
        return outputPath;
      }
    
      const filename = generateExportFilename(exportType, region, options);
      return join(getDefaultDownloadsPath(), filename);
    }
  • Imports TRANSACTION_CSV_COLUMNS which defines the CSV structure/schema for transactions output.
    import {
      ORDER_CSV_COLUMNS,
      ITEM_CSV_COLUMNS,
      SHIPMENT_CSV_COLUMNS,
      TRANSACTION_CSV_COLUMNS,
      GIFT_CARD_CSV_COLUMNS,
      OrderCSVData,
      GiftCardTransactionCSVData,
    } from "./csv-columns";
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 explains the extraction method ('Extracts transaction data from each order's detail page'), which adds useful context beyond the basic 'export' action. However, it lacks details on permissions needed, rate limits, error handling, or whether the operation is idempotent, leaving gaps for a mutation-like tool (exporting files).

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, followed by implementation details and a clear alternative. Both sentences earn their place: the first defines the tool and its output format, the second provides critical usage guidance. No wasted words or redundancy.

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 complexity (6 parameters, file export operation) and no output schema, the description does well by specifying the CSV columns and extraction method. However, it could better address behavioral aspects like file overwriting or error scenarios. With no annotations, it's mostly complete but has minor gaps in operational transparency.

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?

The schema description coverage is 100%, so all parameters are documented in the schema itself. The description does not add any parameter-specific details beyond what's in the schema (e.g., it doesn't explain the relationship between 'year' and 'start_date/end_date' or clarify 'max_orders' behavior). Baseline 3 is appropriate as 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 ('Export Amazon payment transactions to CSV file') and resource ('transaction data from each order's detail page'), distinguishing it from sibling tools like 'export_amazon_orders_csv' or 'export_amazon_items_csv' by focusing specifically on payment transactions. It provides concrete details about the CSV columns, 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 Guidelines5/5

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

The description explicitly provides when to use this tool vs. alternatives by stating 'For faster bulk transaction export, consider get_amazon_transactions which scrapes the dedicated transactions page.' This gives clear guidance on choosing between detailed extraction from order pages vs. faster bulk export, addressing a key decision point for users.

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