@opra-app/mcp
Version:
MCP server for OPRA's business and discount data
28 lines (27 loc) • 1.03 kB
JavaScript
import { z } from "zod";
import { getDiscountCode } from "../api.js";
export const registerGetDiscountCodeTool = (server) => {
server.tool("get-discount-code", "Generates a single-use discount code that the user can redeem. Only call this when the user explicitly wants to use a specific discount.", {
id: z
.string()
.describe("The discount ID. Get this from list-discounts or get-discount-or-campaign-details."),
}, async ({ id }) => {
try {
const discountCode = await getDiscountCode(id);
return {
content: [{ type: "text", text: JSON.stringify(discountCode, null, 2) }],
};
}
catch (error) {
return {
isError: true,
content: [
{
type: "text",
text: `Failed to retrieve discount code for discount with ID ${id}: ${error}`,
},
],
};
}
});
};