Skip to main content
Glama

list_courses

Retrieve a list of Canvas LMS courses for the authenticated user, with options to include concluded courses or all available courses.

Instructions

List courses for the authenticated user.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
include_allNo
include_concludedNo

Implementation Reference

  • The core handler function for the 'list_courses' MCP tool. It is decorated with @mcp.tool() for automatic registration, fetches courses from the Canvas API with optional filters for concluded courses and enrollment types, updates course code/ID caches, and returns a formatted list of courses emphasizing course codes.
    @mcp.tool() async def list_courses(include_concluded: bool = False, include_all: bool = False) -> str: """List courses for the authenticated user.""" params = { "include[]": ["term", "teachers", "total_students"], "per_page": 100 } if not include_all: params["enrollment_type"] = "teacher" if include_concluded: params["state[]"] = ["available", "completed"] else: params["state[]"] = ["available"] courses = await fetch_all_paginated_results("/courses", params) if isinstance(courses, dict) and "error" in courses: return f"Error fetching courses: {courses['error']}" if not courses: return "No courses found." # Refresh our caches with the course data for course in courses: course_id = str(course.get("id")) course_code = course.get("course_code") if course_code and course_id: course_code_to_id_cache[course_code] = course_id id_to_course_code_cache[course_id] = course_code courses_info = [] for course in courses: course_id = course.get("id") name = course.get("name", "Unnamed course") code = course.get("course_code", "No code") # Emphasize code in the output courses_info.append(f"Code: {code}\nName: {name}\nID: {course_id}\n") return "Courses:\n\n" + "\n".join(courses_info)
  • The call to register_course_tools(mcp) in the register_all_tools function, which triggers the definition and registration of the list_courses tool (and other course tools).
    register_course_tools(mcp)
  • TypeScript helper function listCourses() that performs paginated fetch of courses from Canvas API. This is importable and usable within the execute_typescript code_execution tool for token-efficient operations.
    import { fetchAllPaginated } from "../../client.js"; export interface Course { id: number; name: string; course_code: string; workflow_state: string; start_at?: string; end_at?: string; enrollment_term_id?: number; } /** * List all courses for the current user. * * Returns courses where the user is enrolled as a teacher or student. * Useful for discovering course identifiers before performing other operations. */ export async function listCourses(): Promise<Course[]> { return fetchAllPaginated<Course>('/courses', { per_page: 100 }); }

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/vishalsachdev/canvas-mcp'

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