data_list_discounts
Retrieve and display available discount options from the POS system in JSON, CSV, or HTML format for sales transaction processing.
Instructions
Liste des Lister les réductions
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| format | No | json |
Implementation Reference
- src/tools/data.ts:90-114 (handler)The handler function for the 'data_list_discounts' tool (shared with other simple list tools). It authenticates the request, performs an HTTP GET to '/workers/getDiscounts.php' with shop credentials and format, structures the response data into a preview and full structured content, logs details, and handles errors gracefully.async ({ format }: CommonArgs, ctx: Ctx) => { try { const { shopId, apiKey } = resolveAuth(undefined, ctx); const data = await get(path, { idboutique: shopId, key: apiKey, format }); process.stderr.write( `[caisse][tool:${toolName}] ok type=${Array.isArray(data) ? 'array' : typeof data}` + (Array.isArray(data) ? ` len=${data.length}` : '') + '\n' ); //Array.isArray(data) ? data.slice(0, 50) : data const funcResult = structData( data); process.stderr.write(`[caisse][RES] ${JSON.stringify(data)} \n`); process.stderr.write(`[caisse][RES] funcResult ${JSON.stringify(funcResult)} \n`); return funcResult; //return { content, structuredContent: isText ? undefined : data }; } catch (e) { process.stderr.write(`[caisse][tool:${toolName}][error]\n`); process.stderr.write(`[caisse][tool:${toolName}][error] ${(e as Error).message}\n`); // renvoyer un message "propre" plutôt que laisser l’exception devenir un 424 return { content: [{ type: 'text', text: `Erreur pendant la préparation de la réponse: ${(e as Error).message}` }], is_error: true, }; }
- src/tools/data.ts:11-13 (schema)Shared Zod input schema for simple data list tools like 'data_list_discounts', defining an optional 'format' parameter defaulting to 'json'.const CommonShape = { format: z.enum(['json', 'csv', 'html']).default('json'), } satisfies Record<string, ZodTypeAny>;
- src/tools/data.ts:132-132 (registration)Registers the 'data_list_discounts' tool on the MCP server using the registerSimple helper, specifying the backend endpoint '/workers/getDiscounts.php' and localized title/description.registerSimple(server, 'data_list_discounts', '/workers/getDiscounts.php', t('tools.data_list_discounts.description'), t('tools.data_list_discounts.title'));