list_courses
Retrieve a list of enrolled Canvas courses with details including ID, name, course code, and term. Filter to show only active courses if needed.
Instructions
List enrolled courses. Returns id, name, course_code, term.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| active_only | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- canvas_local_mcp/server.py:51-57 (handler)The tool handler for 'list_courses'. Decorated with @mcp.tool(), it fetches courses from Canvas API /api/v1/courses, optionally filtering by active enrollment state, and returns a list of dicts with id, name, and course_code.
@mcp.tool() def list_courses(active_only: bool = True) -> list[dict]: """List enrolled courses. Returns id, name, course_code, term.""" p = "/api/v1/courses" params = {"enrollment_state": "active"} if active_only else {} cs = _get(p, **params) return [{"id": c["id"], "name": c.get("name"), "course_code": c.get("course_code")} for c in cs] - canvas_local_mcp/server.py:51-52 (registration)The @mcp.tool() decorator registers 'list_courses' as an MCP tool via the FastMCP instance.
@mcp.tool() def list_courses(active_only: bool = True) -> list[dict]: - canvas_local_mcp/server.py:30-49 (helper)The _get helper function that performs paginated HTTP GET requests to the Canvas API, used by list_courses to fetch course data.
def _get(path: str, **params) -> Any: params.setdefault("per_page", 100) url = f"{BASE}{path}" out = [] with httpx.Client(headers=HEAD, timeout=30) as c: while url: r = c.get(url, params=params) r.raise_for_status() data = r.json() if isinstance(data, list): out.extend(data) else: return data url = None params = {} link = r.headers.get("Link", "") for part in link.split(","): if 'rel="next"' in part: url = part[part.find("<")+1:part.find(">")] return out