get_discount_codes
Retrieve discount codes with pagination support using cursor and per_page parameters for efficient data access.
Instructions
Get all discount codes
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cursor | No | Cursor for fetching the next page of results | |
| per_page | No | Number of results per page (default: 25) |
Implementation Reference
- src/tools/discount_codes.ts:18-31 (handler)The async handler function for the 'get_discount_codes' tool. It calls apiList to fetch discount codes from the /discount_codes endpoint, logs the response, formats the result using formatList, and appends a next-page cursor if present.
async ({ cursor, per_page }) => { try { const result = await apiList<EduframeRecord>("/discount_codes", { cursor, per_page }); void logResponse("get_discount_codes", { cursor, per_page }, result); const toolResult = formatList(result.records, "discount codes"); if (result.nextCursor) { toolResult.content.push({ type: "text", text: `\nNext page cursor: ${result.nextCursor}` }); } return toolResult; } catch (error) { return formatError(error); } }, ); - src/tools/discount_codes.ts:10-16 (schema)Input schema for the 'get_discount_codes' tool. Defines optional 'cursor' (string) and 'per_page' (positive integer) parameters with descriptions.
{ description: "Get all discount codes", annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true }, inputSchema: { cursor: z.string().optional().describe("Cursor for fetching the next page of results"), per_page: z.number().int().positive().optional().describe("Number of results per page (default: 25)"), }, - src/tools/discount_codes.ts:8-8 (registration)Tool registration call: server.registerTool('get_discount_codes', ...) which registers the tool name with the MCP server.
server.registerTool( - src/tools/index.ts:128-132 (registration)The registerAllTools function iterates over all tool registrations, including registerDiscountCodeTools, to register them with the MCP server.
export function registerAllTools(server: McpServer): void { for (const register of tools) { register(server); } } - src/api.ts:122-137 (helper)The apiList helper function used by the handler to perform a GET request to the Eduframe API with cursor-based pagination support.
export async function apiList<T>(path: string, query?: Record<string, QueryValue>): Promise<ListResult<T>> { const { token } = getConfig(); const url = buildUrl(path, query); const response = await fetch(url.toString(), { method: "GET", headers: buildHeaders(token), }); await checkResponse(response); const records = (await response.json()) as T[]; const nextCursor = parseNextCursor(response.headers.get("Link")); return { records, nextCursor }; }