How it works
A shopping assistant built on MCP
The assistant answers questions about a small apparel catalog. It doesn’t know the products itself: it looks them up by calling tools on a Model Context Protocol server, and the chat shows every call it makes. Everything runs on one Gemini API key.
Try itWhat happens when you ask something
1. You type or speak
Voice is recorded in the browser (up to 30 seconds) and sent to /api/transcribe, where Gemini’s audio understanding turns it into text. The transcript is sent like a typed message.
2. The agent plans
/api/chat runs an agent loop on the server. It connects to the MCP server, lists its tools, converts them to Gemini function declarations, and lets the model decide whether to call any (function calling mode AUTO).
3. Tools run on the MCP server
Each tool call goes to the backend over Streamable HTTP with the official MCP SDK. Structured results go back to the model, which can call more tools (search, then fetch details) for up to five rounds by default.
4. The answer streams back
Text, tool calls and tool results stream to the browser as NDJSON. The chips above each reply show which tool ran, with what arguments, and how many products it found. Replies can be read aloud with your browser’s speech synthesis.
The MCP server
The backend is a FastAPI app with an MCP server built on the official Python SDK, served over Streamable HTTP at /mcp. It runs stateless with JSON responses and a fresh session manager per request, so it works on serverless hosting. All tools are read-only and return typed, structured results.
list_products
none
Every product in the catalog.
search_products
colors, city, min_price, max_price, tags
Exact attribute filters, combined with AND.
semantic_product_search
query, top_k, plus the same filters
Ranks by meaning with Gemini embeddings. Falls back to keyword matching if embeddings are unavailable.
get_product
product_id
Full details for one item: specs, sizes, materials.
It also exposes the resource catalog://products (the full catalog as JSON) and the prompt shopping_assistant. The same logic is available as a REST API (/products, /products/search, /products/semantic-search) with Swagger docs at /docs.
Semantic search
Products are embedded with Gemini gemini-embedding-001 (768 dimensions) the first time someone searches, and kept in an in-memory index. Queries are ranked by cosine similarity after the filters are applied. Without an API key or quota, the server switches to keyword matching, and the tool chip shows “(keyword)”.
Connect your own client
Nothing about the server is tied to this site. Any MCP client that supports Streamable HTTP can use the same tools.
# Claude Code
claude mcp add --transport http product-catalog https://<your-backend>.vercel.app/mcp
# MCP Inspector (choose "Streamable HTTP")
npx @modelcontextprotocol/inspector
# Raw JSON-RPC
curl -s https://<your-backend>.vercel.app/mcp \
-H 'content-type: application/json' \
-H 'accept: application/json, text/event-stream' \
-d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'Tech stack
- Frontend
- Next.js 16, React 19, TypeScript, Tailwind CSS 4
- Agent
- Gemini via @google/genai, MCP TypeScript SDK
- Voice
- MediaRecorder, Gemini transcription, browser speechSynthesis
- Backend
- Python 3.13, FastAPI, MCP Python SDK
- Search
- gemini-embedding-001, in-memory cosine index
- Hosting
- Vercel (frontend and backend as separate projects)
Source and setup instructions are on GitHub.