Get Upcoming Due Dates
get_upcoming_due_datesRetrieve upcoming assignment and quiz due dates across all courses. Filter by course or specify the number of days ahead to view deadlines.
Instructions
Fetch upcoming due dates across all your courses. Shows assignments, quizzes, and other items due within the specified time window. Use this when the user asks about deadlines, what's due, upcoming work, or what they need to do this week.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| daysAhead | No | Number of days ahead to look for due dates | |
| courseId | No | Filter to a specific course ID |
Implementation Reference
- The registerGetUpcomingDueDates function that registers and implements the 'get_upcoming_due_dates' tool. Fetches upcoming due dates across courses from the Brightspace calendar API, with optional courseId filter and configurable daysAhead window.
export function registerGetUpcomingDueDates( server: McpServer, apiClient: D2LApiClient, config: AppConfig ): void { server.registerTool( "get_upcoming_due_dates", { title: "Get Upcoming Due Dates", description: "Fetch upcoming due dates across all your courses. Shows assignments, quizzes, and other items due within the specified time window. Use this when the user asks about deadlines, what's due, upcoming work, or what they need to do this week.", inputSchema: GetUpcomingDueDatesSchema, }, async (args: any) => { try { log("DEBUG", "get_upcoming_due_dates tool called", { args }); // Parse and validate input const { daysAhead, courseId } = GetUpcomingDueDatesSchema.parse(args); // Build time window const now = new Date(); const endDate = new Date(now.getTime() + daysAhead * 24 * 60 * 60 * 1000); const startDateTime = now.toISOString(); const endDateTime = endDate.toISOString(); // D2L calendar API requires orgUnitIdsCSV — fetch enrolled course IDs if not provided let orgUnitIds: string; if (courseId) { orgUnitIds = String(courseId); } else { const enrollments = await apiClient.get<{ Items: EnrollmentItem[] }>( apiClient.lp(`/enrollments/myenrollments/?orgUnitTypeId=3&isActive=true`), { ttl: DEFAULT_CACHE_TTLS.enrollments } ); // Apply course filter const filteredEnrollments = applyCourseFilter( enrollments.Items.map(item => ({ id: item.OrgUnit.Id, name: item.OrgUnit.Name, code: item.OrgUnit.Code, isActive: item.Access.IsActive, })), config.courseFilter ); orgUnitIds = filteredEnrollments.map((e) => e.id).join(","); } log("DEBUG", `get_upcoming_due_dates: querying orgUnitIds=${orgUnitIds}, window=${startDateTime} to ${endDateTime}`); // Build path const path = apiClient.leGlobal( `/calendar/events/myEvents/?startDateTime=${encodeURIComponent(startDateTime)}&endDateTime=${encodeURIComponent(endDateTime)}&orgUnitIdsCSV=${orgUnitIds}` ); // Fetch events — D2L returns ObjectListPage wrapper with "Objects" array (NOT "Items") const response = await apiClient.get<{ Objects: EventDataInfo[]; Next: string | null }>(path, { ttl: DEFAULT_CACHE_TTLS.assignments, }); const events = response.Objects ?? []; log("DEBUG", `get_upcoming_due_dates: raw response keys=${Object.keys(response).join(",")}, event count=${events.length}`); // Map to clean objects and sort by end date (soonest due first) const mappedEvents = events .map((event) => ({ id: event.CalendarEventId, title: event.Title, courseName: event.OrgUnitName, courseId: event.OrgUnitId, startDate: event.StartDateTime, endDate: event.EndDateTime, isAllDay: event.IsAllDayEvent, })) .sort( (a, b) => new Date(a.endDate).getTime() - new Date(b.endDate).getTime() ); log( "INFO", `get_upcoming_due_dates: Retrieved ${mappedEvents.length} events` ); return toolResponse(mappedEvents); } catch (error) { return sanitizeError(error); } } ); } - src/tools/schemas.ts:19-22 (schema)Zod schema for GetUpcomingDueDates tool validating two inputs: daysAhead (number, 1-90, default 7) and courseId (optional positive integer).
export const GetUpcomingDueDatesSchema = z.object({ daysAhead: z.coerce.number().int().min(1).max(90).default(7).describe("Number of days ahead to look for due dates"), courseId: z.coerce.number().int().positive().optional().describe("Filter to a specific course ID"), }); - src/index.ts:20-30 (registration)Import of registerGetUpcomingDueDates at the top of src/index.ts.
import { registerGetMyCourses, registerGetUpcomingDueDates, registerGetMyGrades, registerGetAnnouncements, registerGetAssignments, registerGetCourseContent, registerDownloadFile, registerGetClasslistEmails, registerGetRoster, registerGetSyllabus, - src/index.ts:180-180 (registration)Registration call: registerGetUpcomingDueDates(server, apiClient, config) in the server setup.
registerGetUpcomingDueDates(server, apiClient, config); - src/tools/index.ts:9-9 (registration)Barrel re-export of registerGetUpcomingDueDates from tools/index.ts.
export { registerGetUpcomingDueDates } from "./get-upcoming-due-dates.js";