Skip to main content
Glama

bulk_delete_announcements

Delete multiple announcements from a Canvas course simultaneously, with options to handle errors during batch processing.

Instructions

    Delete multiple announcements from a Canvas course.

    Args:
        course_identifier: The Canvas course code or ID
        announcement_ids: List of announcement IDs to delete
        stop_on_error: If True, stop processing on first error; if False, continue with remaining

    Returns:
        String with detailed results including successful and failed deletions

    Example usage:
        results = bulk_delete_announcements(
            "60366",
            ["925355", "925354", "925353"],
            stop_on_error=False
        )
    

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
course_identifierYes
announcement_idsYes
stop_on_errorNo

Implementation Reference

  • The main handler function implementing the bulk_delete_announcements MCP tool. It iterates over a list of announcement IDs, fetches details, deletes each via Canvas API, tracks successes and failures, and returns a formatted summary.
    @mcp.tool()
    @validate_params
    async def bulk_delete_announcements(
        course_identifier: str | int,
        announcement_ids: list[str | int],
        stop_on_error: bool = False
    ) -> str:
        """
        Delete multiple announcements from a Canvas course.
    
        Args:
            course_identifier: The Canvas course code or ID
            announcement_ids: List of announcement IDs to delete
            stop_on_error: If True, stop processing on first error; if False, continue with remaining
    
        Returns:
            String with detailed results including successful and failed deletions
    
        Example usage:
            results = bulk_delete_announcements(
                "60366",
                ["925355", "925354", "925353"],
                stop_on_error=False
            )
        """
        course_id = await get_course_id(course_identifier)
    
        successful = []
        failed = []
    
        for announcement_id in announcement_ids:
            try:
                # Get announcement details first
                announcement = await make_canvas_request(
                    "get", f"/courses/{course_id}/discussion_topics/{announcement_id}"
                )
    
                if "error" in announcement:
                    failed.append({
                        "id": str(announcement_id),
                        "error": announcement["error"],
                        "message": "Failed to fetch announcement details"
                    })
                    if stop_on_error:
                        break
                    continue
    
                # Proceed with deletion
                response = await make_canvas_request(
                    "delete", f"/courses/{course_id}/discussion_topics/{announcement_id}"
                )
    
                if "error" in response:
                    failed.append({
                        "id": str(announcement_id),
                        "title": announcement.get("title", "Unknown Title"),
                        "error": response["error"],
                        "message": "Failed to delete announcement"
                    })
                    if stop_on_error:
                        break
                else:
                    successful.append({
                        "id": str(announcement_id),
                        "title": announcement.get("title", "Unknown Title")
                    })
    
            except Exception as e:
                failed.append({
                    "id": str(announcement_id),
                    "error": str(e),
                    "message": "Unexpected error during deletion"
                })
                if stop_on_error:
                    break
    
        # Format results
        summary = {
            "total": len(announcement_ids),
            "successful": len(successful),
            "failed": len(failed)
        }
    
        course_display = await get_course_code(course_id) or course_identifier
        result = f"Bulk deletion results for course {course_display}:\n\n"
        result += f"Summary: {summary['successful']} successful, {summary['failed']} failed out of {summary['total']} total\n\n"
    
        if successful:
            result += "Successfully deleted:\n"
            for item in successful:
                result += f"  - ID: {item['id']}, Title: {item['title']}\n"
            result += "\n"
    
        if failed:
            result += "Failed to delete:\n"
            for item in failed:
                result += f"  - ID: {item['id']}"
                if 'title' in item:
                    result += f", Title: {item['title']}"
                result += f", Error: {item['error']}\n"
    
        return result
  • Registration of discussion tools (including bulk_delete_announcements) in the main server setup.
    register_course_tools(mcp)
    register_assignment_tools(mcp)
    register_discussion_tools(mcp)
    register_other_tools(mcp)
    register_rubric_tools(mcp)
    register_peer_review_tools(mcp)
    register_peer_review_comment_tools(mcp)
    register_messaging_tools(mcp)
    register_student_tools(mcp)
    register_accessibility_tools(mcp)
    register_discovery_tools(mcp)
    register_code_execution_tools(mcp)
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