canvas_list_active_courses
Retrieve your currently active Canvas courses using the dashboard API for faster access to current semester classes.
Instructions
Lists only your active/current courses using the dashboard API. Much faster than list_courses.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/list-active-courses.ts:9-42 (handler)The handler function that executes the tool logic: fetches active courses from Canvas dashboard API and returns a formatted text list or error.async () => { try { const dashboardCards = await canvasApiRequest<any[]>(`/dashboard/dashboard_cards`); if (dashboardCards.length === 0) { return { content: [{ type: "text", text: "No active courses found in your dashboard." }] }; } const courseList = dashboardCards.map((card) => { const termName = card.term ? `(${card.term})` : ''; return `- ID: ${card.id} | ${card.shortName} ${termName}`; }).join('\n'); return { content: [{ type: "text", text: `Your active courses:\n\n${courseList}` }] }; } catch (error) { return { content: [{ type: "text", text: `Failed to fetch active courses: ${(error as Error).message}` }], isError: true }; } }
- src/tools/list-active-courses.ts:5-43 (registration)The server.tool() registration of the canvas_list_active_courses tool, including name, description, empty input schema, and handler reference.server.tool( "canvas_list_active_courses", "Lists only your active/current courses using the dashboard API. Much faster than list_courses.", {}, async () => { try { const dashboardCards = await canvasApiRequest<any[]>(`/dashboard/dashboard_cards`); if (dashboardCards.length === 0) { return { content: [{ type: "text", text: "No active courses found in your dashboard." }] }; } const courseList = dashboardCards.map((card) => { const termName = card.term ? `(${card.term})` : ''; return `- ID: ${card.id} | ${card.shortName} ${termName}`; }).join('\n'); return { content: [{ type: "text", text: `Your active courses:\n\n${courseList}` }] }; } catch (error) { return { content: [{ type: "text", text: `Failed to fetch active courses: ${(error as Error).message}` }], isError: true }; } } );
- src/index.ts:25-25 (registration)The call to register the tool on the main MCP server instance in the entrypoint file.registerListActiveCoursesTool(server);
- src/api/canvas-client.ts:16-37 (helper)Supporting utility function canvasApiRequest used by the handler to perform authenticated GET/POST requests to the Canvas API.export async function canvasApiRequest<T>(path: string, method = 'GET', body?: any): Promise<T> { if (!canvasApiToken) { throw new Error("Canvas API token not set. Please check CANVAS_API_TOKEN environment variable."); } const url = `${getBaseUrl()}${path}`; const response = await fetch(url, { method, headers: { 'Authorization': `Bearer ${canvasApiToken}`, 'Content-Type': 'application/json', }, body: body ? JSON.stringify(body) : undefined, }); if (!response.ok) { const error = await response.text(); throw new Error(`Canvas API error: ${response.status} - ${error}`); } return response.json() as Promise<T>; }