Spaces:
No application file
No application file
Update chat_mcp_server.py
Browse files- chat_mcp_server.py +22 -30
chat_mcp_server.py
CHANGED
@@ -1,9 +1,24 @@
|
|
1 |
-
|
|
|
2 |
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
|
6 |
-
@mcp.tool()
|
7 |
def product_recommendation(product_name: str) -> str:
|
8 |
"""
|
9 |
Recommend a product based on the provided product name.
|
@@ -17,8 +32,7 @@ def product_recommendation(product_name: str) -> str:
|
|
17 |
return f"I recommend you try {product_name}."
|
18 |
|
19 |
|
20 |
-
|
21 |
-
def cart_managemnt(action: str, product_name: str) -> str:
|
22 |
"""
|
23 |
Manage the shopping cart by adding or removing products.
|
24 |
|
@@ -37,7 +51,6 @@ def cart_managemnt(action: str, product_name: str) -> str:
|
|
37 |
return "Invalid action. Please specify 'add' or 'remove'."
|
38 |
|
39 |
|
40 |
-
@mcp.tool()
|
41 |
def abondoned_cart_recovery() -> str:
|
42 |
"""
|
43 |
Recover abandoned carts by sending a reminder to the user.
|
@@ -48,7 +61,6 @@ def abondoned_cart_recovery() -> str:
|
|
48 |
return "Don't forget to complete your purchase! Your cart is waiting for you."
|
49 |
|
50 |
|
51 |
-
@mcp.tool()
|
52 |
def order_tracking(order_id: str) -> str:
|
53 |
"""
|
54 |
Track an order based on the provided order ID.
|
@@ -62,7 +74,6 @@ def order_tracking(order_id: str) -> str:
|
|
62 |
return f"Your order {order_id} is currently being processed and will be shipped soon."
|
63 |
|
64 |
|
65 |
-
@mcp.tool()
|
66 |
def checkout() -> str:
|
67 |
"""
|
68 |
Perform the checkout process.
|
@@ -73,7 +84,6 @@ def checkout() -> str:
|
|
73 |
return "Checkout completed successfully! Thank you for your purchase."
|
74 |
|
75 |
|
76 |
-
@mcp.tool()
|
77 |
def customer_support(issue: str) -> str:
|
78 |
"""
|
79 |
Provide customer support for the specified issue.
|
@@ -87,27 +97,12 @@ def customer_support(issue: str) -> str:
|
|
87 |
return f"Our customer support team is looking into your issue: {issue}. We will get back to you shortly."
|
88 |
|
89 |
|
90 |
-
@mcp.tool()
|
91 |
-
def product_search(query: str) -> str:
|
92 |
-
"""
|
93 |
-
Search for products based on the provided query.
|
94 |
-
|
95 |
-
Args:
|
96 |
-
query (str): The search query for products.
|
97 |
-
|
98 |
-
Returns:
|
99 |
-
str: A message with the search results.
|
100 |
-
"""
|
101 |
-
return f"Here are the products matching your search for '{query}': [Product List]."
|
102 |
-
|
103 |
-
|
104 |
-
@mcp.tool()
|
105 |
def multi_channel_support(channel: str, message: str) -> str:
|
106 |
"""
|
107 |
Provide support through multiple channels.
|
108 |
|
109 |
Args:
|
110 |
-
channel (str): The support channel (e.g., 'email', 'chat', 'phone').
|
111 |
message (str): The message or issue to address.
|
112 |
|
113 |
Returns:
|
@@ -116,7 +111,6 @@ def multi_channel_support(channel: str, message: str) -> str:
|
|
116 |
return f"We have received your message via {channel}: '{message}'. Our team will respond shortly."
|
117 |
|
118 |
|
119 |
-
@mcp.tool()
|
120 |
def personalized_recommendations(user_id: str) -> str:
|
121 |
"""
|
122 |
Provide personalized product recommendations based on the user's ID.
|
@@ -130,7 +124,6 @@ def personalized_recommendations(user_id: str) -> str:
|
|
130 |
return f"Based on your preferences, we recommend the following products for you, User {user_id}: [Personalized Product List]."
|
131 |
|
132 |
|
133 |
-
@mcp.tool()
|
134 |
def inventory_management(product_name: str, action: str) -> str:
|
135 |
"""
|
136 |
Manage inventory by adding or removing products.
|
@@ -150,7 +143,6 @@ def inventory_management(product_name: str, action: str) -> str:
|
|
150 |
return "Invalid action. Please specify 'add' or 'remove'."
|
151 |
|
152 |
|
153 |
-
@mcp.tool()
|
154 |
def stock_awareness(product_name: str) -> str:
|
155 |
"""
|
156 |
Check the stock availability of a product.
|
@@ -163,5 +155,5 @@ def stock_awareness(product_name: str) -> str:
|
|
163 |
"""
|
164 |
return f"The current stock status for {product_name} is: [Stock Status]."
|
165 |
|
166 |
-
|
167 |
-
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from web_scraper import search_your_product
|
3 |
|
4 |
+
|
5 |
+
def product_search(query: str) -> str:
|
6 |
+
"""
|
7 |
+
Search for products based on the provided query.
|
8 |
+
|
9 |
+
Args:
|
10 |
+
query (str): The search query for products.
|
11 |
+
|
12 |
+
Returns:
|
13 |
+
str: A message with the search results.
|
14 |
+
"""
|
15 |
+
|
16 |
+
results = search_your_product(query)
|
17 |
+
if not results:
|
18 |
+
return f"No products found for your search: '{query}'. Please try a different query."
|
19 |
+
return f"Here are the products matching your search for '{query}': {results}."
|
20 |
|
21 |
|
|
|
22 |
def product_recommendation(product_name: str) -> str:
|
23 |
"""
|
24 |
Recommend a product based on the provided product name.
|
|
|
32 |
return f"I recommend you try {product_name}."
|
33 |
|
34 |
|
35 |
+
def cart_management(action: str, product_name: str) -> str:
|
|
|
36 |
"""
|
37 |
Manage the shopping cart by adding or removing products.
|
38 |
|
|
|
51 |
return "Invalid action. Please specify 'add' or 'remove'."
|
52 |
|
53 |
|
|
|
54 |
def abondoned_cart_recovery() -> str:
|
55 |
"""
|
56 |
Recover abandoned carts by sending a reminder to the user.
|
|
|
61 |
return "Don't forget to complete your purchase! Your cart is waiting for you."
|
62 |
|
63 |
|
|
|
64 |
def order_tracking(order_id: str) -> str:
|
65 |
"""
|
66 |
Track an order based on the provided order ID.
|
|
|
74 |
return f"Your order {order_id} is currently being processed and will be shipped soon."
|
75 |
|
76 |
|
|
|
77 |
def checkout() -> str:
|
78 |
"""
|
79 |
Perform the checkout process.
|
|
|
84 |
return "Checkout completed successfully! Thank you for your purchase."
|
85 |
|
86 |
|
|
|
87 |
def customer_support(issue: str) -> str:
|
88 |
"""
|
89 |
Provide customer support for the specified issue.
|
|
|
97 |
return f"Our customer support team is looking into your issue: {issue}. We will get back to you shortly."
|
98 |
|
99 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
def multi_channel_support(channel: str, message: str) -> str:
|
101 |
"""
|
102 |
Provide support through multiple channels.
|
103 |
|
104 |
Args:
|
105 |
+
channel (str): The support channel (e.g., 'email', 'chat', 'phone', 'whatsapp').
|
106 |
message (str): The message or issue to address.
|
107 |
|
108 |
Returns:
|
|
|
111 |
return f"We have received your message via {channel}: '{message}'. Our team will respond shortly."
|
112 |
|
113 |
|
|
|
114 |
def personalized_recommendations(user_id: str) -> str:
|
115 |
"""
|
116 |
Provide personalized product recommendations based on the user's ID.
|
|
|
124 |
return f"Based on your preferences, we recommend the following products for you, User {user_id}: [Personalized Product List]."
|
125 |
|
126 |
|
|
|
127 |
def inventory_management(product_name: str, action: str) -> str:
|
128 |
"""
|
129 |
Manage inventory by adding or removing products.
|
|
|
143 |
return "Invalid action. Please specify 'add' or 'remove'."
|
144 |
|
145 |
|
|
|
146 |
def stock_awareness(product_name: str) -> str:
|
147 |
"""
|
148 |
Check the stock availability of a product.
|
|
|
155 |
"""
|
156 |
return f"The current stock status for {product_name} is: [Stock Status]."
|
157 |
|
158 |
+
|
159 |
+
gr.launch(mcp_server=True) # exposes an MCP schema automatically
|