Skip to main content
Glama

instacart_clear_cart

Remove all items from your Instacart shopping cart to start fresh or cancel a pending order.

Instructions

Remove all items from the Instacart cart.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The actual implementation of clearCart() function that removes all items from the Instacart cart. It navigates to the checkout page, loops through all remove buttons and clicks them, saves cookies, and returns success status with count of removed items.
    export async function clearCart(): Promise<{ success: boolean; message: string }> {
      const { page, context } = await initBrowser();
    
      try {
        await page.goto(`${INSTACART_BASE_URL}/store/checkout`, { waitUntil: "networkidle", timeout: DEFAULT_TIMEOUT });
        await page.waitForTimeout(2000);
    
        // Find and click remove buttons for all items
        let itemsRemoved = 0;
        while (true) {
          const removeButton = await page.$('[data-testid="remove-item"], button:has-text("Remove"), [aria-label*="remove"]');
          if (!removeButton) break;
    
          await removeButton.click();
          await page.waitForTimeout(500);
          itemsRemoved++;
    
          // Safety limit
          if (itemsRemoved > 100) break;
        }
    
        await saveCookies(context);
    
        return {
          success: true,
          message: itemsRemoved > 0 ? `Removed ${itemsRemoved} items from cart` : "Cart was already empty",
        };
      } catch (error) {
        throw new Error(`Failed to clear cart: ${error instanceof Error ? error.message : String(error)}`);
      }
    }
  • src/index.ts:326-344 (registration)
    The tool handler registration in the CallToolRequestSchema switch statement. When instacart_clear_cart is called, it executes clearCart() from browser.ts and formats the response as JSON.
    case "instacart_clear_cart": {
      const result = await clearCart();
    
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify(
              {
                success: result.success,
                message: result.message,
              },
              null,
              2
            ),
          },
        ],
      };
    }
  • Tool schema definition for instacart_clear_cart. Defines the tool name, description ('Remove all items from the Instacart cart.'), and input schema (empty object with no required parameters).
      name: "instacart_clear_cart",
      description:
        "Remove all items from the Instacart cart.",
      inputSchema: {
        type: "object",
        properties: {},
      },
    },

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/markswendsen-code/mcp-instacart'

If you have feedback or need assistance with the MCP directory API, please join our Discord server