get-product-details
Retrieve detailed product information from Terminal.shop using a product ID to support shopping decisions and order management.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| productId | Yes |
Implementation Reference
- server.js:508-560 (handler)The handler function for the 'get-product-details' tool. It fetches product details using the provided productId from the terminalApi, formats the information including name, description, variants, subscription info, and tags into markdown text, and returns it. Handles errors by returning an error message.try { const response = await terminalApi.get(`/product/${productId}`); const product = response.data.data; // Format the product details let formattedText = `# ${product.name}\n\n`; formattedText += `ID: ${product.id}\n\n`; formattedText += `## Description\n${product.description}\n\n`; // Add variants section formattedText += `## Available Variants\n`; product.variants.forEach((variant) => { formattedText += `### ${variant.name}\n`; formattedText += `- Price: $${variant.price / 100}\n`; formattedText += `- ID: ${variant.id}\n\n`; }); // Add subscription info if available if (product.subscription) { formattedText += `## Subscription Options\n`; formattedText += `This product ${product.subscription === "required" ? "requires" : "allows"} subscription.\n\n`; } // Add tags if available if (product.tags && Object.keys(product.tags).length > 0) { formattedText += `## Product Tags\n`; Object.entries(product.tags).forEach(([key, value]) => { formattedText += `- ${key}: ${value}\n`; }); formattedText += "\n"; } return { content: [ { type: "text", text: formattedText, }, ], }; } catch (error) { console.error(`Error fetching product ${productId}:`, error); return { content: [ { type: "text", text: `Error fetching product details: ${error.message}`, }, ], isError: true, }; } },
- server.js:505-507 (schema)Input schema for the 'get-product-details' tool, defining 'productId' as a required string using Zod validation.productId: z.string(), }, async ({ productId }) => {
- server.js:503-562 (registration)Registration of the 'get-product-details' tool using server.tool(), specifying the name, input schema, and inline handler function."get-product-details", { productId: z.string(), }, async ({ productId }) => { try { const response = await terminalApi.get(`/product/${productId}`); const product = response.data.data; // Format the product details let formattedText = `# ${product.name}\n\n`; formattedText += `ID: ${product.id}\n\n`; formattedText += `## Description\n${product.description}\n\n`; // Add variants section formattedText += `## Available Variants\n`; product.variants.forEach((variant) => { formattedText += `### ${variant.name}\n`; formattedText += `- Price: $${variant.price / 100}\n`; formattedText += `- ID: ${variant.id}\n\n`; }); // Add subscription info if available if (product.subscription) { formattedText += `## Subscription Options\n`; formattedText += `This product ${product.subscription === "required" ? "requires" : "allows"} subscription.\n\n`; } // Add tags if available if (product.tags && Object.keys(product.tags).length > 0) { formattedText += `## Product Tags\n`; Object.entries(product.tags).forEach(([key, value]) => { formattedText += `- ${key}: ${value}\n`; }); formattedText += "\n"; } return { content: [ { type: "text", text: formattedText, }, ], }; } catch (error) { console.error(`Error fetching product ${productId}:`, error); return { content: [ { type: "text", text: `Error fetching product details: ${error.message}`, }, ], isError: true, }; } }, );