import { ToolMetadata } from 'xmcp';
const baseUrl = 'https://backend.codingthailand.com';
export const metadata: ToolMetadata = {
name: "get_all_products",
description: "เครื่องมือสำหรับดึงข้อมูลสินค้าทั้งหมดจากระบบ",
annotations: {
title: "ดึงข้อมูลสินค้าทั้งหมด",
readOnlyHint: true,
destructiveHint: false,
idempotentHint: true
}
};
export default async function getAllProducts() {
try {
const res = await fetch(`${baseUrl}/v2/products`);
if (!res.ok) {
return `เกิดข้อผิดพลาดจาก API: ${res.statusText}`;
}
const products = await res.json();
return {
structuredContent: {
products: products,
total: products.length
},
content: [
{
type: 'text',
text: `พบสินค้า ${products.length} รายการ`
}
]
}
} catch (error) {
return `เกิดข้อผิดพลาด: ${error instanceof Error ? error.message : "Unknown error"}`;
}
}