|
@@ -217,6 +217,8 @@ async function fetchAllOrdersPages(
|
|
|
async function handleGetOrder(args: Record<string, any>): Promise<ToolCallResult> {
|
|
async function handleGetOrder(args: Record<string, any>): Promise<ToolCallResult> {
|
|
|
const { shop_id, order_id } = args;
|
|
const { shop_id, order_id } = args;
|
|
|
|
|
|
|
|
|
|
+ console.log('[MCP ShopRenter] handleGetOrder called with:', { shop_id, order_id });
|
|
|
|
|
+
|
|
|
// Validate order_id is provided
|
|
// Validate order_id is provided
|
|
|
if (!order_id) {
|
|
if (!order_id) {
|
|
|
return {
|
|
return {
|
|
@@ -233,18 +235,21 @@ async function handleGetOrder(args: Record<string, any>): Promise<ToolCallResult
|
|
|
// Validate shop exists and is ShopRenter
|
|
// Validate shop exists and is ShopRenter
|
|
|
const { data: store, error: storeError } = await supabase
|
|
const { data: store, error: storeError } = await supabase
|
|
|
.from('stores')
|
|
.from('stores')
|
|
|
- .select('id, platform_name, data_access_permissions')
|
|
|
|
|
|
|
+ .select('id, platform_name, store_name, data_access_permissions')
|
|
|
.eq('id', shop_id)
|
|
.eq('id', shop_id)
|
|
|
.eq('platform_name', 'shoprenter')
|
|
.eq('platform_name', 'shoprenter')
|
|
|
.single();
|
|
.single();
|
|
|
|
|
|
|
|
if (storeError || !store) {
|
|
if (storeError || !store) {
|
|
|
|
|
+ console.error('[MCP ShopRenter] Store not found:', { shop_id, error: storeError });
|
|
|
return {
|
|
return {
|
|
|
content: [{ type: 'text', text: JSON.stringify({ error: 'ShopRenter store not found' }) }],
|
|
content: [{ type: 'text', text: JSON.stringify({ error: 'ShopRenter store not found' }) }],
|
|
|
isError: true
|
|
isError: true
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ console.log('[MCP ShopRenter] Store found:', { id: store.id, store_name: store.store_name });
|
|
|
|
|
+
|
|
|
// Check permissions
|
|
// Check permissions
|
|
|
const permissions = store.data_access_permissions as any;
|
|
const permissions = store.data_access_permissions as any;
|
|
|
if (permissions && !permissions.allow_order_access) {
|
|
if (permissions && !permissions.allow_order_access) {
|
|
@@ -257,21 +262,32 @@ async function handleGetOrder(args: Record<string, any>): Promise<ToolCallResult
|
|
|
try {
|
|
try {
|
|
|
// Search for order by innerId (customer-visible order number)
|
|
// Search for order by innerId (customer-visible order number)
|
|
|
// The order_id parameter is actually the innerId from the customer's perspective
|
|
// The order_id parameter is actually the innerId from the customer's perspective
|
|
|
|
|
+ console.log('[MCP ShopRenter] Fetching order with innerId:', order_id);
|
|
|
const response = await fetchOrders(shop_id, 0, 1, { innerId: order_id });
|
|
const response = await fetchOrders(shop_id, 0, 1, { innerId: order_id });
|
|
|
const orders = Array.isArray(response) ? response : (response.data || response.orders || []);
|
|
const orders = Array.isArray(response) ? response : (response.data || response.orders || []);
|
|
|
|
|
|
|
|
|
|
+ console.log('[MCP ShopRenter] API response:', { ordersCount: orders.length });
|
|
|
|
|
+
|
|
|
if (orders.length === 0) {
|
|
if (orders.length === 0) {
|
|
|
|
|
+ console.warn('[MCP ShopRenter] No order found with innerId:', order_id);
|
|
|
return {
|
|
return {
|
|
|
content: [{
|
|
content: [{
|
|
|
type: 'text',
|
|
type: 'text',
|
|
|
text: JSON.stringify({
|
|
text: JSON.stringify({
|
|
|
- error: `No order found with order number: ${order_id}`
|
|
|
|
|
|
|
+ error: `No order found with order number: ${order_id}`,
|
|
|
|
|
+ debug: {
|
|
|
|
|
+ shop_id,
|
|
|
|
|
+ store_name: store.store_name,
|
|
|
|
|
+ searched_innerId: order_id
|
|
|
|
|
+ }
|
|
|
})
|
|
})
|
|
|
}],
|
|
}],
|
|
|
isError: true
|
|
isError: true
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ console.log('[MCP ShopRenter] Order found:', { innerId: orders[0].innerId || orders[0].id });
|
|
|
|
|
+
|
|
|
// Format for LLM
|
|
// Format for LLM
|
|
|
const formattedOrder = formatOrderForLlm(orders[0]);
|
|
const formattedOrder = formatOrderForLlm(orders[0]);
|
|
|
|
|
|
|
@@ -289,7 +305,12 @@ async function handleGetOrder(args: Record<string, any>): Promise<ToolCallResult
|
|
|
content: [{
|
|
content: [{
|
|
|
type: 'text',
|
|
type: 'text',
|
|
|
text: JSON.stringify({
|
|
text: JSON.stringify({
|
|
|
- error: `Failed to fetch order: ${error instanceof Error ? error.message : 'Unknown error'}`
|
|
|
|
|
|
|
+ error: `Failed to fetch order: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
|
|
|
|
+ debug: {
|
|
|
|
|
+ shop_id,
|
|
|
|
|
+ order_id,
|
|
|
|
|
+ errorDetails: error instanceof Error ? error.stack : String(error)
|
|
|
|
|
+ }
|
|
|
})
|
|
})
|
|
|
}],
|
|
}],
|
|
|
isError: true
|
|
isError: true
|