Get Classlist Emails
get_classlist_emailsFetch all email addresses for a course—instructors, TAs, and students—to enable direct communication with the entire class.
Instructions
Fetch all email addresses for everyone in a course — instructors, TAs, and students. Use this when the user wants a list of emails for a class, needs to email the whole class, or wants contact info for everyone enrolled.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| courseId | Yes | Course ID to get emails for. |
Implementation Reference
- src/tools/get-classlist-emails.ts:28-78 (handler)The main handler function that registers and implements the 'get_classlist_emails' tool. It takes a courseId, fetches the classlist via the D2L API, extracts emails (filtering out nulls for privacy-hidden users), and returns the list of emails with name, email, and role.
export function registerGetClasslistEmails( server: McpServer, apiClient: D2LApiClient ): void { server.registerTool( "get_classlist_emails", { title: "Get Classlist Emails", description: "Fetch all email addresses for everyone in a course — instructors, TAs, and students. " + "Use this when the user wants a list of emails for a class, needs to email the whole class, " + "or wants contact info for everyone enrolled.", inputSchema: GetClasslistEmailsSchema, }, async (args: any) => { try { log("DEBUG", "get_classlist_emails tool called", { args }); const { courseId } = GetClasslistEmailsSchema.parse(args); // Fetch full classlist (all roles) using paged endpoint const path = apiClient.le(courseId, "/classlist/paged/"); const response = await apiClient.get<ClasslistResponse>(path, { ttl: DEFAULT_CACHE_TTLS.roster, }); if (response.Next) { log( "WARN", "get_classlist_emails: Pagination detected but not implemented. Some users may be missing.", { courseId, next: response.Next } ); } // Extract emails, filtering out nulls (privacy-hidden) const emails = response.Objects .filter((user) => user.Email) .map((user) => ({ name: user.DisplayName, email: user.Email, role: user.ClasslistRoleDisplayName, })); log("INFO", `get_classlist_emails: ${emails.length} emails from ${response.Objects.length} users in course ${courseId}`); return toolResponse(emails); } catch (error) { return sanitizeError(error); } } ); } - src/tools/schemas.ts:49-52 (schema)Input schema for get_classlist_emails — validates that courseId is a positive integer.
export const GetClasslistEmailsSchema = z.object({ courseId: z.coerce.number().int().positive() .describe("Course ID to get emails for."), }); - src/index.ts:186-186 (registration)Where the tool is registered on the server — calls registerGetClasslistEmails(server, apiClient) in the main index.
registerGetClasslistEmails(server, apiClient); - src/tools/index.ts:15-15 (registration)Barrel export re-exporting the registerGetClasslistEmails function from the tools module.
export { registerGetClasslistEmails } from "./get-classlist-emails.js";