Skip to main content
Glama

create_student_anonymization_map

Generate a secure CSV file mapping real student data to anonymous IDs for a course, enabling 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
NameRequiredDescriptionDefault
course_identifierYes

Implementation Reference

  • The main handler function for the 'create_student_anonymization_map' tool. It fetches students from a Canvas course, generates anonymous IDs using generate_anonymous_id, and writes a CSV mapping file locally. Decorated with @mcp.tool() for automatic registration.
    @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)}"
  • The register_other_tools(mcp) call within register_all_tools, which defines the nested tool handler and registers it via the @mcp.tool() decorator.
    register_other_tools(mcp)
  • Helper function used by the tool to generate consistent anonymous student IDs from real Canvas user IDs using SHA256 hashing.
    def generate_anonymous_id(real_id: str | int, prefix: str = "Student") -> str: """Generate a consistent anonymous ID for a given real ID. Args: real_id: The real Canvas user ID or identifier prefix: Prefix for the anonymous ID (default: "Student") Returns: Consistent anonymous identifier """ real_id_str = str(real_id) # Check cache first if real_id_str in _anonymization_cache: return _anonymization_cache[real_id_str] # Generate consistent hash-based ID hash_object = hashlib.sha256(real_id_str.encode()) hash_hex = hash_object.hexdigest() # Use first 8 characters for readability anonymous_id = f"{prefix}_{hash_hex[:8]}" # Cache the mapping _anonymization_cache[real_id_str] = anonymous_id return anonymous_id

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