get-product-details
Retrieve detailed product information from Terminal.shop using a product ID for browsing, shopping cart management, and order placement.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| productId | Yes |
Implementation Reference
- server.js:507-560 (handler)The handler function for the 'get-product-details' tool. It fetches product details from the Terminal.shop API using the provided productId, formats the information including name, description, variants, subscription options, and tags, and returns it as formatted text.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, }; } },
- server.js:504-506 (schema)The input schema for the 'get-product-details' tool, requiring a 'productId' string parameter validated with Zod.{ productId: z.string(), },
- server.js:502-561 (registration)The registration of the 'get-product-details' tool on the MCP server using server.tool(), specifying the tool name, input schema, and inline handler function.server.tool( "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, }; } }, );