#!/usr/bin/env python3.11
"""
๐ฟ ืื ืืช ืืกืืืืื ืืืืื ืฉื ืืืจืื ืืื
Complete Stevia Store MCP Server with full e-commerce functionality
"""
import asyncio
import argparse
import random
import uuid
from datetime import datetime, timedelta
from mcp.server.fastmcp import FastMCP
# Initialize the MCP server
mcp = FastMCP("๐ฟ ืื ืืช ืืกืืืืื ืฉื ืืืจืื ืืื")
# Expanded product catalog with detailed information
PRODUCTS = {
1: {
"name": "ืกืืืืื ืืืขืืช ืืืจืื ืืช 100 ืืจื",
"category": "ืืืจื ืืื",
"price": 45.90,
"cost": 25.00,
"description": "ืกืืืืื ืืืขืืช 100% ืืืจืื ืืช ืืื ืชืืกืคืืช ืืืืืืช. ืืืชืืง ืืืขื ืขื ืืื ืืืชืืง ืคื 300 ืืืกืืืจ ืืจืืื",
"ingredients": "ืขืื ืกืืืืื ืืืจืื ืืื ืืืืจืื 100%",
"benefits": ["ืืื ืงืืืจืืืช", "ืืงืจืช ืกืืืจ", "ืืืขื ืืืืืืื", "ืืชืืื ืืื ืืืืืืื"],
"usage": "ืืชืืื ืืืฉืงืืืช ืืืื ืืงืจืื, ืงืื ืืืื ืืืคืื. ืืคืืช ืงืื ื = ืืฃ ืกืืืจ",
"weight": "100 ืืจื",
"origin": "ืคืจืืืืื",
"kosher": True,
"organic": True,
"stock": 150,
"rating": 4.8,
"reviews": 89
},
2: {
"name": "ืกืืืืื ืืืืืืืช - 60 ืืืืืืช",
"category": "ืืืฆืจืื ืืืื ืื",
"price": 29.90,
"cost": 15.00,
"description": "ืืืืืืช ืกืืืืื ื ืืืืช ืืฉืืืืฉ ืืงืคื, ืชื ืืืฉืงืืืช. ืื ืืืืืื ืฉืืื ืืืคืืช ืกืืืจ",
"ingredients": "ืชืืฆืืช ืกืืืืื ืืจืืืืช, ืืืืจื ืขืืจ ืืืขืืื",
"benefits": ["ื ืื ืื ืฉืืื", "ืืื ืื ืืืืืง", "ืืื ืงืืืจืืืช", "ืื ืืืืง ืืฉืื ืืื"],
"usage": "ืืืืืื ืืืช ืืืฉืงื. ื ืืชื ืืืฆืืช ืืืฆื ืื ื",
"weight": "60 ืืืืืืช",
"origin": "ืืฉืจืื",
"kosher": True,
"organic": False,
"stock": 200,
"rating": 4.6,
"reviews": 156
},
3: {
"name": "ืกืืืืื ื ืืืืืช ืืืขื ืื ืืื - 50ml",
"category": "ืืืฆืจืื ืืืื ืื",
"price": 39.90,
"cost": 20.00,
"description": "ืชืืฆืืช ืกืืืืื ื ืืืืืช ืขื ืืขื ืื ืืื ืืืขื. ืืืฉืื ืืืฉืงืืืช ืืืงืื ืืืื",
"ingredients": "ืชืืฆืืช ืกืืืืื, ืชืืฆืืช ืื ืืื ืืืขืืช, ืืื ืืืืงืงืื",
"benefits": ["ืืขื ืขืืื", "ื ืคื ืงืื", "ืืืืื ืฉืืืืฉืื", "ืืจืื ืืืืืื"],
"usage": "3-5 ืืืคืืช ืืืฉืงื. ืืชืืื ืื ืืงืื ืืืื ืืขืืืืช",
"weight": "50ml",
"origin": "ืืฉืจืื",
"kosher": True,
"organic": False,
"stock": 100,
"rating": 4.7,
"reviews": 203
},
4: {
"name": "ืืืงืช ืกืืืืื ืืืคืื - 200 ืืจื",
"category": "ืืืฉืื ืืืคืื",
"price": 55.90,
"cost": 30.00,
"description": "ืืืงืช ืกืืืืื ืืืืืืช ืืืคืื ืืืืฉืื. ืขืืืื ืืืื ืืืชืืืื ืืื ืกืืื ืืืชืืื ืื",
"ingredients": "ืกืืืืื ืืขืืืืช ืืืืืื ืืืคืื, ืืืืฆื ืืืขื",
"benefits": ["ืขืืืื ืืืื", "ืื ืืฉื ื ืืขื", "ืืชืืืื ืืื ืืืชืืื ืื", "ืืืกืืช ืงืืืจืืืช"],
"usage": "ืืืก ืืืช ืฉื ืืืงื = ืืืก ืกืืืจ ืืืชืืื ืื. ืืชืืื ืืขืืืืช, ืืืกืงืืืืืื ืืขืื",
"weight": "200 ืืจื",
"origin": "ืืืืื",
"kosher": True,
"organic": True,
"stock": 80,
"rating": 4.9,
"reviews": 67
},
5: {
"name": "ืืืจื ืืขืืื - 4 ืกืืืื",
"category": "ืืืจืืื",
"price": 89.90,
"cost": 45.00,
"description": "ืืืจื ืืขืืื ืืืืื 4 ืกืืื ืกืืืืื ืฉืื ืื: ืืืงื, ืืืืืืช, ื ืืืื ืืืจืืืจืื ืงืื ืื",
"ingredients": "4 ืืืฆืจื ืกืืืืื ืฉืื ืื ืืืจืืืืช ืืื ื",
"benefits": ["ืืืืจื ืืช ืืืืืื", "ืืชื ื ืืืฉืืืช", "ืืกืืื ื", "ืืืืืืื ืืืชืืืืื"],
"usage": "ื ืกื ืื ืกืื ืืืฆืื ืืช ืืืชืืื ืืื",
"weight": "ืืืจื ืฉื 4 ืืืฆืจืื",
"origin": "ืืฉืจืื",
"kosher": True,
"organic": True,
"stock": 50,
"rating": 4.5,
"reviews": 134
},
6: {
"name": "ืกืืืืื ื ืืืืืช ืืขื ืฉืืงืืื - 50ml",
"category": "ืืืฆืจืื ืืืื ืื",
"price": 42.90,
"cost": 22.00,
"description": "ืชืืฆืืช ืกืืืืื ื ืืืืืช ืขื ืืขื ืฉืืงืืื ืืืื. ืืืฉืื ืืงืคื, ืืื ืืขืืืืช",
"ingredients": "ืชืืฆืืช ืกืืืืื, ืชืืฆืืช ืฉืืงืืื ืืืขืืช, ืืื ืืืืงืงืื",
"benefits": ["ืืขื ืฉืืงืืื ืขืฉืืจ", "ืืื ืกืืืจ", "ืืชืืื ืืืืืื", "ืืืื ืขื ืืืืื"],
"usage": "3-5 ืืืคืืช ืืืฉืงื. ืืขืืื ืืงืคื ืืืืื ืื",
"weight": "50ml",
"origin": "ืืฉืจืื",
"kosher": True,
"organic": False,
"stock": 75,
"rating": 4.4,
"reviews": 98
},
7: {
"name": "ืกืืืืื ืืจืืืจืื - 300 ืืจื",
"category": "ืืืจื ืืื",
"price": 65.90,
"cost": 35.00,
"description": "ืืจืืืจื ืกืืืืื ืืืขืืื ืืืจืงื ืืืื ืืกืืืจ ืืื. ื ืื ืืืืืื ืืืฉืืืืฉ ืืืืืืื",
"ingredients": "ืืจืืืจื ืกืืืืื ืืขืืืืื, ืืื ืชืืกืคืืช",
"benefits": ["ืืจืงื ื ืขืื", "ืงื ืืืืืื", "ืืขื ื ืงื", "ืืชืืื ืืื ืืฉืืืืฉืื"],
"usage": "ืืคืืช = ืืฃ ืกืืืจ. ืืชืืื ืืืฉืงืืืช, ืืื ืื ืืืคืื",
"weight": "300 ืืจื",
"origin": "ืืจืืื",
"kosher": True,
"organic": True,
"stock": 120,
"rating": 4.6,
"reviews": 78
},
8: {
"name": "ืกืืืืื ืืืจืื ืืช ืคืจืืืืื - 50 ืืจื",
"category": "ืคืจืืืืื",
"price": 75.90,
"cost": 40.00,
"description": "ืกืืืืื ืืืจืื ืืช ืืืืืช ืคืจืืืืื ืืืืืจ ืืืืืื ืืืื ืืขืืื. ืขืืืจ 3 ืืืืงืืช ืืืืืช",
"ingredients": "ืขืื ืกืืืืื ืืืจืื ืืื ืคืจืืืืื ืืืื",
"benefits": ["ืืืืืช ืืืืื ืืืืชืจ", "ืืขื ืืืฉืื", "ืืืจืื ื ืืืกืื", "ืืืื ืืฉืืจ"],
"usage": "ืืชืืื ืืฉืืืืฉืื ืืืืืืื ืืืืืืื ืืืืืช ืืืืื",
"weight": "50 ืืจื",
"origin": "ืคืจืืืืื - ืืืืจ ืคืจืืืืื",
"kosher": True,
"organic": True,
"stock": 60,
"rating": 5.0,
"reviews": 34
}
}
# Shopping cart and orders (in memory for demo)
shopping_cart = {}
orders = {}
next_order_id = 1001
# FAQ Database
FAQ_DATABASE = {
"ืกืืืืื": {
"ืื ืื ืกืืืืื?": "ืกืืืืื ืืื ืฆืื ืืืขื ืืืฉืคืืช ืืืจืฆืืช ืืืืื ืืืจืื ืืืจืืงื. ืืขืืื ืฉืื ืืืืืื ืืืืจืื ืืืชืืงืื ืืืขืืื ืฉืื ืืชืืงืื ืคื 200-300 ืืืกืืืจ ืื ืืื ืงืืืจืืืช.",
"ืืื ืกืืืืื ืืืืื?": "ืื! ืกืืืืื ืืืืจืช ืืืืืื ืขื ืืื ื-FDA, ืืจืฉืืช ืืืืจืืคืืช ืืืืื ืืืฉืจื ืืืจืืืืช ืืืฉืจืื. ืืื ืืฉืืฉืช ืืืืช ืฉื ืื ืืืจืื ืืืจืืงื.",
"ืืื ืกืืืืื ืืฉืคืืขื ืขื ืจืืช ืืกืืืจ?": "ืกืืืืื ืื ืืขืื ืืช ืจืืช ืืกืืืจ ืืื ืืืฃ ืขืฉืืื ืืขืืืจ ืืืืืกืืช ืจืืืช ืืกืืืจ. ืืชืืืื ืืืืื ืกืืืจืช.",
"ืืื ืืฉ ืืกืืืืื ืืขื ืืืืื?": "ืกืืืืื ืืืืืชืืช ืืื ืฉืื ื ืืืขื ืืื ืืฉืืืจื ืืขื ืืืืื. ืืฉืื ืืงื ืืช ืืืฆืจืื ืืืืืชืืื ืืืืฉืชืืฉ ืืืื ืื ืื ื ืืื ืื."
},
"ืฉืืืืฉ": {
"ืืื ืืฉืชืืฉืื ืืกืืืืื?": "ืชืืื ืืกืื: ืืืงื - ืืคืืช ืงืื ื ืืืงืื ืืฃ ืกืืืจ, ืืืืืืช - ืืืช ืืืฉืงื, ื ืืืื - 3-5 ืืืคืืช ืืืฉืงื. ืืชืืืื ืืืขื ืืืืกืืคื ืืคื ืืืขื.",
"ืืื ืืคืฉืจ ืืืคืืช ืขื ืกืืืืื?": "ืืืืื! ืืฉืชืืฉื ืืืืงืช ืืกืืืืื ืืืืืืืช ืืืคืื ืฉืื ื. ืืื ืขืืืื ืืืื ืืืชืืืื ืืื ืกืืื ืืืชืืื ืื.",
"ืืื ืืืืืคืื ืกืืืจ ืืกืืืืื?": "ืืืจื ืืื: ืืืก ืกืืืจ = ืืฃ ืฉื ืืืงืช ืกืืืืื. ืืืฉืงืืืช: ืืฃ ืกืืืจ = ืืคืืช ืกืืืืื. ืืืืจื ืฉืื ื ืืืื ืืืจืื ืืืจืืช ืืคืืจื.",
"ืืื ืืคืฉืจ ืืชืช ืืืืืื?": "ืื! ืกืืืืื ืืืืื ืืืืืื ืืืขืฆื ืขืืืคื ืขื ืกืืืจ ืืืืื ื ืืจืืืืชืืช. ืืื ืื ืืืจืืช ืืขืฉืฉืช ืืื ืืฉืคืืขื ืขื ืืืชื ืืืืช."
},
"ืืืื ืืช": {
"ืืื ืืื ืืืงื ืืืฉืืื?": "ืืืฉืืื ืืืงื 2-5 ืืื ืขืกืงืื ืืื ืืืจืฅ. ืืืืจ ืืืจืื - ืขื 2 ืืืื, ืืฆืคืื ืืืืจืื - ืขื 5 ืืืื.",
"ืื ืขืืื ืืืฉืืื?": "ืืืฉืืื ืขืืื 25 ืฉ\"ื, ืืื ืื ืืื ื ืขื ืืืื ืืช ืืขื 150 ืฉ\"ื!",
"ืืื ืืคืฉืจ ืืฉืื?": "ืื ืื ื ืืงืืืื ืืจืืืกื ืืฉืจืื (ืืืื, ืืืกืืจืงืืจื), ืืื, ืคืืืืืงืก ืืืขืืจื ืื ืงืืืช.",
"ืืื ืืคืฉืจ ืืืืืืจ ืืืฆืจืื?": "ืื! ืืืืจื ืชืื 14 ืืืื ืืื ืฉืืืืช. ืืืืฆืจ ืฆืจืื ืืืืืช ืืืจืืื ืืงืืจืืช."
},
"ืืืืืช": {
"ืืืืคื ืืกืืืืื ืฉืืื?": "ืื ืื ื ืืืืืืื ืืฉืืจืืช ืืืืงืืืื ืืืืืื ืืืืชืจ ืืคืจืืืืื ืืืจืืื - ืืืงื ืืืืืื ืืืืขื ืฉื ืืกืืืืื.",
"ืืื ืืืืฆืจืื ืืืจืื ืืื?": "ืืืง ืืืืืฆืจืื ืฉืื ื ืืืจืื ืืื ืืืกืืืื. ืชืืืื ืืจืืืช ืืคืจืื ืื ืืืฆืจ ืื ืืื ืืืจืื ื.",
"ืืื ืืชื ืฉืืืจืื ืขื ืืืืืืช?": "ืื ืืฉืืื ืขืืืจ 3 ืืืืงืืช ืืืืืช: ืืืงืืจ, ืืืืขื ืืืฉืจืื ืืืคื ื ืืฉืืืืง. ืื ืื ื ืขืืืืื ืจืง ืขื ืกืคืงืื ืืืกืืืื.",
"ืื ืชืืงืฃ ืืืืฆืจืื?": "ืื ืืืืฆืจืื ืฉืื ื ืืขืื ืชืืงืฃ ืฉื 2-3 ืฉื ืื ืืืื ืืืืฆืืจ. ืื ืื ื ืืงืคืืืื ืขื ืืืื ืืจื."
}
}
# Promotions and discounts
PROMOTIONS = {
"first_time": {
"name": "ืืจืืืื ืืืืื!",
"description": "ืื ืื 10% ืืืงืืืืช ืืืฉืื",
"discount_percent": 10,
"code": "WELCOME10",
"min_amount": 50
},
"bulk_discount": {
"name": "ืงื ืืื ืืืืืช",
"description": "ืื ืื 15% ืขื ืืืื ืืช ืืขื 300 ืฉ\"ื",
"discount_percent": 15,
"min_amount": 300
},
"free_shipping": {
"name": "ืืฉืืื ืืื ื",
"description": "ืืฉืืื ืืื ื ืขื ืืืื ืืช ืืขื 150 ืฉ\"ื",
"free_shipping": True,
"min_amount": 150
}
}
@mcp.tool()
def browse_products(category: str = "") -> str:
"""
๐๏ธ ืขืืื ืืงืืืื ืืืฆืจื ืืกืืืืื ืืืื ืฉื ืืืจืื ืืื
Args:
category: ืกืื ืื ืืคื ืงืืืืจืื - "ืืืจื ืืื", "ืืืฆืจืื ืืืื ืื", "ืืืฉืื ืืืคืื", "ืืืจืืื", "ืคืจืืืืื"
Returns:
ืจืฉืืืช ืืืืฆืจืื ืืืืื ืื ืขื ืคืจืืื ืืืืื
"""
result = "๐ฟ **ืืจืืืื ืืืืื ืืื ืืช ืืกืืืืื ืฉื ืืืจืื ืืื!**\n\n"
if category:
result += f"๐ **ืงืืืืจืื: {category}**\n\n"
filtered_products = {k: v for k, v in PRODUCTS.items() if v["category"] == category}
else:
result += "๐ **ืื ืืืืฆืจืื ืฉืื ื:**\n\n"
filtered_products = PRODUCTS
if not filtered_products:
return f"๐ฆ ืื ื ืืฆืื ืืืฆืจืื ืืงืืืืจืื '{category}'"
current_category = ""
for product_id, product in filtered_products.items():
if product["category"] != current_category:
current_category = product["category"]
result += f"\n๐ท๏ธ **{current_category}:**\n{'='*50}\n"
# Stock indicator
if product["stock"] > 20:
stock_indicator = "โ
ืืืืื ืจื"
elif product["stock"] > 5:
stock_indicator = f"๐ก ื ืืชืจื {product['stock']} ืืืืืืช"
else:
stock_indicator = f"๐ด ื ืืชืจื ืจืง {product['stock']} ืืืืืืช!"
# Product details
result += f"**#{product_id} - {product['name']}**\n"
result += f"๐ฐ **ืืืืจ: โช{product['price']:.2f}** | {stock_indicator}\n"
result += f"๐ ืืฉืงื: {product['weight']} | ๐ ืืงืืจ: {product['origin']}\n"
# Certifications
certifications = []
if product['kosher']:
certifications.append("โก๏ธ ืืฉืจ")
if product['organic']:
certifications.append("๐ฑ ืืืจืื ื")
if certifications:
result += f"๐ {' | '.join(certifications)}\n"
# Rating
stars = "โญ" * int(product['rating'])
result += f"โญ {product['rating']}/5 ({product['reviews']} ืืืงืืจืืช) {stars}\n"
result += f"๐ {product['description']}\n"
result += f"๐ *ืืืืกืคื ืืขืืื: add_to_cart ืขื ID #{product_id}*\n"
result += f"๐ *ืืคืจืืื ืืืืื: get_product_details ืขื ID #{product_id}*\n\n"
result += "\n" + "="*60 + "\n"
result += "๐ **ืืฆืขืืช ืืืืืืืช:**\n"
result += "โข ๐ ืืฉืืื ืืื ื ืืขื โช150\n"
result += "โข ๐ ืื ืื 10% ืืืงืืืืช ืืืฉืื (ืงืื: WELCOME10)\n"
result += "โข ๐ ืืืขืืฅ ืืื ื: 03-1234567\n"
result += "โข ๐ ืืืืจื ืชืื 14 ืืืื"
return result
@mcp.tool()
def get_product_details(product_id: int) -> str:
"""
๐ ืฆืคืืื ืืคืจืื ืืืฆืจ ืืืืื ืืืคืืจืืื
Args:
product_id: ืืืื ืืืืฆืจ (1-8)
Returns:
ืคืจืืื ืืืืื ืขื ืืืืฆืจ ืืืื ืจืืืืื, ืืชืจืื ืืช ืืืืคื ืฉืืืืฉ
"""
if product_id not in PRODUCTS:
return f"โ ืื ื ืืฆื ืืืฆืจ ืขื ืืืื #{product_id}\n\n๐ก ืืืืฆืจืื ืืืืื ืื: 1-8"
product = PRODUCTS[product_id]
result = f"๐ฟ **ืคืจืื ืืืฆืจ ืืืืื - #{product_id}**\n\n"
result += f"**{product['name']}**\n"
result += f"๐ท๏ธ ืงืืืืจืื: {product['category']}\n"
result += f"๐ฐ **ืืืืจ: โช{product['price']:.2f}**\n"
result += f"๐ ืืฉืงื/ืืืื: {product['weight']}\n"
result += f"๐ ืืงืืจ: {product['origin']}\n\n"
# Stock status
if product["stock"] > 20:
result += "โ
**ืืืืื ืจื - ืืืื ืืืฉืืื ืืืืื**\n\n"
elif product["stock"] > 5:
result += f"๐ก **ื ืืชืจื {product['stock']} ืืืืืืช - ืืืืื ื ืขืืฉืื!**\n\n"
else:
result += f"๐ด **ื ืืชืจื ืจืง {product['stock']} ืืืืืืช! ืืืื ืืืจืื**\n\n"
# Certifications
certifications = []
if product['kosher']:
certifications.append("โก๏ธ ืืฉืจ")
if product['organic']:
certifications.append("๐ฑ ืืืจืื ื ืืืกืื")
if certifications:
result += f"๐ **ืืืฉืืจืื:** {' | '.join(certifications)}\n\n"
# Rating and reviews
stars = "โญ" * int(product['rating'])
result += f"โญ **ืืืจืื: {product['rating']}/5** ({product['reviews']} ืืืงืืจืืช) {stars}\n\n"
# Description
result += f"๐ **ืชืืืืจ ืืืืฆืจ:**\n{product['description']}\n\n"
# Ingredients
result += f"๐งช **ืจืืืืื:**\n{product['ingredients']}\n\n"
# Benefits
result += f"โจ **ืืชืจืื ืืช ืืืืฆืจ:**\n"
for benefit in product['benefits']:
result += f"โข {benefit}\n"
result += "\n"
# Usage instructions
result += f"๐ **ืืืจืืืช ืฉืืืืฉ:**\n{product['usage']}\n\n"
# Profit margin for internal use
profit_margin = ((product['price'] - product['cost']) / product['price'] * 100)
# Add to cart section
result += "๐ **ืืืืกืคื ืืขืืื:**\n"
result += f"ืืฉืชืืฉ ืืคืงืืื: `add_to_cart` ืขื ืืืฆืจ #{product_id}\n\n"
# Special offers
result += "๐ **ืืฆืขืืช ืืืืืืืช:**\n"
result += "โข ืืฉืืื ืืื ื ืืขื โช150\n"
result += "โข ืื ืื 10% ืืืงืืืืช ืืืฉืื (ืงืื: WELCOME10)\n"
result += "โข ืืืขืืฅ ืชืืื ื ืืื ื\n"
result += "โข ืืืืจื ืชืื 14 ืืืื\n\n"
# Related products suggestion
related_products = [pid for pid, p in PRODUCTS.items()
if p['category'] == product['category'] and pid != product_id]
if related_products:
result += "๐ **ืืืฆืจืื ืืืืื:**\n"
for pid in related_products[:2]:
result += f"โข #{pid} - {PRODUCTS[pid]['name']} (โช{PRODUCTS[pid]['price']:.2f})\n"
return result
@mcp.tool()
def search_products(query: str) -> str:
"""
๐ ืืืคืืฉ ืืืฆืจืื ืืชืงืื ืืื ืืช ืืกืืืืื
Args:
query: ืืืืช ืืืคืืฉ - ืฉื ืืืฆืจ, ืงืืืืจืื, ืจืืื ืื ืืชืจืื
Returns:
ืชืืฆืืืช ืืืคืืฉ ืืชืงืืืืช ืขื ืฆืืื ืื
"""
if not query:
return "๐ ืื ื ืืื ืก ืืืืช ืืืคืืฉ\n\n๐ก ืืืืืืืช ืืืืคืืฉ: 'ืืืงื', 'ื ืืืื', 'ืืืจืื ื', 'ืืคืื'"
results = []
query_lower = query.lower()
for product_id, product in PRODUCTS.items():
score = 0
# Search in name (highest priority)
if query_lower in product["name"].lower():
score += 10
# Search in description
if query_lower in product["description"].lower():
score += 5
# Search in category
if query_lower in product["category"].lower():
score += 7
# Search in ingredients
if query_lower in product["ingredients"].lower():
score += 3
# Search in benefits
for benefit in product["benefits"]:
if query_lower in benefit.lower():
score += 4
# Search in usage
if query_lower in product["usage"].lower():
score += 2
if score > 0:
results.append((product_id, product, score))
if not results:
return f"๐ ืื ื ืืฆืื ืืืฆืจืื ืขืืืจ ืืืืคืืฉ: '{query}'\n\n๐ก ื ืกื ืืืืื ืืื: 'ืืืงื', 'ื ืืืื', 'ืืืืืืช', 'ืืืจืื ื', 'ืืคืื'"
# Sort by relevance score
results.sort(key=lambda x: x[2], reverse=True)
result = f"๐ **ืชืืฆืืืช ืืืคืืฉ ืขืืืจ: '{query}'**\n"
result += f"ื ืืฆืื {len(results)} ืืืฆืจืื (ืืกืืืจืื ืืคื ืจืืืื ืืืืช):\n\n"
for product_id, product, score in results:
# Stock indicator
if product["stock"] > 20:
stock_indicator = "โ
ืืืืื"
elif product["stock"] > 5:
stock_indicator = f"๐ก ื ืืชืจื {product['stock']}"
else:
stock_indicator = f"๐ด ื ืืชืจื {product['stock']}!"
# Relevance indicator
if score >= 10:
relevance = "๐ฏ ืืชืืื ืืืฉืืืช"
elif score >= 7:
relevance = "โ
ืืชืืื ืืืืื"
elif score >= 4:
relevance = "๐ก ืืชืืื ืืืงืืช"
else:
relevance = "๐ ื ืืฆื"
result += f"**#{product_id} - {product['name']}** {relevance}\n"
result += f"๐ฐ โช{product['price']:.2f} | ๐ {product['weight']} | {stock_indicator}\n"
result += f"๐ท๏ธ {product['category']}"
# Show certifications
if product['organic']:
result += " | ๐ฑ ืืืจืื ื"
if product['kosher']:
result += " | โก๏ธ ืืฉืจ"
result += "\n"
result += f"๐ {product['description'][:120]}...\n"
result += f"๐ *ืืืืกืคื: add_to_cart ืขื ID #{product_id}*\n"
result += f"๐ *ืืคืจืืื: get_product_details ืขื ID #{product_id}*\n\n"
return result
@mcp.tool()
def add_to_cart(product_id: int, quantity: int = 1) -> str:
"""
๐ ืืืกืคืช ืืืฆืจ ืืขืืืช ืืงื ืืืช ืขื ืืืฉืื ืื ืืืช
Args:
product_id: ืืืื ืืืืฆืจ (1-8)
quantity: ืืืืช (ืืจืืจืช ืืืื: 1)
Returns:
ืืืฉืืจ ืืืกืคื ืืืฆื ืืขืืื ืขื ืื ืืืช ืืืื ืืช
"""
if product_id not in PRODUCTS:
return f"โ ืื ื ืืฆื ืืืฆืจ ืขื ืืืื #{product_id}\n\n๐ก ืืืืฆืจืื ืืืืื ืื: 1-8"
if quantity <= 0:
return "โ ืืืืช ืืืืืช ืืืืืช ืืืืืืช"
product = PRODUCTS[product_id]
if quantity > product["stock"]:
return f"โ ๏ธ ืืืืื ืจืง {product['stock']} ืืืืืืช ืืืืืฆืจ '{product['name']}'"
# Add to cart
if product_id in shopping_cart:
total_quantity = shopping_cart[product_id]["quantity"] + quantity
if total_quantity > product["stock"]:
return f"โ ๏ธ ืื ื ืืชื ืืืืกืืฃ {quantity} ืืืืืืช ื ืืกืคืืช. ืืืืื {product['stock']} ืืืืืืช ืืืขืืื ืืืจ {shopping_cart[product_id]['quantity']}"
shopping_cart[product_id]["quantity"] = total_quantity
shopping_cart[product_id]["total_price"] = total_quantity * product["price"]
else:
shopping_cart[product_id] = {
"name": product["name"],
"price": product["price"],
"quantity": quantity,
"total_price": quantity * product["price"],
"category": product["category"]
}
# Calculate cart totals
subtotal = sum(item["total_price"] for item in shopping_cart.values())
total_items = sum(item["quantity"] for item in shopping_cart.values())
# Apply discounts
discounts = []
discount_amount = 0
# Bulk discount
if subtotal >= PROMOTIONS["bulk_discount"]["min_amount"]:
bulk_discount = subtotal * (PROMOTIONS["bulk_discount"]["discount_percent"] / 100)
discounts.append(f"๐ ืื ืืช ืืืืช ({PROMOTIONS['bulk_discount']['discount_percent']}%): -โช{bulk_discount:.2f}")
discount_amount += bulk_discount
# Calculate shipping
shipping_cost = 0 if subtotal >= PROMOTIONS["free_shipping"]["min_amount"] else 25
final_total = subtotal - discount_amount + shipping_cost
result = f"โ
**ืืืืฆืจ ื ืืกืฃ ืืขืืื!**\n\n"
result += f"๐ **{product['name']}**\n"
result += f"๐ฆ ืืืืช: {quantity} ืืืืืืช\n"
result += f"๐ฐ ืืืืจ ืืืืืื: โช{product['price']:.2f}\n"
result += f"๐ต ืกื\"ื ืคืจืื: โช{(quantity * product['price']):.2f}\n\n"
result += "๐๏ธ **ืกืืืื ืืขืืื:**\n"
result += f"๐ ืกื\"ื ืคืจืืืื: {total_items}\n"
result += f"๐ต ืกื\"ื ืืืฆืจืื: โช{subtotal:.2f}\n"
# Show discounts
if discounts:
result += "\n๐ **ืื ืืืช ืฉืืืคืขืื:**\n"
for discount in discounts:
result += f"โข {discount}\n"
result += f"๐ฐ **ืืืจื ืื ืืืช: โช{(subtotal - discount_amount):.2f}**\n"
# Shipping info
if shipping_cost > 0:
result += f"\n๐ ืืื ืืฉืืื: โช{shipping_cost:.2f}\n"
result += f"๐ก ืืืกืฃ โช{(PROMOTIONS['free_shipping']['min_amount'] - subtotal):.2f} ืืืฉืืื ืืื ื!\n"
else:
result += "\n๐ ืืฉืืื ืืื ื!\n"
result += f"\n๐ณ **ืกื\"ื ืืชืฉืืื: โช{final_total:.2f}**\n\n"
# Promotion suggestions
if subtotal < PROMOTIONS["first_time"]["min_amount"]:
result += f"๐ ืืืค: ืืืกืฃ โช{(PROMOTIONS['first_time']['min_amount'] - subtotal):.2f} ืืงืื ืื ืื 10% ืขื ืงืื WELCOME10\n"
result += "โก **ืคืขืืืืช ืืืื ืืช:**\n"
result += "โข `view_cart` - ืฆืคืืื ืืขืืื ืืืื\n"
result += "โข `update_cart_item` - ืขืืืื ืืืืืืช\n"
result += "โข `remove_from_cart` - ืืกืจืช ืคืจืื\n"
result += "โข `apply_discount_code` - ืืคืขืืช ืงืื ืื ืื\n"
result += "โข `checkout` - ืืืฉื ืืชืฉืืื"
return result
@mcp.tool()
def view_cart() -> str:
"""
๐ ืฆืคืืื ืืคืืจืืช ืืขืืืช ืืงื ืืืช
Returns:
ืชืืื ืืขืืื ืขื ืคืืจืื ืืืืจืื, ืื ืืืช ืืขืืืืช
"""
if not shopping_cart:
return """๐ ืืขืืื ืฉืื ืจืืงื
๐๏ธ **ืืืชืืืช ืงื ืืื:**
โข `browse_products` - ืขืืื ืืื ืืืืฆืจืื
โข `search_products` - ืืืคืืฉ ืืืฆืจ ืกืคืฆืืคื
โข `get_store_info` - ืืืืข ืขื ืืื ืืช
๐ **ืืฆืขืืช ืืืืืืืช:**
โข ืื ืื 10% ืืืงืืืืช ืืืฉืื (ืงืื: WELCOME10)
โข ืืฉืืื ืืื ื ืืขื โช150"""
result = "๐ **ืขืืืช ืืงื ืืืช ืฉืื:**\n\n"
subtotal = 0
total_items = 0
# List all items
for product_id, item in shopping_cart.items():
result += f"**{item['name']}**\n"
result += f"๐ฐ โช{item['price']:.2f} ร {item['quantity']} = โช{item['total_price']:.2f}\n"
result += f"๐ท๏ธ ืงืืืืจืื: {item['category']} | ืืง\"ื: #{product_id}\n"
result += f"โ๏ธ *ืขืืืื: update_cart_item {product_id} [ืืืืช]* | ๐๏ธ *ืืกืจื: remove_from_cart {product_id}*\n\n"
total_items += item['quantity']
subtotal += item['total_price']
# Calculate discounts
discounts = []
discount_amount = 0
# Bulk discount
if subtotal >= PROMOTIONS["bulk_discount"]["min_amount"]:
bulk_discount = subtotal * (PROMOTIONS["bulk_discount"]["discount_percent"] / 100)
discounts.append(("๐ ืื ืืช ืืืืช (15%)", bulk_discount))
discount_amount += bulk_discount
# Calculate shipping
shipping_cost = 0 if subtotal >= PROMOTIONS["free_shipping"]["min_amount"] else 25
final_total = subtotal - discount_amount + shipping_cost
result += "=" * 50 + "\n"
result += f"๐ **ืกืืืื ืืืื ื:**\n"
result += f"๐ฆ ืกื\"ื ืคืจืืืื: {total_items}\n"
result += f"๐ต ืกื\"ื ืืืฆืจืื: โช{subtotal:.2f}\n"
# Show applied discounts
if discounts:
result += "\n๐ **ืื ืืืช ืืืคืขืืืช:**\n"
for discount_name, discount_value in discounts:
result += f"โข {discount_name}: -โช{discount_value:.2f}\n"
result += f"๐ฐ **ืืืจื ืื ืืืช: โช{(subtotal - discount_amount):.2f}**\n"
# Shipping calculation
if shipping_cost > 0:
result += f"\n๐ ืืื ืืฉืืื: โช{shipping_cost:.2f}\n"
needed_for_free_shipping = PROMOTIONS["free_shipping"]["min_amount"] - subtotal
if needed_for_free_shipping > 0:
result += f"๐ก ืืืกืฃ โช{needed_for_free_shipping:.2f} ืืืฉืืื ืืื ื!\n"
else:
result += "\n๐ ืืฉืืื ืืื ื! (ืืืื ื ืืขื โช150)\n"
result += f"\n๐ณ **ืกื\"ื ืืชืฉืืื: โช{final_total:.2f}**\n\n"
# Available promotions
result += "๐ **ืื ืืืช ืืืื ืืช:**\n"
if subtotal >= PROMOTIONS["first_time"]["min_amount"]:
result += "โข `apply_discount_code WELCOME10` - ืื ืื 10% ืืืงืืืืช ืืืฉืื\n"
else:
needed = PROMOTIONS["first_time"]["min_amount"] - subtotal
result += f"โข ืืืกืฃ โช{needed:.2f} ืืืฉืชืืฉ ืืงืื WELCOME10 ืืื ืื 10%\n"
result += "\nโก **ืคืขืืืืช ืืืื ืืช:**\n"
result += "โข `checkout` - ืืืฉื ืืชืฉืืื ๐ณ\n"
result += "โข `apply_discount_code [ืงืื]` - ืืคืขืืช ืงืื ืื ืื ๐ซ\n"
result += "โข `clear_cart` - ืจืืงืื ืืขืืื ๐งน\n"
result += "โข `browse_products` - ืืืฉื ืงื ืืื ๐๏ธ"
return result
@mcp.tool()
def update_cart_item(product_id: int, new_quantity: int) -> str:
"""
โ๏ธ ืขืืืื ืืืืช ืืืฆืจ ืืขืืื
Args:
product_id: ืืืื ืืืืฆืจ
new_quantity: ืืืืช ืืืฉื (0 ืืืืืงื)
Returns:
ืืืฉืืจ ืขืืืื ืขื ืกืืืื ืืืฉ
"""
if product_id not in shopping_cart:
return f"โ ืืืืฆืจ #{product_id} ืื ื ืืฆื ืืขืืื\n\n๐ ืืฆืคืืื ืืขืืื: `view_cart`"
if new_quantity < 0:
return "โ ืืืืช ืืืืืช ืืืืืช 0 ืื ืืืืืืช"
item_name = shopping_cart[product_id]['name']
old_quantity = shopping_cart[product_id]['quantity']
if new_quantity == 0:
del shopping_cart[product_id]
return f"๐๏ธ ืืืืฆืจ '{item_name}' ืืืกืจ ืืืขืืื\n\n๐ ืืฆืคืืื ืืขืืื ืืืขืืืื ืช: `view_cart`"
# Check stock availability
if product_id in PRODUCTS and new_quantity > PRODUCTS[product_id]["stock"]:
return f"โ ๏ธ ืืืืื ืจืง {PRODUCTS[product_id]['stock']} ืืืืืืช ืืืืืฆืจ '{item_name}'"
# Update quantity
shopping_cart[product_id]['quantity'] = new_quantity
shopping_cart[product_id]['total_price'] = new_quantity * shopping_cart[product_id]['price']
result = f"โ
**ืืืืช ืขืืืื ื ืืืฆืืื!**\n\n"
result += f"๐ฆ {item_name}\n"
result += f"๐ {old_quantity} โ {new_quantity} ืืืืืืช\n"
result += f"๐ฐ ืืืืจ ืืขืืืื: โช{shopping_cart[product_id]['total_price']:.2f}\n\n"
# Show updated cart summary
subtotal = sum(item["total_price"] for item in shopping_cart.values())
total_items = sum(item["quantity"] for item in shopping_cart.values())
shipping_cost = 0 if subtotal >= 150 else 25
result += f"๐๏ธ **ืกืืืื ืขืืื ืืขืืืื:**\n"
result += f"๐ ืกื\"ื ืคืจืืืื: {total_items}\n"
result += f"๐ต ืกื\"ื: โช{subtotal:.2f}\n"
result += f"๐ ืืฉืืื: {'ืืื ื' if shipping_cost == 0 else f'โช{shipping_cost:.2f}'}\n"
result += f"๐ณ **ืกื\"ื ืืชืฉืืื: โช{(subtotal + shipping_cost):.2f}**\n\n"
result += "๐ ืืฆืคืืื ืืืื: `view_cart`"
return result
@mcp.tool()
def remove_from_cart(product_id: int) -> str:
"""
๐๏ธ ืืกืจืช ืืืฆืจ ืืืขืืื
Args:
product_id: ืืืื ืืืืฆืจ ืืืกืจื
Returns:
ืืืฉืืจ ืืกืจื
"""
return update_cart_item(product_id, 0)
@mcp.tool()
def clear_cart() -> str:
"""
๐งน ืจืืงืื ืืขืืื ืืืืืืื
Returns:
ืืืฉืืจ ืจืืงืื ืขื ืืฆืขืืช ืืืืจื ืืงื ืืื
"""
if not shopping_cart:
return "๐ ืืขืืื ืืืจ ืจืืงื\n\n๐๏ธ ืืืืจื ืืงื ืืื: `browse_products`"
items_count = len(shopping_cart)
shopping_cart.clear()
return f"""๐งน **ืืขืืื ืจืืงื ื ืืืฆืืื!**
๐ ืืืกืจื {items_count} ืคืจืืืื ืืืขืืื
๐๏ธ **ืืืืฉื ืงื ืืื:**
โข `browse_products` - ืขืืื ืืื ืืืืฆืจืื
โข `search_products [ืืืื]` - ืืืคืืฉ ืืืฆืจ ืกืคืฆืืคื
๐ **ืืฆืขืืช ืืืืืืืช:**
โข ืื ืื 10% ืืืงืืืืช ืืืฉืื (ืงืื: WELCOME10)
โข ืืฉืืื ืืื ื ืืขื โช150"""
@mcp.tool()
def apply_discount_code(discount_code: str) -> str:
"""
๐ซ ืืคืขืืช ืงืื ืื ืื
Args:
discount_code: ืงืื ืืื ืื (ืืื WELCOME10)
Returns:
ืืืฉืืจ ืืคืขืืช ืืื ืื ืื ืืืืขืช ืฉืืืื
"""
if not shopping_cart:
return "โ ืืขืืื ืจืืงื. ืืืกืฃ ืืืฆืจืื ืืคื ื ืืคืขืืช ืงืื ืื ืื"
subtotal = sum(item["total_price"] for item in shopping_cart.values())
if discount_code.upper() == "WELCOME10":
if subtotal >= PROMOTIONS["first_time"]["min_amount"]:
discount_amount = subtotal * (PROMOTIONS["first_time"]["discount_percent"] / 100)
new_total = subtotal - discount_amount
return f"""โ
**ืงืื ืื ืื ืืืคืขื ืืืฆืืื!**
๐ซ ืงืื: {discount_code.upper()}
๐ ืื ืื: {PROMOTIONS["first_time"]["discount_percent"]}% ({PROMOTIONS["first_time"]["name"]})
๐ฐ ืืกืืช: โช{discount_amount:.2f}
๐ **ืืคื ื ืื ืื:** โช{subtotal:.2f}
๐ **ืืืจื ืื ืื:** โช{new_total:.2f}
๐ณ **ืืืืฉื ืืชืฉืืื:** `checkout`
๐ **ืืฆืคืืื ืืขืืื:** `view_cart`"""
else:
needed = PROMOTIONS["first_time"]["min_amount"] - subtotal
return f"โ ืงืื WELCOME10 ืืืจืฉ ืืืื ื ืืื ืืืืืช ืฉื โช{PROMOTIONS['first_time']['min_amount']:.2f}\n\n๐ก ืืืกืฃ ืขืื โช{needed:.2f} ืืืคืขืืช ืืื ืื"
return f"""โ ืงืื ืื ืื '{discount_code}' ืื ืชืงืฃ
๐ซ **ืงืืื ืื ืื ืืืื ืื:**
โข WELCOME10 - ืื ืื 10% ืืืงืืืืช ืืืฉืื (ืืืื ื ืืขื โช50)
๐ก **ืืืค:** ืงืืื ืื ืื ืจืืืฉืื ืืืืชืืืช ืืืืืืช/ืงืื ืืช"""
@mcp.tool()
def checkout(customer_name: str, customer_email: str, customer_phone: str,
shipping_address: str, notes: str = "", discount_code: str = "") -> str:
"""
๐ณ ืืืฆืืข ืืืื ื ืืชืฉืืื ืืื
Args:
customer_name: ืฉื ืืื
customer_email: ืืชืืืช ืืืืืื
customer_phone: ืืกืคืจ ืืืคืื
shipping_address: ืืชืืืช ืืืื ืืืฉืืื
notes: ืืขืจืืช ืืืืืืืช (ืืืคืฆืืื ืื)
discount_code: ืงืื ืื ืื (ืืืคืฆืืื ืื)
Returns:
ืคืจืื ืืืืื ื ืืืืืื ืืืกืคืจ ืืขืงื
"""
global next_order_id
if not shopping_cart:
return "โ ืืขืืื ืจืืงื. ืืืกืฃ ืืืฆืจืื ืืคื ื ืืืฆืืข ืืืื ื"
# Validate inputs
if not all([customer_name, customer_email, customer_phone, shipping_address]):
return "โ ื ื ืืืื ืืช ืื ืืฉืืืช ืื ืืจืฉืื: ืฉื, ืืืืืื, ืืืคืื ืืืชืืืช ืืฉืืื"
# Calculate totals
subtotal = sum(item["total_price"] for item in shopping_cart.values())
total_items = sum(item["quantity"] for item in shopping_cart.values())
# Apply discount if provided
discount_amount = 0
applied_discount = ""
if discount_code.upper() == "WELCOME10" and subtotal >= PROMOTIONS["first_time"]["min_amount"]:
discount_amount = subtotal * (PROMOTIONS["first_time"]["discount_percent"] / 100)
applied_discount = f"WELCOME10 ({PROMOTIONS['first_time']['discount_percent']}%)"
# Automatic bulk discount
if subtotal >= PROMOTIONS["bulk_discount"]["min_amount"]:
bulk_discount = subtotal * (PROMOTIONS["bulk_discount"]["discount_percent"] / 100)
if bulk_discount > discount_amount:
discount_amount = bulk_discount
applied_discount = f"ืื ืืช ืืืืช ({PROMOTIONS['bulk_discount']['discount_percent']}%)"
# Calculate shipping
shipping_cost = 0 if subtotal >= PROMOTIONS["free_shipping"]["min_amount"] else 25
final_total = subtotal - discount_amount + shipping_cost
# Generate order
order_id = next_order_id
next_order_id += 1
tracking_number = f"ORG{datetime.now().strftime('%Y%m%d')}{order_id:04d}"
# Create order record
orders[order_id] = {
"id": order_id,
"tracking_number": tracking_number,
"customer_name": customer_name,
"customer_email": customer_email,
"customer_phone": customer_phone,
"shipping_address": shipping_address,
"notes": notes,
"items": dict(shopping_cart), # Copy current cart
"subtotal": subtotal,
"discount_amount": discount_amount,
"applied_discount": applied_discount,
"shipping_cost": shipping_cost,
"total": final_total,
"order_date": datetime.now(),
"status": "ืืขืืื",
"estimated_delivery": datetime.now() + timedelta(days=random.randint(2, 5))
}
# Clear cart after successful order
shopping_cart.clear()
# Generate comprehensive receipt
result = "๐ **ืืืืื ื ืืืฆืขื ืืืฆืืื!**\n\n"
result += f"๐ **ืืกืคืจ ืืืื ื: #{order_id}**\n"
result += f"๐ฆ **ืืกืคืจ ืืขืงื: {tracking_number}**\n"
result += f"๐
**ืชืืจืื ืืืื ื:** {datetime.now().strftime('%d/%m/%Y %H:%M')}\n\n"
result += f"๐ค **ืคืจืื ืืงืื:**\n"
result += f"๐ง {customer_name}\n"
result += f"โ๏ธ {customer_email}\n"
result += f"๐ {customer_phone}\n"
result += f"๐ {shipping_address}\n"
if notes:
result += f"๐ ืืขืจืืช: {notes}\n"
result += "\n"
result += f"๐ **ืคืจืืืื ืฉืืืืื ื:**\n"
for product_id, item in orders[order_id]["items"].items():
result += f"โข {item['name']} ร {item['quantity']} = โช{item['total_price']:.2f}\n"
result += f"\n๐ฐ **ืกืืืื ืืกืคื:**\n"
result += f"๐๏ธ ืกื\"ื ืืืฆืจืื ({total_items} ืืืืืืช): โช{subtotal:.2f}\n"
if discount_amount > 0:
result += f"๐ ืื ืื ({applied_discount}): -โช{discount_amount:.2f}\n"
result += f"๐ต ืืืจื ืื ืื: โช{(subtotal - discount_amount):.2f}\n"
if shipping_cost > 0:
result += f"๐ ืืฉืืื: โช{shipping_cost:.2f}\n"
else:
result += "๐ ืืฉืืื: ืืื ื!\n"
result += f"๐ณ **ืกื\"ื ืืืื: โช{final_total:.2f}**\n\n"
result += f"๐ง **ืืืฉืืจ ืืืฉืื ืืืืืืื** ืชืื ืืงืืช ืกืคืืจืืช\n"
estimated_delivery = orders[order_id]["estimated_delivery"]
result += f"๐ **ืืื ืืฉืืื ืืฉืืขืจ:** {estimated_delivery.strftime('%d/%m/%Y')}\n"
result += f"๐ **ืืืืจืืจืื:** 03-1234567 (ืฆืืื ืืืื ื #{order_id})\n\n"
result += f"๐ **ืืืขืงื ืืืจื ืืืืื ื:**\n"
result += f"`track_order {order_id}` ืื `track_by_number {tracking_number}`\n\n"
result += "๐ **ืชืืื ืฉืืืจืช ืืืืจืื ืืื!**\n"
result += "๐ฟ ืืกืืืืื ืืืืขืืช ืืืืจืืื ืืืืชืจ ืืืฉืจืื\n\n"
result += "๐ **ืืฆืขื ืืืืืืช:** ืืฉืชืืฉ ืืงืื RETURN15 ืืืืื ื ืืืื ืืื ืื 15%"
return result
@mcp.tool()
def track_order(order_id: int) -> str:
"""
๐ฆ ืืขืงื ืืืจื ืืืื ื ืืคื ืืกืคืจ ืืืื ื
Args:
order_id: ืืกืคืจ ืืืื ื
Returns:
ืกืืืืก ืืคืืจื ืฉื ืืืืื ื
"""
if order_id not in orders:
return f"โ ืื ื ืืฆืื ืืืื ื ืขื ืืกืคืจ #{order_id}\n\n๐ก ืืื ืฉืืืกืคืจ ื ืืื ืื ืืฉืชืืฉ ื: `track_by_number [ืืกืคืจ ืืขืงื]`"
order = orders[order_id]
# Calculate delivery status
days_since_order = (datetime.now() - order["order_date"]).days
estimated_days = (order["estimated_delivery"] - order["order_date"]).days
# Determine status
if days_since_order >= estimated_days:
current_status = "ื ืืกืจ"
elif days_since_order >= estimated_days - 1:
current_status = "ืืืจื - ืืืืข ืืืื!"
elif days_since_order >= 1:
current_status = "ื ืฉืื"
else:
current_status = "ืืขืืื"
# Status emojis
status_emoji = {
'ืืขืืื': 'โณ',
'ื ืฉืื': '๐',
'ืืืจื - ืืืืข ืืืื!': '๐โโ๏ธ',
'ื ืืกืจ': 'โ
'
}
result = f"๐ฆ **ืืขืงื ืืืื ื #{order['id']}**\n\n"
result += f"๐ค ืืงืื: {order['customer_name']}\n"
result += f"๐
ืืืืื: {order['order_date'].strftime('%d/%m/%Y %H:%M')}\n"
result += f"๐ฆ ืืกืคืจ ืืขืงื: **{order['tracking_number']}**\n"
result += f"๐ ืืชืืืช: {order['shipping_address']}\n\n"
result += f"๐ **ืกืืืืก ื ืืืื: {status_emoji.get(current_status, '๐')} {current_status}**\n\n"
# Timeline
result += "๐
**ืฆืืจ ืืื:**\n"
result += f"โ
{order['order_date'].strftime('%d/%m/%Y %H:%M')} - ืืืื ื ืืชืงืืื\n"
if days_since_order >= 0:
result += f"โ
{(order['order_date'] + timedelta(hours=2)).strftime('%d/%m/%Y %H:%M')} - ืชืฉืืื ืืืฉืจ\n"
if days_since_order >= 1:
result += f"โ
{(order['order_date'] + timedelta(days=1)).strftime('%d/%m/%Y')} - ื ืฉืื ืืืืืกื\n"
if current_status == "ื ืืกืจ":
result += f"โ
{order['estimated_delivery'].strftime('%d/%m/%Y')} - ื ืืกืจ ืืืฆืืื!\n"
elif current_status == "ืืืจื - ืืืืข ืืืื!":
result += f"๐ ืืืื - ืืืจื ืืืื\n"
else:
result += f"โฐ {order['estimated_delivery'].strftime('%d/%m/%Y')} - ืืืขื ืืฉืืขืจืช\n"
result += "\n๐๏ธ **ืคืจืืืื ืืืืื ื:**\n"
for product_id, item in order["items"].items():
result += f"โข {item['name']} ร {item['quantity']} - โช{item['total_price']:.2f}\n"
result += f"\n๐ฐ **ืกืืืื ืืกืคื:**\n"
result += f"๐ ืกื\"ื ืืืฆืจืื: โช{order['subtotal']:.2f}\n"
if order['discount_amount'] > 0:
result += f"๐ ืื ืื ({order['applied_discount']}): -โช{order['discount_amount']:.2f}\n"
if order['shipping_cost'] > 0:
result += f"๐ ืืฉืืื: โช{order['shipping_cost']:.2f}\n"
else:
result += "๐ ืืฉืืื: ืืื ื\n"
result += f"๐ณ **ืกื\"ื: โช{order['total']:.2f}**\n\n"
# Contact info
result += "๐ **ืืืืจืืจืื:**\n"
result += "โข ืืืคืื: 03-1234567\n"
result += "โข ืืืืืื: support@organital.co.il\n"
result += f"โข WhatsApp: 050-1234567 (ืฆืืื ืืืื ื #{order_id})"
return result
@mcp.tool()
def track_by_number(tracking_number: str) -> str:
"""
๐ฆ ืืขืงื ืืืื ื ืืคื ืืกืคืจ ืืขืงื
Args:
tracking_number: ืืกืคืจ ืืืขืงื (ืืื ORG20241117001)
Returns:
ืกืืืืก ืืคืืจื ืฉื ืืืืื ื
"""
# Find order by tracking number
for order_id, order in orders.items():
if order["tracking_number"] == tracking_number.upper():
return track_order(order_id)
return f"โ ืื ื ืืฆืื ืืืื ื ืขื ืืกืคืจ ืืขืงื: {tracking_number}\n\n๐ก ืืื ืฉืืืกืคืจ ื ืืื ืื ืืฉืชืืฉ ื: `track_order [ืืกืคืจ ืืืื ื]`"
@mcp.tool()
def ask_faq(question: str) -> str:
"""
โ ืฉืืืืช ื ืคืืฆืืช ืืชืืืื
Args:
question: ืืฉืืื ืื ื ืืฉื ืืคื ืืื
Returns:
ืชืฉืืื ืืคืืจืืช ืืืกืืก ืืืืข
"""
question_lower = question.lower()
# Search through FAQ database
best_match = None
best_score = 0
for category, questions in FAQ_DATABASE.items():
for faq_question, answer in questions.items():
score = 0
# Check for exact matches in question
if question_lower in faq_question.lower():
score += 10
# Check for word matches
question_words = question_lower.split()
faq_words = faq_question.lower().split()
for word in question_words:
if len(word) > 2: # Skip short words
if word in faq_words:
score += 5
if word in answer.lower():
score += 3
if score > best_score:
best_score = score
best_match = (category, faq_question, answer)
if best_match and best_score >= 3:
category, faq_question, answer = best_match
result = f"โ **ืฉืืื:** {faq_question}\n\n"
result += f"โ
**ืชืฉืืื:**\n{answer}\n\n"
result += f"๐ท๏ธ **ืงืืืืจืื:** {category}\n\n"
# Suggest related questions
related = []
for q in FAQ_DATABASE[category].keys():
if q != faq_question:
related.append(q)
if related:
result += "๐ **ืฉืืืืช ืงืฉืืจืืช:**\n"
for i, related_q in enumerate(related[:3], 1):
result += f"{i}. {related_q}\n"
result += "\n"
result += "๐ **ืืฉืืืืช ื ืืกืคืืช:**\n"
result += "โข ืืืคืื: 03-1234567 (ื'-ื' 9:00-17:00)\n"
result += "โข ืืืืืื: support@organital.co.il\n"
result += "โข WhatsApp: 050-1234567"
return result
# If no good match found, provide general help
result = f"๐ค ืื ืืฆืืชื ืชืฉืืื ืืืืืงืช ืืฉืืื: '{question}'\n\n"
result += "๐ก **ื ืืฉืืื ืคืืคืืืจืืื:**\n\n"
# Show popular questions from each category
for category, questions in FAQ_DATABASE.items():
result += f"**{category}:**\n"
for i, q in enumerate(list(questions.keys())[:2], 1):
result += f"{i}. {q}\n"
result += "\n"
result += "๐ **ืืชืืืื ืืฉืืจื:**\n"
result += "โข ืืืคืื: 03-1234567 (ื'-ื' 9:00-17:00)\n"
result += "โข ืืืืืื: support@organital.co.il\n"
result += "โข WhatsApp: 050-1234567\n\n"
result += "๐ก ื ืกื ืื ืกื ืืช ืืฉืืื ืืืจืช ืื ืืืจ ื ืืฉื ืืืจืฉืืื ืืืขืื"
return result
@mcp.tool()
def get_store_info() -> str:
"""
โน๏ธ ืืืืข ืืื ืขื ืืื ืืช, ืฉืืจืืชืื ืืืฆืืจืช ืงืฉืจ
Returns:
ืืืืข ืืงืืฃ ืขื ืืื ืืช ืืฉืืจืืชืื
"""
return """๐ฟ **ืืจืืืื ืืืืื ืืืืจืื ืืื - ืื ืืช ืืกืืืืื ืืืืขืืช**
๐ **ืขื ืืื ืืช:**
ืืืจืื ืืื ืืื ืืืืื ืืืฉืจืื ืืืืฆืจื ืกืืืืื ืืืขืืื ืืืืจืื ืืื ืืื 8 ืฉื ืื.
ืื ืื ื ืืชืืืื ืืืืืื ืืืฆืืจ ืืืฆืจื ืกืืืืื ืืืืืืช ืืืืืื ืืืืชืจ ืืฉืืจืืช ืืืงืืจืืช ืืืืืื ืืืจืื ืืืจืืงื.
๐ **ืืื ืืืืืจ ืื ื:**
โข โ
ืืืฆืจืื ืืืจืื ืืื ืืืกืืืื
โข โ
3 ืืืืงืืช ืืืืืช ืงืคืื ืืืช ืืื ืืฉืืื
โข โ
ืืืื ืืฉืืจ ืืืงืืืื ืืคืจืืืืื ืืืจืืื
โข โ
ืืื ืชืืกืคืืช ืืืืืืช ืื ืืืืจืื ืืืืืืชืืื
โข โ
ืืฉืืื ืืืืจ ืืืืืืื ืืื ืืืจืฅ
โข โ
ืืืขืืฅ ืชืืื ื ืืงืฆืืขื ืืื ื
โข โ
ืืืจืืืช ืืืืจ ืืกืคื ืชืื 14 ืืืื
๐ **ืืฆืืจืช ืงืฉืจ:**
โข โ๏ธ ืืืคืื: 03-1234567 (ื'-ื' 9:00-17:00)
โข โ๏ธ ืืืืืื: support@organital.co.il
โข ๐ฑ WhatsApp: 050-1234567 (ืืืื 24/7)
โข ๐ ืืชืจ: www.organital.co.il
๐ **ืืฉืืืืื:**
โข ๐ ืืฉืืื ืืื ื ืขื ืืืื ืืช ืืขื โช150
โข ๐ฆ ืืฉืืื ืืืืจ ืชืื 2-5 ืืื ืขืกืงืื
โข ๐ช ืืคืฉืจืืช ืืืกืืฃ ืขืฆืื (ืืชืืืื ืืจืืฉ)
โข ๐ ืืฉืืื ืืื ืืืจืฅ ืืืื ืืืฉืืืื ืืจืืืงืื
๐ณ **ืืคืฉืจืืืืช ืชืฉืืื:**
โข ๐ณ ืืจืืืกื ืืฉืจืื (ืืืื, ืืืกืืจืงืืจื, ืืืงืก)
โข ๐ฑ ืืื ืืคืืืืืงืก
โข ๐ฆ ืืขืืจื ืื ืงืืืช
โข ๐ต ืชืฉืืื ืืขืช ืืืกืืฃ
๐ **ืืืื ืืืช ืืืืจืืช:**
โข โ
ืืืืจื ืชืื 14 ืืืื ืืื ืฉืืืืช
โข ๐ฐ ืืืืจ ืืกืคื ืืื
โข ๐ฆ ืืืืฆืจ ืืืื ืืืืืช ืืืจืืื ืืงืืจืืช
โข ๐ ืืื ืืฉืืื ืืืืจื ืขื ืืฉืืื ื ื
๐ฑ **ืืืืขืืฅ ืืชืืื ืชื ืฉืื ื:**
ืฆืฆืจื ืงืฉืจ ืืืืขืืฅ ืืื ื ืขื ืืืืืื ืืช ืฉืื ื:
โข ๐ ืชืื ืื ืชืคืจืื ืขื ืกืืืืื
โข ๐ฐ ืืชืืื ืื ืืืืืืื ืืืคืื ืืจืืื
โข ๐ ืฉืืืื ืขื ืชืจืืคืืช ืืืืืืืช ืืืืืืืช
โข ๐ถ ืฉืืืืฉ ืืกืืืืื ืืืืืื
๐ **ืืืชืืืช ืงื ืืื:**
โข `browse_products` - ืขืืื ืืื ืืืืฆืจืื
โข `search_products [ืืืื]` - ืืืคืืฉ ืืืฆืจ ืกืคืฆืืคื
โข `ask_faq [ืฉืืื]` - ืฉืืืืช ืืชืฉืืืืช ื ืคืืฆืืช
๐ **ืืฆืขืืช ืืืืืืืช:**
โข ๐ ืื ืื 10% ืืืงืืืืช ืืืฉืื (ืงืื: WELCOME10)
โข ๐ ืื ืื 15% ืขื ืืืื ืืช ืืขื โช300
โข ๐ ืื ืืช ืืื ืืืืืช 20% (ืืืืืฉ ืืืืืชืื)
โข ๐ฅ ืื ืื 25% ืขื ืืืื ืืช ืงืืืฆืชืืืช (5+ ืืืืืืช)"""
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Complete Stevia Store MCP Server")
args = parser.parse_args()
# Run the FastMCP server
mcp.run()