Skip to main content
Glama
brendan-ch

Canvas Assignment Assistant

by brendan-ch

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
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • 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
        };
      }
    }
  • 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);
  • 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>;
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/brendan-ch/canvas-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server