DEV Community

BuyWhere
BuyWhere

Posted on

How to Add Product Search to Your AI Agent with MCP — in 10 Lines

Why Product Search Is Hard for AI Agents

If you are building a shopping assistant, price comparison tool, or commerce agent, you know the problem: product data is scattered across dozens of merchants, each with their own API or no API at all.

This tutorial shows you how to add real product search to your AI agent using the Model Context Protocol (MCP) - no scraping, no API keys, no setup.

What You Will Build

An AI agent that can search for products across multiple stores, compare prices, and get structured product data - all in 10 lines of code.

Step 1: Install the MCP Server

npx -y @buywhere/mcp
Enter fullscreen mode Exit fullscreen mode

That is it. No keys. No signup. The server connects your agent to a structured product catalog.

Step 2: Configure Your Client

Add this to your MCP client config:

{"mcpServers":{"buywhere":{"command":"npx","args":["-y","@buywhere/mcp"]}}}
Enter fullscreen mode Exit fullscreen mode

Step 3: Ask Your Agent to Search

In Claude Desktop or any MCP client, you can now ask:

Find me the best price on Sony WH-1000XM5 headphones across stores

Your agent will use the search_products tool, get structured results, and compare prices automatically.

Python Integration

from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client

async def search(query: str):
    server = StdioServerParameters(command="npx", args=["-y", "@buywhere/mcp"])
    async with stdio_client(server) as (read, write):
        async with ClientSession(read, write) as session:
            await session.initialize()
            result = await session.call_tool("search_products", {"query": query})
            return result.content
Enter fullscreen mode Exit fullscreen mode

Why MCP Instead of Scraping

Web scraping breaks when merchants update HTML. You get rate-limited and blocked. It takes weeks to build and maintain. MCP with BuyWhere gives you a stable API in 10 lines with zero maintenance.

Try It Now

Install the server with npx @buywhere/mcp and ask your agent to find a product. We are running a Build With BuyWhere challenge with API credits for the best AI agent submissions - details at buywhere.ai.

More BuyWhere tutorials:


Star BuyWhere MCP on GitHub — the open-source product catalog API for AI agents.

Related reading:

Top comments (0)