The Kroger MCP Server allows language models like Claude to interact with Kroger's grocery services, enabling product searches, store lookups, and cart management through the Model Context Protocol (MCP).
config.py
:# config.py
KROGER_CLIENT_ID = "YOUR_ACTUAL_CLIENT_ID"
KROGER_CLIENT_SECRET = "YOUR_ACTUAL_CLIENT_SECRET"
KROGER_REDIRECT_URI = "http://localhost:8080/callback"
To enable cart management functionality:
Run the authorization script:
python auth.py
Follow the displayed instructions:
Store the refresh token in config.py
:
KROGER_USER_REFRESH_TOKEN = "YOUR_SAVED_REFRESH_TOKEN"
Install required dependencies:
pip install requests mcp
Launch the server:
python server.py
The server uses STDIO for communication with MCP clients and doesn't open network ports. To stop the server, press Ctrl+C
in the terminal.
python /path/to/your/project/server.py
You can interact with the server programmatically using an MCP client library:
from modelcontext import Client, StdioClientTransport
async def main():
client = Client(name="example-kroger-client", version="1.0", capabilities={})
transport = StdioClientTransport(command=["python", "server.py"])
await client.connect(transport)
# Find stores near a ZIP code
store_results = await client.call_tool(
"find_stores",
{"zip_code": "45202", "limit": 1}
)
# Search for products
if store_results and len(store_results) > 0:
location_id = store_results[0].get("locationId")
product_results = await client.call_tool(
"search_products",
{"query": "milk", "location_id": location_id, "limit": 2}
)
await client.disconnect()
The server provides the following capabilities:
find_stores(zip_code: str, radius_miles: int = 10, limit: int = 5)
Locates Kroger stores near a specified ZIP code.
search_products(query: str, location_id: str, limit: int = 10)
Searches for products by keyword at a specific store location.
get_product(product_id: str, location_id: str)
Retrieves detailed information about a specific product.
add_to_cart(product_id: str, quantity: int, location_id: str)
Adds a product to the user's Kroger cart (requires user authorization).
If you try to use cart functions without authorization, you'll receive an error message instructing you to complete the OAuth2 flow.
If tokens expire, the server will attempt to refresh them automatically. If the refresh token is invalid, you'll need to re-authorize.
Kroger's API has rate limits. If exceeded, the server will return an error with HTTP 429 status code. Wait before trying again.
To add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "kroger" '{"command":"python","args":["server.py"]}'
See the official Claude Code MCP documentation for more details.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"kroger": {
"command": "python",
"args": [
"server.py"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.config/Claude/claude_desktop_config.json
2. Add this to your configuration file:
{
"mcpServers": {
"kroger": {
"command": "python",
"args": [
"server.py"
]
}
}
}
3. Restart Claude Desktop for the changes to take effect