Get My Courses
get_my_coursesRetrieve your enrolled Brightspace courses including names, codes, and IDs. Use this to view current classes or obtain course identifiers for other queries.
Instructions
Fetch your enrolled Brightspace courses with names, codes, and IDs. Use this when the user asks about their courses, enrolled classes, what they're taking this semester, or needs a course ID for other queries.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| activeOnly | No | Only return currently active courses |
Implementation Reference
- src/tools/get-my-courses.ts:41-100 (handler)The registerGetMyCourses function that registers and implements the get_my_courses tool. It calls server.registerTool with the tool name, metadata, and an async handler that fetches Brightspace enrollments via the D2L API, maps them to a clean structure, applies a course filter, and returns the result.
export function registerGetMyCourses( server: McpServer, apiClient: D2LApiClient, config: AppConfig ): void { server.registerTool( "get_my_courses", { title: "Get My Courses", description: "Fetch your enrolled Brightspace courses with names, codes, and IDs. Use this when the user asks about their courses, enrolled classes, what they're taking this semester, or needs a course ID for other queries.", inputSchema: GetMyCoursesSchema, }, async (args: any) => { try { log("DEBUG", "get_my_courses tool called", { args }); // Parse and validate input const { activeOnly } = GetMyCoursesSchema.parse(args); // Build path - orgUnitTypeId=3 means "Course Offering" type const path = apiClient.lp( `/enrollments/myenrollments/?orgUnitTypeId=3${activeOnly ? "&isActive=true" : ""}` ); // Fetch enrollments const response = await apiClient.get<EnrollmentResponse>(path, { ttl: DEFAULT_CACHE_TTLS.enrollments, }); // Check for pagination if (response.PagingInfo?.HasMoreItems) { log( "WARN", "get_my_courses: Pagination detected but not implemented. Some courses may be missing.", { hasMore: true } ); } // Map to clean objects and apply course filter const courses = applyCourseFilter( response.Items.map((item) => ({ id: item.OrgUnit.Id, name: item.OrgUnit.Name, code: item.OrgUnit.Code, role: item.Access.ClasslistRoleName, isActive: item.Access.IsActive, lastAccessed: item.Access.LastAccessed, })), config.courseFilter ); log("INFO", `get_my_courses: Retrieved ${courses.length} courses`); return toolResponse(courses); } catch (error) { return sanitizeError(error); } } ); } - src/tools/schemas.ts:15-17 (schema)Zod schema definition for GetMyCoursesSchema, defining activeOnly as an optional boolean parameter defaulting to true.
export const GetMyCoursesSchema = z.object({ activeOnly: z.boolean().default(true).describe("Only return currently active courses"), }); - src/index.ts:179-179 (registration)Registration call in main index.ts where registerGetMyCourses is invoked with server, apiClient, and config.
registerGetMyCourses(server, apiClient, config); - src/tools/index.ts:8-8 (registration)Barrel export re-exporting registerGetMyCourses from get-my-courses.js.
export { registerGetMyCourses } from "./get-my-courses.js"; - src/index.ts:21-22 (registration)Import of registerGetMyCourses in main index.ts.
registerGetMyCourses, registerGetUpcomingDueDates,