This example demonstrates how to use Model Context Protocol to build a personalized shopping assistant that remembers user preferences and makes tailored product recommendations.
The E-commerce Shopping Assistant uses MCP to structure all the context needed for personalized product recommendations, including:
User Profile
Style preferences, size information, past purchases
Product Catalog Integration
Tools for searching products and checking inventory
Memory Management
Short-term conversation context and long-term preference tracking
// E-commerce Assistant MCP Context
import { MCPContext } from '@modl/mcp';
const shoppingAssistant = new MCPContext({
systemInstruction: "You are a helpful shopping assistant for a fashion retailer.",
userGoal: "Find stylish, waterproof sneakers under €150",
userProfile: {
name: "Alex",
style: ["minimalist", "neutral", "casual-elegant"],
shoeSize: "EU 42",
pastPurchases: ["Nike Air Max", "Common Projects", "Vans Old Skool"],
preferredPriceRange: "100-150 EUR"
},
tools: [
{
name: "searchProducts",
description: "Search the product catalog",
parameters: {
query: "string",
filters: "object",
limit: "number"
}
},
{
name: "getProductDetails",
description: "Get detailed information about a product",
parameters: {
productId: "string"
}
},
{
name: "checkInventory",
description: "Check if a product is in stock",
parameters: {
productId: "string",
size: "string"
}
}
],
memory: {
shortTerm: [],
longTerm: {
stylePreferences: "modern minimalist, neutral colors",
purchaseBehavior: "researches thoroughly before buying"
}
}
});
export default shoppingAssistant;Structured representation of user preferences, sizes, and purchase history.
userProfile: {
name: "Alex",
style: ["minimalist", "neutral"],
shoeSize: "EU 42",
pastPurchases: ["Nike Air Max", ...],
preferredPriceRange: "100-150 EUR"
}Defined tools for product search, details, and inventory checking.
tools: [
{
name: "searchProducts",
description: "Search the catalog",
parameters: {
query: "string",
filters: "object",
limit: "number"
}
},
// More tools...
]Once the MCP context is defined, it can be used with any LLM provider to create a personalized shopping experience:
import OpenAI from 'openai';
import shoppingAssistant from './shopping-assistant.js';
const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
});
async function getRecommendations(userQuery) {
// Update the user goal with the specific query
shoppingAssistant.updateContext({
userGoal: userQuery
});
// Compile the context for OpenAI
const context = shoppingAssistant.compileFor('openai');
// Use the context in your OpenAI call
const response = await openai.chat.completions.create({
model: 'gpt-4o',
messages: [
{
role: 'system',
content: context.systemMessage
},
{
role: 'user',
content: userQuery
}
],
tools: context.tools
});
// Update short-term memory with this interaction
shoppingAssistant.updateMemory({
shortTerm: [
...shoppingAssistant.memory.shortTerm,
{
type: "interaction",
query: userQuery,
response: response.choices[0].message.content
}
]
});
return response.choices[0].message.content;
}
// Example usage
getRecommendations("I need waterproof sneakers for city walking");Try out the E-commerce Shopping Assistant with this interactive demo. Ask for product recommendations or specific items.
Hello! I'm your personal shopping assistant. How can I help you today?
I'm looking for waterproof sneakers under €150 that would work for city walking.
Based on your style preferences and past purchases, I'd recommend the Vessi Cityscape (€135). They're fully waterproof, have a minimalist design, and come in neutral colors like Slate Grey.
Another good option would be the Allbirds Mizzle (€145). They're water-resistant, made with sustainable materials, and have a clean aesthetic similar to your previous purchases.
Would you like to see more details about either of these options?
This is a demo interface. The assistant is not actually functional.