DEV Community

BuyWhere
BuyWhere

Posted on

Zero to MCP: Build a Shopping Agent with BuyWhere

Zero to MCP: Build a Shopping Agent with BuyWhere

By the BuyWhere Team · May 2026 · 15 min read


What You'll Build

In this tutorial, you'll build a shopping agent powered by BuyWhere that can:

  • Search for products across thousands of merchants
  • Compare prices in real-time
  • Find the best deals with natural language queries
  • Surface purchase links instantly

All in under 50 lines of code.


1. What is MCP and Why It Matters

Model Context Protocol (MCP) is an open protocol developed by Anthropic that lets AI models connect directly with external tools, data sources, and APIs. Think of it as USB-C for AI — a universal, standardized way to plug capabilities into any LLM.

Before MCP: You'd build custom tool integrations for every model provider, maintain brittle function-calling code, and handle authentication/server management yourself.

With MCP: You spin up an MCP server, your AI client discovers its tools automatically, and everything just works — whether you're using Claude Desktop, Cursor, VS Code with Copilot, or a custom agent framework.

BuyWhere exposes a full MCP server so any AI agent can search, compare, and shop across our merchant network without you writing a single API integration.


2. Prerequisites

  • Node.js 18+ (or Bun 1.0+)
  • An API key from BuyWhere Developer Portal (free tier available)
  • Claude Desktop or any MCP-capable client (optional, for step 5)

3. Setting Up the BuyWhere MCP Server

There are two ways to get started — pick the one that fits your workflow.

Option A: Quick Start with npx

npx @buywhere/mcp-server --api-key YOUR_BUYWHERE_API_KEY
Enter fullscreen mode Exit fullscreen mode

That's it. The server starts on stdio and exposes BuyWhere's full tool set to any MCP client.

Option B: Install from npm

npm install @buywhere/mcp-server
Enter fullscreen mode Exit fullscreen mode

Then create a server.js:

import { BuyWhereMCPServer } from '@buywhere/mcp-server';

const server = new BuyWhereMCPServer({
  apiKey: process.env.BUYWHERE_API_KEY
});

server.start();
Enter fullscreen mode Exit fullscreen mode

Option C: One-Click with Smithery

If you're managing multiple MCP servers, add BuyWhere to your Smithery config:

{
  "mcpServers": {
    "buywhere": {
      "command": "npx",
      "args": ["@buywhere/mcp-server", "--api-key", "${BUYWHERE_API_KEY}"]
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

4. What Tools Does BuyWhere Expose?

Once the server is running, MCP clients automatically discover these tools:

Tool Description
search_products Search products by keyword, category, or merchant
compare_prices Compare prices across merchants for a specific product
get_deals Find active deals, discounts, and coupon-eligible items
get_product_details Fetch full product specs, reviews, and availability
find_nearby_stores Locate physical stores with in-stock inventory

Each tool returns structured data the AI can reason over — no parsing required.


5. Building Your Shopping Agent

Let's wire this into a working agent. We'll use the MCP client SDK to connect to BuyWhere.

Step 1: Set up the project

mkdir shopping-agent && cd shopping-agent
npm init -y
npm install @modelcontextprotocol/sdk @buywhere/mcp-server
Enter fullscreen mode Exit fullscreen mode

Step 2: Create the agent

Create agent.mjs:

import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';

// 1. Start the BuyWhere MCP server
const transport = new StdioClientTransport({
  command: 'npx',
  args: ['@buywhere/mcp-server', '--api-key', process.env.BUYWHERE_API_KEY]
});

const client = new Client({
  name: 'shopping-agent',
  version: '1.0.0'
});

await client.connect(transport);

// 2. Discover available tools
const tools = await client.listTools();
console.log('Available tools:', tools.map(t => t.name));

// 3. Search for products
const searchResult = await client.callTool({
  name: 'search_products',
  arguments: {
    query: 'wireless noise-cancelling headphones',
    limit: 5
  }
});

console.log('Search results:', searchResult.content);

// 4. Compare prices
const compareResult = await client.callTool({
  name: 'compare_prices',
  arguments: {
    product: 'Sony WH-1000XM5',
    merchants: ['amazon', 'bestbuy', 'walmart']
  }
});

console.log('Price comparison:', compareResult.content);

// 5. Find deals
const dealsResult = await client.callTool({
  name: 'get_deals',
  arguments: {
    category: 'electronics',
    maxDiscount: 30
  }
});

console.log('Best deals:', dealsResult.content);

await client.close();
Enter fullscreen mode Exit fullscreen mode

Step 3: Run it

export BUYWHERE_API_KEY="your-key-here"
node agent.mjs
Enter fullscreen mode Exit fullscreen mode

In under 50 lines, you have a fully functional shopping agent that searches, compares, and deals-hunts across thousands of merchants.


6. Bringing It to Life: A Conversational Shopping Assistant

The real magic happens when you connect BuyWhere to a conversational AI. Here's a full interactive shopping assistant:

import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
import readline from 'readline';

function ask(question) {
  const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
  return new Promise(resolve => rl.question(question, answer => { rl.close(); resolve(answer); }));
}

async function main() {
  const transport = new StdioClientTransport({
    command: 'npx',
    args: ['@buywhere/mcp-server', '--api-key', process.env.BUYWHERE_API_KEY]
  });

  const client = new Client({ name: 'shopping-assistant', version: '1.0.0' });
  await client.connect(transport);

  console.log('\n🛍️  BuyWhere Shopping Assistant ready!');
  console.log('Ask me anything about products, prices, or deals.\n');

  while (true) {
    const input = await ask('> ');
    if (input.toLowerCase() === 'exit') break;

    if (input.toLowerCase().includes('deal') || input.toLowerCase().includes('discount')) {
      const result = await client.callTool({
        name: 'get_deals',
        arguments: { query: input }
      });
      console.log(result.content);
    } else if (input.toLowerCase().includes('compare') || input.toLowerCase().includes('price')) {
      const result = await client.callTool({
        name: 'compare_prices',
        arguments: { query: input }
      });
      console.log(result.content);
    } else {
      const result = await client.callTool({
        name: 'search_products',
        arguments: { query: input }
      });
      console.log(result.content);
    }
  }

  await client.close();
}

main();
Enter fullscreen mode Exit fullscreen mode

Run it, type "find me noise-cancelling headphones under $200", and watch BuyWhere search across merchants and return real results.


7. Extending with Custom Tools

You can chain BuyWhere data into your own tools. For example, a price-drop alerter:

import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';

async function checkPriceDrop(product, targetPrice) {
  const transport = new StdioClientTransport({
    command: 'npx',
    args: ['@buywhere/mcp-server', '--api-key', process.env.BUYWHERE_API_KEY]
  });
  const client = new Client({ name: 'price-watcher', version: '1.0.0' });
  await client.connect(transport);

  const result = await client.callTool({
    name: 'compare_prices',
    arguments: { product }
  });

  const lowestPrice = result.content[0]?.text 
    ? parseFloat(result.content[0].text.match(/\$[\d.]+/)?.[0]?.slice(1) || '999')
    : 999;

  if (lowestPrice <= targetPrice) {
    console.log(`🔥 PRICE DROP: ${product} now $${lowestPrice} (target: $${targetPrice})`);
  }

  await client.close();
  return lowestPrice;
}

checkPriceDrop('Sony WH-1000XM5', 250);
Enter fullscreen mode Exit fullscreen mode

8. Deploying to Claude Desktop

Add BuyWhere to your claude_desktop_config.json:

{
  "mcpServers": {
    "buywhere": {
      "command": "npx",
      "args": ["@buywhere/mcp-server", "--api-key", "${BUYWHERE_API_KEY}"],
      "env": {
        "BUYWHERE_API_KEY": "your-key-here"
      }
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Now Claude can shop, compare, and find deals for you directly in conversation.


9. Next Steps


Why This Matters

MCP is rapidly becoming the standard for AI-tool integration. By exposing BuyWhere through MCP, we're making it possible for any AI agent — from Claude to Copilot to custom agents — to access real-time shopping data without custom integrations.

The developer who builds with MCP today is building the infrastructure of tomorrow's AI-powered commerce.


Ready to build? Grab your free API key at buywhere.ai/developers and start shipping.

More BuyWhere tutorials:

Top comments (0)