MCPInstall
kroger-mcp logo

kroger-mcp

by CupOfOwls 79 stars CupOfOwls/kroger-mcp

A FastMCP server that provides AI assistants like Claude with seamless access to Kroger's grocery shopping functionality through the Model Context Protocol (MCP). This server enables AI assistants to find stores, search products, manage shopping carts, and access Kroger's comprehensive grocery data via the kroger-api python library.

READMEmain

🛒 Kroger MCP Server 🛍️ -- FastMCP for Kroger Shopping

A FastMCP server that provides AI assistants like Claude with access to Kroger's grocery shopping functionality through the Model Context Protocol (MCP). This server enables AI assistants to find stores, search products, manage shopping carts, and access Kroger's comprehensive grocery data via the kroger-api python library.

📚 Docs: https://cupofowls.github.io/kroger-api/building-ai-agents/agent-lab — build an AI agent with kroger-mcp, and the full tool reference.

📺 Demo

Using Claude with this MCP server to search for stores, find products, and add items to your cart:

https://github.com/user-attachments/assets/69055f5f-04f5-4ec1-96ac-330aa288fbd1

Changelog

A changelog with recent changes is here.

🚀 Quick Start

Prerequisites

You will need Kroger API credentials (free from Kroger Developer Portal). Visit the Kroger Developer Portal to:

  1. Create a developer account
  2. Register your application
  3. Get your CLIENT_ID, CLIENT_SECRET, and set your REDIRECT_URI

The first time you run a tool requiring user authentication, you'll be prompted to authorize your app through your web browser. You're granting permission to your own registered app, not to any third party.

Installation

⚠️ macOS users must use installation Option 2 ⚠️

Option 1: Using uvx with Claude Desktop (Recommended)

Once published to PyPI, you can use uvx to run the package directly without cloning the repository:

Edit Claude Desktop's configuration file:

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json

Linux: ~/.config/Claude/claude_desktop_config.json

Windows: %APPDATA%/Claude/claude_desktop_config.json

{
  "mcpServers": {
    "kroger": {
      "command": "uvx",
      "args": [
        "kroger-mcp"
      ],
      "env": {
        "KROGER_CLIENT_ID": "your_client_id",
        "KROGER_CLIENT_SECRET": "your_client_secret", 
        "KROGER_REDIRECT_URI": "http://localhost:8000/callback",
        "KROGER_USER_ZIP_CODE": "10001"
      }
    }
  }
}

Benefits of this method:

  • Automatically installs the package from PyPI if needed
  • Creates an isolated environment for running the server
  • Makes it easy to stay updated with the latest version
  • Doesn't require maintaining a local repository clone

Option 2: Using uv with a Local Clone

First, clone locally:

git clone https://github.com/CupOfOwls/kroger-mcp

Then, edit Claude Desktop's configuration file:

{
  "mcpServers": {
    "kroger": {
      "command": "uv",
      "args": [
        "--directory",
        "/path/to/cloned/kroger-mcp",
        "run",
        "kroger-mcp"
      ],
      "env": {
        "KROGER_CLIENT_ID": "your_client_id",
        "KROGER_CLIENT_SECRET": "your_client_secret", 
        "KROGER_REDIRECT_URI": "http://localhost:8000/callback",
        "KROGER_USER_ZIP_CODE": "10001"
      }
    }
  }
}

Option 3: Installing From PyPI

# Install with uv (recommended)
uv pip install kroger-mcp

# Or install with pip
pip install kroger-mcp

Option 4: Installing From Source

# Clone the repository
git clone https://github.com/CupOfOwls/kroger-mcp
cd kroger-mcp

# Install with uv (recommended)
uv sync

# Or install with pip
pip install -e .

Configuration

Pass the settings in the env block of your MCP client's JSON config, or put them in a .env file in the directory you start the server from (only its KROGER_* settings are read):

# Required: Your Kroger API credentials
KROGER_CLIENT_ID=your_client_id_here
KROGER_CLIENT_SECRET=your_client_secret_here
KROGER_REDIRECT_URI=http://localhost:8000/callback

# Optional: Default zip code for location searches
KROGER_USER_ZIP_CODE=90274

# Optional: The scopes the user grants at sign-in (default: product.compact cart.basic:write).
# Add profile.compact for get_user_profile, but only if your app is registered for the Identity API.
# KROGER_USER_SCOPES=product.compact cart.basic:write profile.compact

Running the Server

# With uv (recommended)
uv run kroger-mcp

# With uvx (directly from PyPI without installation)
uvx kroger-mcp

# Or with Python directly
python server.py

# Options such as an HTTP transport (see kroger-mcp --help)
uvx kroger-mcp --transport streamable-http --port 8000

# With FastMCP CLI for development
fastmcp dev server.py --with-editable .

🛠️ Features

💬 Built-In MCP Prompts

  • Shopping Path: Find optimal path through store for a grocery list
  • Pharmacy Check: Check if pharmacy at preferred location is open
  • Store Selection: Help user set their preferred Kroger store
  • Recipe Shopping: Find recipes and add ingredients to cart

📚 Available Tools

Location Tools

ToolDescriptionAuth Required
search_locationsFind Kroger stores near a zip codeNo
get_location_detailsGet detailed information about a specific storeNo
set_preferred_locationSet a preferred store for future operationsNo
get_preferred_locationGet the currently set preferred storeNo
check_location_existsVerify if a location ID is validNo

Product Tools

ToolDescriptionAuth Required
search_productsSearch for products by name, brand, or other criteriaNo
bulk_search_productsRun up to 25 product searches in a single callNo
get_product_detailsGet detailed product information including pricingNo
search_products_by_idFind products by their specific product IDNo
get_product_imagesGet product images from specific perspective (front, back, etc.)No

Cart Tools

ToolDescriptionAuth Required
add_items_to_cartAdd a single item to cartYes
bulk_add_to_cartAdd multiple items to cart in one operationYes
view_current_cartView items currently in your local cart trackingNo
remove_from_cartRemove items from local cart trackingNo
clear_current_cartClear all items from local cart trackingNo
mark_order_placedMove current cart to order historyNo
view_order_historyView history of placed ordersNo

Information Tools

ToolDescriptionAuth Required
list_chainsGet all Kroger-owned chainsNo
get_chain_detailsGet details about a specific chainNo
check_chain_existsCheck if a chain existsNo
list_departmentsGet all store departmentsNo
get_department_detailsGet details about a specific departmentNo
check_department_existsCheck if a department existsNo

Profile Tools

ToolDescriptionAuth Required
get_user_profileGet authenticated user's profile informationYes
test_authenticationCheck that the user is signed in and the token has not expired, refreshing it if it hasNo
get_authentication_infoGet detailed authentication statusNo
force_reauthenticateDelete the saved sign-in, so the user can sign in againNo

start_authentication asks the user to grant product.compact and cart.basic:write, which the cart tools need. get_user_profile also needs profile.compact, from the Identity API. An app may request only the scopes of the API products it is registered for, and Kroger refuses the whole sign-in with invalid_scope when one is missing, so profile.compact is not requested by default. To use get_user_profile, register the Identity API for your app in the Kroger Developer Portal, set KROGER_USER_SCOPES to product.compact cart.basic:write profile.compact, restart the server, and sign in again.

Utility Tools

ToolDescriptionAuth Required
get_current_datetimeGet current system date and timeNo

🧰 Local-Only Cart Tracking

Since the Kroger API doesn't provide cart viewing functionality, this server maintains local tracking:

Local Cart Storage

  • File: kroger_cart.json
  • Contents: Current cart items with timestamps
  • Automatic: Created and updated automatically

Order History

  • File: kroger_order_history.json
  • Contents: Historical orders with placement timestamps
  • Usage: Move completed carts to history with mark_order_placed

Where these files live

State files (cart, order history, preferences) and OAuth tokens are stored in the first matching location:

  1. $KROGER_TOKEN_DIR, if you set that environment variable
  2. $XDG_DATA_HOME/kroger-mcp/ (defaults to ~/.local/share/kroger-mcp/) on macOS/Linux
  3. %APPDATA%\kroger-mcp\ on Windows

They are never written to the current working directory, which may be read-only or change between sessions under MCP hosts like Claude Desktop. Files from older versions that live in the working directory are migrated automatically on first use.

Several server processes can share the directory, for example one for Claude Desktop and one for Claude Code. Each change to a state file, and each renewal of the sign-in, holds a lock on that file (a .lock file beside it), so the processes do not overwrite each other's changes or sign each other out.

⚡ Concurrent calls

Each tool that calls the Kroger API or reads a state file runs in a worker thread, so a slow Kroger request holds up only its own call. The assistant's other calls go on, and so do the other clients of a server that uses the streamable-http or sse transport. Cancelling a call answers at once, but the request it already sent still finishes: a cancelled add_items_to_cart can still add the items.

⚠️ Error Handling

A tool that fails returns an MCP error result (isError: true), so the assistant can see what went wrong and correct its next call:

  • Text content: what went wrong, followed by Next step: and what to do about it, often naming the tool to call.
  • Structured content: an error object with a stable type, the message, the next_step, the tool, and every detail the kroger-api package has about a Kroger API error: status_code, Kroger's kroger_code and kroger_message, the request method and url, the correlation_id, a hint, and the response_body.
typeWhen
invalid_argumentsAn argument breaks the tool's input schema (wrong pattern, out of range, unknown name). errors lists each one. No request is sent.
invalid_parameterkroger-api rejected a value the schema cannot check, such as a search term of more than 8 words. No request is sent.
authentication_requiredThe user is not signed in, or the sign-in expired and could not be renewed.
location_requiredA product tool got no location_id and no preferred location is set.
bad_request, authentication_error, permission_denied, not_found, rate_limited, server_errorThe Kroger API answered 400, 401, 403, 404, 429, or 5xx.
connection_error, timeoutThe Kroger API could not be reached, or did not answer within 30 seconds.
configuration_errorA setting such as KROGER_CLIENT_ID is missing or invalid. Fix the server configuration and restart it.
local_state_errorA cart, order history, or preferences file could not be read or written.

A cart add that times out, loses its connection after the request may have been sent, or gets a 5xx has outcome_unknown: true. Kroger may have added the items anyway, so the next step says to have the user check their cart before adding again, instead of retrying.

A search that finds nothing is not an error: it returns count: 0 and a message. The full list of error types is in the MCP tools reference.

🚧 Kroger Public API Limitations

  • View Only: The remove_from_cart and clear_current_cart tools ONLY affect local tracking, not the actual Kroger cart
  • Local Sync: Use these tools only when the user has already removed items from their cart in the Kroger app/website
  • One-Way: Items can be added to the Kroger cart but not removed through the Public API. The Partner API would allow these things, but that requires entering a contract with Kroger.
APIVersionRate LimitNotes
Authorization1.0.13No specific limitToken management
Products1.2.410,000 calls/daySearch and product details
Locations1.2.21,600 calls/day per endpointStore locations and details
Cart1.2.35,000 calls/dayAdd/manage cart items
Identity1.2.35,000 calls/dayUser profile information

Note: Rate limits are enforced per endpoint, not per operation. You can distribute calls across operations using the same endpoint as needed.

🏫 Basic Workflow

  1. Set up a preferred location:

    User: "Find Kroger stores near 90274"
    Assistant: [Uses search_locations tool]
    User: "Set the first one as my preferred location"
    Assistant: [Uses set_preferred_location tool]
    
  2. Search and add products:

    User: "Add milk to my cart"
    Assistant: [Uses search_products, then add_items_to_cart]
    
    User: "Add bread, eggs, and cheese to my cart"
    Assistant: [Uses search_products for each, then bulk_add_to_cart]
    
  3. Manage cart and orders:

    User: "What's in my cart?"
    Assistant: [Uses view_current_cart tool to see local memory]
    
    User: "I placed the order on the Kroger website"
    Assistant: [Uses mark_order_placed tool, moving current cart to the order history]
    

🍪 OAuth2 Authentication

When Claude attempts to modify your Kroger account, you will be asked to insert a link into your browser that will handle authentication and allow Claude to add/remove items from your cart. Ensure that you have already made a Kroger account (this is different than your Kroger development account) before attempting to paste this link into your browser to initiate authentication.

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

⚠️ Disclaimer

This is an unofficial MCP server for the Kroger Public API. It is not affiliated with, endorsed by, or sponsored by Kroger.

For questions about the Kroger API, visit the Kroger Developer Portal or read the kroger-api package documentation.


MseeP.ai Security Assessment Badge

More E-commerce Solutions MCP servers

Similar servers from the same category.

Alipay's official MCP Server, allowing you to easily integrate transaction creation, query, refund, and other capabilities offered by the Alipay Open Platform into your LLM applications.

FormQuery+5

Bridges WordPress websites and WooCommerce data with local clients through REST API calls, enabling content access without direct streaming connections.

ConnectDirect

Dodo Payments

dodopayments

Provides a bridge to the Dodo Payments API for processing payments, managing subscriptions, and handling licensing through over 40 specialized tools for customer and product management.

payment

Integrates with Adfin's financial management platform to enable credit control checks, invoice creation, and document uploads through dynamically generated API tools and specialized file system capabilities.

filesystempayment