Skip to main content
Glama

list_modules

Read-only

Retrieve all modules for a Canvas course, with optional inclusion of module items and filtering by name.

Instructions

List all modules in a course.

    Args:
        course_identifier: Course code or Canvas ID
        include_items: Include summary of items in each module
        search_term: Filter modules by name
    

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
course_identifierYes
include_itemsNo
search_termNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The async function `list_modules` that implements the tool logic. It takes a course_identifier (str or int), optional include_items flag, and optional search_term, fetches modules from the Canvas API, formats them into a human-readable string with details like name, position, state, items count, unlock date, prerequisites, and optionally lists up to 5 items per module.
    async def list_modules(
        course_identifier: str | int,
        include_items: bool = False,
        search_term: str | None = None
    ) -> str:
        """List all modules in a course.
    
        Args:
            course_identifier: Course code or Canvas ID
            include_items: Include summary of items in each module
            search_term: Filter modules by name
        """
        course_id = await get_course_id(course_identifier)
    
        params = {"per_page": 100}
        if include_items:
            params["include[]"] = ["items"]
        if search_term:
            params["search_term"] = search_term
    
        modules = await fetch_all_paginated_results(
            f"/courses/{course_id}/modules", params
        )
    
        if isinstance(modules, dict) and "error" in modules:
            return f"Error fetching modules: {modules['error']}"
    
        if not modules:
            return "No modules found in course."
    
        course_display = await get_course_code(course_id) or course_identifier
        result = f"Modules in {course_display}:\n\n"
    
        for module in modules:
            module_id = module.get("id")
            name = module.get("name", "Unnamed")
            position = module.get("position", 0)
            state = module.get("state", "unknown")
            published = module.get("published", False)
            items_count = module.get("items_count", 0)
            unlock_at = module.get("unlock_at")
            require_sequential = module.get("require_sequential_progress", False)
            prerequisite_ids = module.get("prerequisite_module_ids", [])
    
            result += f"**{name}**\n"
            result += f"  ID: {module_id}\n"
            result += f"  Position: {position}\n"
            result += f"  Status: {state} | Published: {'Yes' if published else 'No'}\n"
            result += f"  Items: {items_count}\n"
    
            if unlock_at:
                result += f"  Unlocks: {format_date(unlock_at)}\n"
            if require_sequential:
                result += "  Sequential Progress: Required\n"
            if prerequisite_ids:
                result += f"  Prerequisites: {prerequisite_ids}\n"
    
            # Include item summary if requested
            if include_items and "items" in module:
                items = module.get("items", [])
                if items:
                    result += "  Items:\n"
                    for item in items[:5]:  # Show first 5 items
                        item_title = item.get("title", "Untitled")
                        item_type = item.get("type", "Unknown")
                        result += f"    - {item_title} ({item_type})\n"
                    if len(items) > 5:
                        result += f"    ... and {len(items) - 5} more items\n"
    
            result += "\n"
    
        return result
  • The `register_shared_module_tools` function that registers the tool via `@mcp.tool` decorator on the `list_modules` function, making it accessible to both students and educators.
    def register_shared_module_tools(mcp: FastMCP):
        """Register module tools accessible to both students and educators."""
    
        @mcp.tool(annotations=ToolAnnotations(readOnlyHint=True))
        @validate_params
  • The function signature serves as the schema/type definition: parameters include course_identifier (str|int), include_items (bool, default False), and search_term (str|None). The return type is str.
    async def list_modules(
        course_identifier: str | int,
        include_items: bool = False,
        search_term: str | None = None
    ) -> str:
  • Imported helper functions used by list_modules: get_course_id (to resolve course identifier), fetch_all_paginated_results (to paginate API calls), get_course_code (for display), format_date (for date formatting), and validate_params (decorator for parameter validation).
    from ..core.cache import get_course_code, get_course_id
    from ..core.client import fetch_all_paginated_results, make_canvas_request
    from ..core.dates import format_date, parse_date
    from ..core.validation import validate_params
    
    
    def register_shared_module_tools(mcp: FastMCP):
        """Register module tools accessible to both students and educators."""
    
        @mcp.tool(annotations=ToolAnnotations(readOnlyHint=True))
        @validate_params
        async def list_modules(
            course_identifier: str | int,
            include_items: bool = False,
            search_term: str | None = None
        ) -> str:
            """List all modules in a course.
    
            Args:
                course_identifier: Course code or Canvas ID
                include_items: Include summary of items in each module
                search_term: Filter modules by name
            """
            course_id = await get_course_id(course_identifier)
    
            params = {"per_page": 100}
            if include_items:
                params["include[]"] = ["items"]
            if search_term:
                params["search_term"] = search_term
    
            modules = await fetch_all_paginated_results(
                f"/courses/{course_id}/modules", params
            )
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already provide readOnlyHint=true. The description adds no further behavioral details beyond what the annotation and schema cover.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Concise one-line purpose followed by parameter list. No fluff, front-loaded.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Covers purpose and all parameters. Has output schema, so return details are handled. Minor omission: no mention of pagination or ordering, but adequate for a list tool.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0% schema description coverage, the description compensates by explaining each parameter's purpose (e.g., 'Course code or Canvas ID', 'Include summary of items'). Adds value beyond schema titles.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Clearly states 'List all modules in a course,' specifying the verb and resource. Distinguishes from sibling tools like create_module, delete_module, etc.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies use for listing modules, and parameters clarify filtering options. However, it does not explicitly state when to prefer this over alternatives like list_module_items or get_course_structure.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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