get_enrollments
Retrieve enrollment records with filters for student, course, status, and pagination via cursor and per_page.
Instructions
Get all enrollment records
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) | |
| student_id | No | Filter results on student_id | |
| planned_course_id | No | Filter results on planned_course_id | |
| status | No | Filter results on status | |
| with_canceled | No | Filter results based on whether they include a canceled status or not |
Implementation Reference
- src/tools/enrollments.ts:7-52 (registration)Registers the 'get_enrollments' tool on the MCP server via server.registerTool('get_enrollments', ...)
export function registerEnrollmentTools(server: McpServer): void { server.registerTool( "get_enrollments", { description: "Get all enrollment records", 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)"), student_id: z.number().int().optional().describe("Filter results on student_id"), planned_course_id: z.number().int().optional().describe("Filter results on planned_course_id"), status: z .array(z.enum(["confirmed", "active", "canceled", "completed"])) .optional() .describe("Filter results on status"), with_canceled: z .boolean() .optional() .describe("Filter results based on whether they include a canceled status or not"), }, }, async ({ cursor, per_page, student_id, planned_course_id, status, with_canceled }) => { try { const result = await apiList<EduframeRecord>("/enrollments", { cursor, per_page, student_id, planned_course_id, status, with_canceled, }); void logResponse( "get_enrollments", { cursor, per_page, student_id, planned_course_id, status, with_canceled }, result, ); const toolResult = formatList(result.records, "enrollments"); if (result.nextCursor) { toolResult.content.push({ type: "text", text: `\nNext page cursor: ${result.nextCursor}` }); } return toolResult; } catch (error) { return formatError(error); } }, ); - src/tools/enrollments.ts:28-51 (handler)The async handler function that executes the 'get_enrollments' tool logic: calls apiList('/enrollments', ...) and formats results
async ({ cursor, per_page, student_id, planned_course_id, status, with_canceled }) => { try { const result = await apiList<EduframeRecord>("/enrollments", { cursor, per_page, student_id, planned_course_id, status, with_canceled, }); void logResponse( "get_enrollments", { cursor, per_page, student_id, planned_course_id, status, with_canceled }, result, ); const toolResult = formatList(result.records, "enrollments"); if (result.nextCursor) { toolResult.content.push({ type: "text", text: `\nNext page cursor: ${result.nextCursor}` }); } return toolResult; } catch (error) { return formatError(error); } }, - src/tools/enrollments.ts:13-26 (schema)Zod input schema for the 'get_enrollments' tool: cursor, per_page, student_id, planned_course_id, status, with_canceled
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)"), student_id: z.number().int().optional().describe("Filter results on student_id"), planned_course_id: z.number().int().optional().describe("Filter results on planned_course_id"), status: z .array(z.enum(["confirmed", "active", "canceled", "completed"])) .optional() .describe("Filter results on status"), with_canceled: z .boolean() .optional() .describe("Filter results based on whether they include a canceled status or not"), }, - src/api.ts:122-137 (helper)The apiList helper function used by the 'get_enrollments' handler to GET /enrollments with query params
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 }; } - src/formatters.ts:40-60 (helper)The formatList helper used to format the enrollment records into a CallToolResult response
export function formatList(records: EduframeRecord[], resourceName: string): CallToolResult { if (records.length === 0) { return { content: [ { type: "text", text: `No ${resourceName} found.`, }, ], }; } return { content: [ { type: "text", text: `Found ${records.length} ${resourceName}:\n\n${formatJSON(records)}${RESPONSE_LOG_HINT}`, }, ], }; }