> ## Documentation Index
> Fetch the complete documentation index at: https://betterdatainc.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Claude MCP Integration

> Connect your store to Claude Desktop with MCP

The Model Context Protocol (MCP) is Anthropic's standard for connecting Claude to external tools and data sources. This guide shows how to create an MCP server for your e-commerce store.

## What is MCP?

MCP allows Claude Desktop to:

* **Tools**: Call your backend functions (search, add to cart, checkout)
* **Resources**: Access live data feeds (product catalog, inventory)
* **Prompts**: Use pre-defined conversation templates

## Quick Setup

### 1. Install the Package

```bash theme={null}
npm install @commercegateway/commerce-gateway
```

### 2. Create Your MCP Server

```typescript mcp-server.ts theme={null}
import { MCPServer } from '@commercegateway/commerce-gateway/mcp';
import { MyBackend } from './backend';

const server = new MCPServer({
  backends: {
    products: new MyBackend(),
    cart: new MyBackend(),
  },
  tools: [
    'search_products',
    'get_product_details', 
    'add_to_cart',
    'check_inventory',
    'get_recommendations',
    'create_order',
  ],
  resources: ['catalog'],
  prompts: ['shopping_assistant'],
  name: 'my-store',
  version: '1.0.0',
});

server.start();
```

### 3. Configure Claude Desktop

Add to `~/.config/claude/claude_desktop_config.json` (macOS) or `%APPDATA%\Claude\claude_desktop_config.json` (Windows):

```json theme={null}
{
  "mcpServers": {
    "my-store": {
      "command": "node",
      "args": ["/absolute/path/to/mcp-server.js"],
      "env": {
        "REDIS_URL": "redis://localhost:6379",
        "API_KEY": "your-api-key"
      }
    }
  }
}
```

### 4. Restart Claude Desktop

Close and reopen Claude Desktop. Your tools should now be available!

## Built-in Tools

The gateway includes 6 commerce tools out of the box:

| Tool                  | Description                         |
| --------------------- | ----------------------------------- |
| `search_products`     | Search product catalog with filters |
| `get_product_details` | Get detailed product info by ID     |
| `add_to_cart`         | Add item to shopping cart           |
| `check_inventory`     | Check stock availability            |
| `get_recommendations` | Get product recommendations         |
| `create_order`        | Create order from cart              |

## Example Conversation

<Steps>
  <Step title="User asks about products">
    > "What wireless headphones do you have?"

    Claude calls `search_products` with query "wireless headphones"
  </Step>

  <Step title="Claude shows results">
    > "I found 3 wireless headphones:
    >
    > 1. **Premium Wireless Headphones** - \$299.99 ⭐ 4.8/5
    >    Active noise cancellation, 30-hour battery
    >
    > 2. **Sport Earbuds** - \$149.99 ⭐ 4.6/5
    >    Water resistant, 8-hour battery
    >
    > Would you like details on any of these?"
  </Step>

  <Step title="User adds to cart">
    > "Add the Premium headphones in black to my cart"

    Claude calls `add_to_cart` with product ID and variant
  </Step>
</Steps>

## Troubleshooting

<AccordionGroup>
  <Accordion title="Claude doesn't see my tools">
    1. Check that the path in `claude_desktop_config.json` is absolute
    2. Ensure the script runs without errors: `node /path/to/mcp-server.js`
    3. Restart Claude Desktop completely
  </Accordion>

  <Accordion title="Tool calls fail silently">
    Your backend might be throwing errors. Add logging to your terminal output and check there.
  </Accordion>
</AccordionGroup>
