create_student_anonymization_map
Generate a secure CSV file that maps real student data to anonymous IDs for a Canvas course, creating a de-anonymization key for faculty to identify students while maintaining privacy.
Instructions
Create a local CSV file mapping real student data to anonymous IDs for a course.
This tool generates a de-anonymization key that allows faculty to identify students
from their anonymous IDs. The file is saved locally and should be kept secure.
Args:
course_identifier: The Canvas course code (e.g., badm_554_120251_246794) or ID
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| course_identifier | Yes |
Implementation Reference
- The primary handler function for the 'create_student_anonymization_map' tool. Decorated with @mcp.tool() and @validate_params, it fetches students from the Canvas course, generates anonymous IDs, and writes a secure local CSV mapping file.@mcp.tool() @validate_params async def create_student_anonymization_map(course_identifier: str | int) -> str: """Create a local CSV file mapping real student data to anonymous IDs for a course. This tool generates a de-anonymization key that allows faculty to identify students from their anonymous IDs. The file is saved locally and should be kept secure. Args: course_identifier: The Canvas course code (e.g., badm_554_120251_246794) or ID """ import csv from pathlib import Path from ..core.anonymization import generate_anonymous_id course_id = await get_course_id(course_identifier) # Get all students in the course params = { "enrollment_type[]": "student", "include[]": ["email"], "per_page": 100 } students = await fetch_all_paginated_results( f"/courses/{course_id}/users", params ) if isinstance(students, dict) and "error" in students: return f"Error fetching students: {students['error']}" if not students: return f"No students found for course {course_identifier}." # Create local_maps directory if it doesn't exist maps_dir = Path("local_maps") maps_dir.mkdir(exist_ok=True) # Generate filename with course identifier course_display = await get_course_code(course_id) or str(course_identifier) safe_course_name = "".join(c for c in course_display if c.isalnum() or c in ("-", "_")) filename = f"anonymization_map_{safe_course_name}.csv" filepath = maps_dir / filename # Create mapping data mapping_data = [] for student in students: real_id = student.get("id") real_name = student.get("name", "Unknown") real_email = student.get("email", "No email") # Generate the same anonymous ID that would be used by the anonymization system anonymous_id = generate_anonymous_id(real_id, prefix="Student") mapping_data.append({ "real_name": real_name, "real_id": real_id, "real_email": real_email, "anonymous_id": anonymous_id }) # Write to CSV file try: with open(filepath, 'w', newline='', encoding='utf-8') as csvfile: fieldnames = ["real_name", "real_id", "real_email", "anonymous_id"] writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() writer.writerows(mapping_data) result = "β Student anonymization map created successfully!\n\n" result += f"π File location: {filepath}\n" result += f"π₯ Students mapped: {len(mapping_data)}\n" result += f"π« Course: {course_display}\n\n" result += "β οΈ **SECURITY WARNING:**\n" result += "This file contains sensitive student information and should be:\n" result += "β’ Kept secure and not shared\n" result += "β’ Deleted when no longer needed\n" result += "β’ Never committed to version control\n\n" result += "π File format: CSV with columns real_name, real_id, real_email, anonymous_id\n" result += "π Use this file to identify students from their anonymous IDs in tool outputs." return result except Exception as e: return f"Error creating anonymization map: {str(e)}"
- src/canvas_mcp/server.py:50-50 (registration)Top-level registration call within register_all_tools(mcp) that invokes register_other_tools to register this tool along with other tools in the 'other_tools' module.register_other_tools(mcp)