Skip to main content
Glama
marcusquinn

Amazon Order History CSV Download MCP

by marcusquinn

check_amazon_auth_status

Verify Amazon login status for a specific region to ensure authentication before downloading order history CSV files.

Instructions

Check if the browser session is authenticated with Amazon for a specific region. Returns authentication status (authenticated/not authenticated), current URL, and any error messages. Use this to verify login status before running other tools, or to prompt user to log in if session expired.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
regionYesAmazon region code to check authentication for

Implementation Reference

  • src/index.ts:488-504 (registration)
    Tool registration including name, description, and input schema (region required).
      {
        name: "check_amazon_auth_status",
        description:
          "Check if the browser session is authenticated with Amazon for a specific region. Returns authentication status (authenticated/not authenticated), current URL, and any error messages. Use this to verify login status before running other tools, or to prompt user to log in if session expired.",
        inputSchema: {
          type: "object",
          properties: {
            region: {
              type: "string",
              description: "Amazon region code to check authentication for",
              enum: getRegionCodes(),
            },
          },
          required: ["region"],
        },
      },
    ];
  • Input schema definition requiring 'region' parameter with enum of supported Amazon regions.
    inputSchema: {
      type: "object",
      properties: {
        region: {
          type: "string",
          description: "Amazon region code to check authentication for",
          enum: getRegionCodes(),
        },
      },
      required: ["region"],
    },
  • MCP tool dispatch handler: validates region, calls AmazonPlugin.checkAuthStatus, formats response with auth status, username, message, and login URL if needed.
    case "check_amazon_auth_status": {
      const regionParam = args?.region as string | undefined;
      const regionError = validateRegion(regionParam, args);
      if (regionError) return regionError;
      const region = regionParam!;
    
      const currentPage = await getPage();
      const authStatus = await amazonPlugin.checkAuthStatus(
        currentPage,
        region,
      );
    
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify(
              {
                status: authStatus.authenticated ? "success" : "error",
                params: {
                  region,
                },
                authenticated: authStatus.authenticated,
                username: authStatus.username,
                message: authStatus.message,
                loginUrl: authStatus.authenticated
                  ? undefined
                  : amazonPlugin.getLoginUrl(region),
              },
              null,
              2,
            ),
          },
        ],
      };
    }
  • Core authentication check implementation: navigates to order-history if needed, checks for sign-in selectors (indicating unauthenticated), logged-in nav elements (with username extraction), or order content presence.
    async checkAuthStatus(page: Page, region: string): Promise<AuthStatus> {
      const regionConfig = getRegionByCode(region);
      if (!regionConfig) {
        return {
          authenticated: false,
          region,
          message: `Unknown region: ${region}`,
        };
      }
    
      try {
        // Check current URL - if already on Amazon, don't navigate again
        const currentUrl = page.url();
        if (!currentUrl.includes(regionConfig.domain)) {
          const url = `https://www.${regionConfig.domain}/gp/css/order-history`;
          await page.goto(url, { waitUntil: "domcontentloaded", timeout: 60000 });
          // Wait for page content instead of fixed delay
          await page
            .waitForSelector(
              ".order-card, #signInSubmit, #ap_email, .a-box-group",
              { timeout: 2000 },
            )
            .catch(() => {});
        }
    
        // Check for sign-in page indicators (multiple patterns)
        const signInIndicators = [
          "#signInSubmit",
          "#ap_email",
          'input[name="email"]',
          "#ap_password",
          '[data-action="sign-in"]',
          ".auth-pagelet-container",
        ];
    
        for (const selector of signInIndicators) {
          const count = await page.locator(selector).count();
          if (count > 0) {
            return {
              authenticated: false,
              region,
              message: "Not logged in - sign in required",
            };
          }
        }
    
        // If we're on any Amazon page that's NOT a sign-in page, we're probably logged in
        // Check for common logged-in indicators
        const loggedInIndicators = [
          "#nav-link-accountList",
          "#nav-orders",
          ".nav-line-1",
          "#nav-al-container",
        ];
    
        for (const selector of loggedInIndicators) {
          const count = await page.locator(selector).count();
          if (count > 0) {
            // Try to get username
            const username = await getTextByXPaths(
              page,
              [
                '//span[@id="nav-link-accountList-nav-line-1"]',
                '//span[contains(@class, "nav-line-1")]',
              ],
              "",
            );
    
            return {
              authenticated: true,
              username: username || undefined,
              region,
              message: "Authenticated",
            };
          }
        }
    
        // Check if page contains order-related content
        const pageContent = await page.content();
        if (
          pageContent.includes("your-orders") ||
          pageContent.includes("order-card") ||
          pageContent.includes("orderCard")
        ) {
          return {
            authenticated: true,
            region,
            message: "Authenticated (detected order content)",
          };
        }
    
        return {
          authenticated: false,
          region,
          message: "Unable to determine authentication status",
        };
      } catch (error) {
        return {
          authenticated: false,
          region,
          message: `Error checking auth: ${error}`,
        };
      }
    }
Behavior4/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 what the tool does (checks authentication status), what it returns (status, URL, error messages), and its purpose in a workflow (verification before other tools). However, it lacks details on potential side effects, rate limits, or specific error handling beyond mentioning 'error messages'.

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 usage guidelines. Both sentences are essential—the first explains what the tool does, and the second explains when to use it—with zero 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 low complexity (one parameter, no output schema, no annotations), the description is mostly complete. It covers purpose, usage, and output details. However, it could be more complete by specifying the exact format of the return values (e.g., structured data types) or any prerequisites, though this is mitigated by the simple 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%, so the schema fully documents the single parameter 'region' with its enum values. The description adds no additional parameter semantics beyond what the schema provides, such as explaining why region matters for authentication or how it affects the check. This meets the baseline for high schema coverage.

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 ('Check if the browser session is authenticated'), the resource ('Amazon for a specific region'), and the output ('authentication status, current URL, and any error messages'). It distinguishes this tool from its siblings, which are all data export or retrieval tools, by focusing on authentication verification rather than data extraction.

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 states when to use this tool ('to verify login status before running other tools') and when not to use it ('or to prompt user to log in if session expired'), providing clear context for its application. It implies alternatives by suggesting it should precede other tools, though it doesn't name specific alternatives.

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