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}`, }; } }

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