Skip to main content
Glama

delete_announcement_with_confirmation

Remove announcements from Canvas courses with safety checks to prevent accidental deletion. Verify title matches before deleting or test with dry run.

Instructions

Delete an announcement with optional safety checks. Args: course_identifier: The Canvas course code or ID announcement_id: The announcement ID to delete require_title_match: If provided, only delete if the announcement title matches exactly dry_run: If True, verify but don't actually delete (for testing) Returns: String with operation result including status and title match information Raises: ValueError: If require_title_match is provided and doesn't match the actual title Example usage: # Delete only if title matches exactly (safety check) result = delete_announcement_with_confirmation( "60366", "925355", require_title_match="Preparing for the week", dry_run=False )

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
course_identifierYes
announcement_idYes
require_title_matchNo
dry_runNo

Implementation Reference

  • Implementation of the delete_announcement_with_confirmation tool handler. Deletes a Canvas announcement (discussion topic with is_announcement=true) after fetching details, optional title match confirmation, and dry-run support. Uses Canvas API DELETE /courses/{course_id}/discussion_topics/{announcement_id}.
    @mcp.tool() @validate_params async def delete_announcement_with_confirmation( course_identifier: str | int, announcement_id: str | int, require_title_match: str | None = None, dry_run: bool = False ) -> str: """ Delete an announcement with optional safety checks. Args: course_identifier: The Canvas course code or ID announcement_id: The announcement ID to delete require_title_match: If provided, only delete if the announcement title matches exactly dry_run: If True, verify but don't actually delete (for testing) Returns: String with operation result including status and title match information Raises: ValueError: If require_title_match is provided and doesn't match the actual title Example usage: # Delete only if title matches exactly (safety check) result = delete_announcement_with_confirmation( "60366", "925355", require_title_match="Preparing for the week", dry_run=False ) """ course_id = await get_course_id(course_identifier) # First fetch the announcement details announcement = await make_canvas_request( "get", f"/courses/{course_id}/discussion_topics/{announcement_id}" ) if "error" in announcement: return f"Error fetching announcement details: {announcement['error']}" actual_title = announcement.get("title", "Unknown Title") title_matched = True # Check title match if required if require_title_match is not None: title_matched = actual_title == require_title_match if not title_matched: return f"Title mismatch - Expected: '{require_title_match}', Actual: '{actual_title}'. Deletion aborted for safety." # Handle dry run if dry_run: course_display = await get_course_code(course_id) or course_identifier result = f"DRY RUN - Would delete announcement from course {course_display}:\n\n" result += f"ID: {announcement_id}\n" result += f"Title: {actual_title}\n" result += "Status: dry_run\n" result += "Message: Announcement would be deleted (dry run mode)\n" if require_title_match: result += f"Title matched: {title_matched}\n" return result # Proceed with actual deletion response = await make_canvas_request( "delete", f"/courses/{course_id}/discussion_topics/{announcement_id}" ) if "error" in response: return f"Error deleting announcement '{actual_title}': {response['error']}" course_display = await get_course_code(course_id) or course_identifier result = f"Announcement deleted successfully from course {course_display}:\n\n" result += f"ID: {announcement_id}\n" result += f"Title: {actual_title}\n" result += "Status: deleted\n" result += "Message: Announcement deleted successfully\n" if require_title_match: result += f"Title matched: {title_matched}\n" return result
  • Call to register_discussion_tools(mcp) in register_all_tools function, which registers all discussion and announcement tools including delete_announcement_with_confirmation.
    register_discussion_tools(mcp)
  • Import of register_discussion_tools from .tools in server.py.
    register_discussion_tools,
  • Import of register_discussion_tools from discussions.py in tools/__init__.py, making it available for server.py.
    from .discussions import register_discussion_tools
  • Type definition for AnnouncementInfo used in Canvas API responses for announcements/discussion topics.
    class AnnouncementInfo(TypedDict, total=False): id: int | str title: str message: str posted_at: str | None delayed_post_at: str | None lock_at: str | None published: bool is_announcement: bool
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