Skip to main content
Glama

tool_prepare_answer_key

Extract all assignment questions, answers, and explanations to create a complete answer key for grading preparation in Gradescope.

Instructions

Prepare a complete answer key for an entire assignment.

Extracts ALL questions from the outline (prompt text, reference answers,
explanations) and saves to /tmp/gradescope-answerkey-{assignment_id}.md.
Run this ONCE before grading to avoid re-fetching question details.

Args:
    course_id: The Gradescope course ID.
    assignment_id: The assignment ID.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
course_idYes
assignment_idYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The actual implementation of the tool logic that prepares the answer key.
    def prepare_answer_key(course_id: str, assignment_id: str) -> str:
        """Prepare a complete answer key for an entire assignment.
    
        Extracts ALL questions from the assignment outline, including:
        - Question numbers, types, and weights
        - Prompt/question text (if available in structured data)
        - Explanation/reference answers (if provided by the instructor)
        - For questions without reference answers, generates a rubric-based draft
    
        Saves the result to /tmp/gradescope-answerkey-{assignment_id}.md.
        This file can then be referenced when grading individual submissions,
        saving context by not having to re-fetch question details each time.
    
        Args:
            course_id: The Gradescope course ID.
            assignment_id: The assignment ID.
        """
        if not course_id or not assignment_id:
            return "Error: course_id and assignment_id are required."
    
        try:
            questions = _fetch_assignment_questions(course_id, assignment_id)
        except AuthError as e:
            return f"Authentication error: {e}"
        except ValueError as e:
            return f"Error: {e}"
        except Exception as e:
            return f"Error preparing answer key: {e}"
    
        # Outline data is optional (scanned exams don't have AssignmentEditor)
        try:
            outline_props = _get_outline_data(course_id, assignment_id)
        except Exception:
            outline_props = {}
    
        outline_questions = outline_props.get("questions", {})
        assignment_info = outline_props.get("assignment", {})
        title = assignment_info.get("title", f"Assignment {assignment_id}")
    
        # Build a sorted list of questions
        question_list = []
        for qid, q in questions.items():
            parent_id = q.get("parent_id")
            q_data = {
                "id": qid,
                "title": q.get("title", ""),
                "weight": q.get("weight", 0),
                "type": q.get("type", "Unknown"),
                "parent_id": parent_id,
                "index": q.get("index", 0),
            }
    
            # Build label
            if parent_id and str(parent_id) in questions:
                parent = questions[str(parent_id)]
                q_data["label"] = f"Q{parent.get('index', '?')}.{q.get('index', '?')}"
            else:
                q_data["label"] = f"Q{q.get('index', '?')}"
    
            # Extract prompt text and explanation from outline
            outline_q = outline_questions.get(str(qid), {})
            prompt_parts = []
            explanation_parts = []
            for item in outline_q.get("content", []):
                item_type = item.get("type")
  • Registration of the 'tool_prepare_answer_key' tool as an MCP tool, which calls the 'prepare_answer_key' helper function.
    @mcp.tool()
    def tool_prepare_answer_key(course_id: str, assignment_id: str) -> str:
        """Prepare a complete answer key for an entire assignment.
    
        Extracts ALL questions from the outline (prompt text, reference answers,
        explanations) and saves to /tmp/gradescope-answerkey-{assignment_id}.md.
        Run this ONCE before grading to avoid re-fetching question details.
    
        Args:
            course_id: The Gradescope course ID.
            assignment_id: The assignment ID.
        """
        return prepare_answer_key(course_id, assignment_id)
Behavior4/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It clearly describes the tool's action (extracts questions, saves to a specific file path), purpose (to avoid re-fetching), and output location (/tmp/gradescope-answerkey-{assignment_id}.md). However, it doesn't mention potential side effects like file overwriting or error conditions.

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?

The description is efficiently structured with three sentences: purpose statement, detailed action, and usage timing. Every sentence adds value without redundancy. The parameter documentation is clear and directly relevant.

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?

Given the tool has an output schema (which handles return values), no annotations, and only 2 parameters with 0% schema coverage, the description does well by explaining the tool's purpose, behavior, and parameter roles. However, it lacks details on error handling or what happens if the file already exists, which would be helpful for a tool that saves files.

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?

Schema description coverage is 0%, so the description must compensate. It adds meaningful context for both parameters: course_id is described as 'The Gradescope course ID' and assignment_id as 'The assignment ID', which clarifies their roles in locating the specific assignment. However, it doesn't provide format examples or validation rules.

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?

The description clearly states the specific action ('Prepare a complete answer key'), the resource ('entire assignment'), and the scope ('extracts ALL questions from the outline'). It distinguishes itself from siblings like tool_get_assignment_outline (which likely fetches but doesn't process) and tool_grade_answer_group (which grades specific answers rather than preparing a key).

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

Usage Guidelines5/5

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

The description explicitly states when to use this tool ('Run this ONCE before grading to avoid re-fetching question details') and provides a clear timing guideline. It implies this is a preparatory step distinct from actual grading tools like tool_grade_answer_group, though it doesn't name specific alternatives.

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/Yuanpeng-Li/gradescope-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server