Skip to main content
Glama
brendan-ch

Canvas Assignment Assistant

by brendan-ch

get_assignment

Retrieve detailed Canvas assignment information including descriptions, submission requirements, and embedded links using course and assignment IDs.

Instructions

Retrieves detailed information about a specific assignment, including its description, submission requirements, and embedded links.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
courseIdYesCourse ID
assignmentIdYesAssignment ID
formatTypeNoFormat type: full (HTML), plain (text only), or markdown (formatted)markdown

Implementation Reference

  • The main handler function that fetches the assignment from the Canvas API, processes its description according to the specified format, extracts links, and builds a comprehensive Markdown response including details like due date, submission types, rubric, and special requirements.
    async ({ courseId, assignmentId, formatType }) => {
      try {
        const assignment = await canvasApiRequest<CanvasAssignment>(`/courses/${courseId}/assignments/${assignmentId}`);
    
        let description: string;
        let links: { text: string; href: string }[] = [];
    
        if (assignment.description) {
          links = extractLinks(assignment.description);
        }
    
        switch (formatType) {
          case 'full':
            description = assignment.description || 'No description available';
            break;
          case 'plain':
            description = htmlToPlainText(assignment.description) || 'No description available';
            break;
          case 'markdown':
          default:
            description = assignment.description ?
              convertHtmlToMarkdown(assignment.description) :
              'No description available';
            break;
        }
    
        const details = [
          `# ${assignment.name}`,
          ``,
          `**Course ID:** ${courseId}`,
          `**Assignment ID:** ${assignment.id}`,
          `**Due Date:** ${formatDate(assignment.due_at)}`,
          `**Points Possible:** ${assignment.points_possible}`,
          `**Status:** ${assignment.published ? 'Published' : 'Unpublished'}${assignment.only_visible_to_overrides ? ' (Only visible to specific students)' : ''}`,
          ``,
          `## Submission Requirements`,
          `- **Submission Type:** ${assignment.submission_types?.join(', ') || 'Not specified'}`,
        ];
    
        // Add allowed file extensions if relevant
        if (assignment.submission_types?.includes('online_upload') && assignment.allowed_extensions?.length) {
          details.push(`- **Allowed File Types:** ${assignment.allowed_extensions.map(ext => `\`.${ext}\``).join(', ')}`);
        }
    
        // Add attempt limits if specified
        if (assignment.allowed_attempts !== null && assignment.allowed_attempts !== -1) {
          details.push(`- **Allowed Attempts:** ${assignment.allowed_attempts}`);
        }
    
        // Add grading type info
        details.push(`- **Grading Type:** ${assignment.grading_type.replace(/_/g, ' ').toLowerCase()}`);
    
        // Add time restrictions if any
        if (assignment.unlock_at || assignment.lock_at) {
          details.push(`- **Time Restrictions:**`);
          if (assignment.unlock_at) {
            details.push(`  - Available from: ${formatDate(assignment.unlock_at)}`);
          }
          if (assignment.lock_at) {
            details.push(`  - Locks at: ${formatDate(assignment.lock_at)}`);
          }
        }
    
        // Add group assignment info if relevant
        if (assignment.has_group_assignment) {
          details.push(`- **Group Assignment:** Yes`);
        }
    
        // Add peer review info if enabled
        if (assignment.peer_reviews) {
          details.push(`- **Peer Reviews Required:** Yes`);
        }
    
        // Add word count requirement if specified
        if (assignment.word_count) {
          details.push(`- **Required Word Count:** ${assignment.word_count}`);
        }
    
        // Add external tool info if present
        if (assignment.external_tool_tag_attributes?.url) {
          details.push(`- **External Tool Required:** Yes`);
          details.push(`  - Tool URL: ${assignment.external_tool_tag_attributes.url}`);
          if (assignment.external_tool_tag_attributes.new_tab) {
            details.push(`  - Opens in new tab: Yes`);
          }
        }
    
        // Add plagiarism detection info
        if (assignment.turnitin_enabled || assignment.vericite_enabled) {
          details.push(`- **Plagiarism Detection:**`);
          if (assignment.turnitin_enabled) details.push(`  - Turnitin enabled`);
          if (assignment.vericite_enabled) details.push(`  - VeriCite enabled`);
        }
    
        // Add rubric information if available
        if (assignment.rubric && assignment.rubric.length > 0) {
          details.push('', '## Rubric');
          if (assignment.use_rubric_for_grading) {
            details.push('*This rubric is used for grading*', '');
          }
          assignment.rubric.forEach(criterion => {
            details.push(`### ${criterion.description} (${criterion.points} points)`);
            if (criterion.long_description) {
              details.push(criterion.long_description);
            }
            details.push('');
          });
        }
    
        // Add special requirements
        const specialReqs = [];
        if (assignment.anonymize_students) specialReqs.push('Anonymous Grading Enabled');
        if (assignment.require_lockdown_browser) specialReqs.push('Lockdown Browser Required');
        if (assignment.annotatable_attachment_id) specialReqs.push('Annotation Required');
        if (specialReqs.length > 0) {
          details.push('', '## Special Requirements', '');
          specialReqs.forEach(req => details.push(`- ${req}`));
        }
    
        // Add lock status if relevant
        if (assignment.locked_for_user) {
          details.push('', '## Access Restrictions', '');
          details.push(assignment.lock_explanation || 'This assignment is currently locked.');
        }
    
        details.push(
          ``,
          `## Description`,
          ``,
          description
        );
    
        // Add links section if any links were found
        if (links.length > 0) {
          details.push('', '## Required Materials and Links', '');
          links.forEach(link => {
            details.push(`- [${link.text}](${link.href})`);
          });
        }
    
        return {
          content: [{
            type: "text",
            text: details.join('\n')
          }]
        };
      } catch (error) {
        return {
          content: [{
            type: "text",
            text: `Failed to fetch assignment details: ${(error as Error).message}`
          }],
          isError: true
        };
      }
    }
  • Zod schema defining the input parameters for the get_assignment tool: courseId, assignmentId, and optional formatType.
    {
      courseId: z.string().or(z.number()).describe("Course ID"),
      assignmentId: z.string().or(z.number()).describe("Assignment ID"),
      formatType: z.enum(['full', 'plain', 'markdown']).default('markdown')
        .describe("Format type: full (HTML), plain (text only), or markdown (formatted)"),
    },
  • Registers the 'get_assignment' tool on the MCP server using server.tool(), providing name, description, input schema, and handler function.
    export function registerGetAssignmentTool(server: McpServer) {
      server.tool(
        "get_assignment",
        "Retrieves detailed information about a specific assignment, including its description, submission requirements, and embedded links.",
        {
          courseId: z.string().or(z.number()).describe("Course ID"),
          assignmentId: z.string().or(z.number()).describe("Assignment ID"),
          formatType: z.enum(['full', 'plain', 'markdown']).default('markdown')
            .describe("Format type: full (HTML), plain (text only), or markdown (formatted)"),
        },
        async ({ courseId, assignmentId, formatType }) => {
          try {
            const assignment = await canvasApiRequest<CanvasAssignment>(`/courses/${courseId}/assignments/${assignmentId}`);
    
            let description: string;
            let links: { text: string; href: string }[] = [];
    
            if (assignment.description) {
              links = extractLinks(assignment.description);
            }
    
            switch (formatType) {
              case 'full':
                description = assignment.description || 'No description available';
                break;
              case 'plain':
                description = htmlToPlainText(assignment.description) || 'No description available';
                break;
              case 'markdown':
              default:
                description = assignment.description ?
                  convertHtmlToMarkdown(assignment.description) :
                  'No description available';
                break;
            }
    
            const details = [
              `# ${assignment.name}`,
              ``,
              `**Course ID:** ${courseId}`,
              `**Assignment ID:** ${assignment.id}`,
              `**Due Date:** ${formatDate(assignment.due_at)}`,
              `**Points Possible:** ${assignment.points_possible}`,
              `**Status:** ${assignment.published ? 'Published' : 'Unpublished'}${assignment.only_visible_to_overrides ? ' (Only visible to specific students)' : ''}`,
              ``,
              `## Submission Requirements`,
              `- **Submission Type:** ${assignment.submission_types?.join(', ') || 'Not specified'}`,
            ];
    
            // Add allowed file extensions if relevant
            if (assignment.submission_types?.includes('online_upload') && assignment.allowed_extensions?.length) {
              details.push(`- **Allowed File Types:** ${assignment.allowed_extensions.map(ext => `\`.${ext}\``).join(', ')}`);
            }
    
            // Add attempt limits if specified
            if (assignment.allowed_attempts !== null && assignment.allowed_attempts !== -1) {
              details.push(`- **Allowed Attempts:** ${assignment.allowed_attempts}`);
            }
    
            // Add grading type info
            details.push(`- **Grading Type:** ${assignment.grading_type.replace(/_/g, ' ').toLowerCase()}`);
    
            // Add time restrictions if any
            if (assignment.unlock_at || assignment.lock_at) {
              details.push(`- **Time Restrictions:**`);
              if (assignment.unlock_at) {
                details.push(`  - Available from: ${formatDate(assignment.unlock_at)}`);
              }
              if (assignment.lock_at) {
                details.push(`  - Locks at: ${formatDate(assignment.lock_at)}`);
              }
            }
    
            // Add group assignment info if relevant
            if (assignment.has_group_assignment) {
              details.push(`- **Group Assignment:** Yes`);
            }
    
            // Add peer review info if enabled
            if (assignment.peer_reviews) {
              details.push(`- **Peer Reviews Required:** Yes`);
            }
    
            // Add word count requirement if specified
            if (assignment.word_count) {
              details.push(`- **Required Word Count:** ${assignment.word_count}`);
            }
    
            // Add external tool info if present
            if (assignment.external_tool_tag_attributes?.url) {
              details.push(`- **External Tool Required:** Yes`);
              details.push(`  - Tool URL: ${assignment.external_tool_tag_attributes.url}`);
              if (assignment.external_tool_tag_attributes.new_tab) {
                details.push(`  - Opens in new tab: Yes`);
              }
            }
    
            // Add plagiarism detection info
            if (assignment.turnitin_enabled || assignment.vericite_enabled) {
              details.push(`- **Plagiarism Detection:**`);
              if (assignment.turnitin_enabled) details.push(`  - Turnitin enabled`);
              if (assignment.vericite_enabled) details.push(`  - VeriCite enabled`);
            }
    
            // Add rubric information if available
            if (assignment.rubric && assignment.rubric.length > 0) {
              details.push('', '## Rubric');
              if (assignment.use_rubric_for_grading) {
                details.push('*This rubric is used for grading*', '');
              }
              assignment.rubric.forEach(criterion => {
                details.push(`### ${criterion.description} (${criterion.points} points)`);
                if (criterion.long_description) {
                  details.push(criterion.long_description);
                }
                details.push('');
              });
            }
    
            // Add special requirements
            const specialReqs = [];
            if (assignment.anonymize_students) specialReqs.push('Anonymous Grading Enabled');
            if (assignment.require_lockdown_browser) specialReqs.push('Lockdown Browser Required');
            if (assignment.annotatable_attachment_id) specialReqs.push('Annotation Required');
            if (specialReqs.length > 0) {
              details.push('', '## Special Requirements', '');
              specialReqs.forEach(req => details.push(`- ${req}`));
            }
    
            // Add lock status if relevant
            if (assignment.locked_for_user) {
              details.push('', '## Access Restrictions', '');
              details.push(assignment.lock_explanation || 'This assignment is currently locked.');
            }
    
            details.push(
              ``,
              `## Description`,
              ``,
              description
            );
    
            // Add links section if any links were found
            if (links.length > 0) {
              details.push('', '## Required Materials and Links', '');
              links.forEach(link => {
                details.push(`- [${link.text}](${link.href})`);
              });
            }
    
            return {
              content: [{
                type: "text",
                text: details.join('\n')
              }]
            };
          } catch (error) {
            return {
              content: [{
                type: "text",
                text: `Failed to fetch assignment details: ${(error as Error).message}`
              }],
              isError: true
            };
          }
        }
      );
    }
  • src/index.ts:27-27 (registration)
    Top-level registration call that invokes registerGetAssignmentTool on the main server instance to enable the tool.
    registerGetAssignmentTool(server);
Behavior3/5

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

No annotations are provided, so the description carries the full burden. It discloses that the tool retrieves information (implying read-only behavior) and specifies the types of details returned. However, it doesn't mention potential errors (e.g., invalid IDs), authentication needs, rate limits, or response format, leaving gaps in behavioral context.

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 a single, efficient sentence that front-loads the core purpose and lists key details without unnecessary words. Every part earns its place by specifying what is retrieved, making it highly concise and well-structured.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations and no output schema, the description provides basic context but is incomplete. It covers the purpose and output content but lacks details on error handling, authentication, or return structure. For a read tool with full schema coverage, this is minimally adequate but has clear gaps.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all parameters thoroughly. The description doesn't add any meaning beyond what the schema provides (e.g., it doesn't explain how 'formatType' affects the output or provide examples). Baseline 3 is appropriate as the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('retrieves') and resource ('specific assignment') with specific details about what information is included ('description, submission requirements, and embedded links'). It distinguishes from the sibling 'search_assignments' by focusing on a single assignment rather than searching multiple, though it doesn't explicitly mention this distinction.

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

Usage Guidelines3/5

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

The description implies usage for retrieving detailed information about a specific assignment, but it doesn't explicitly state when to use this tool versus alternatives like 'search_assignments' or provide any exclusions. The context is clear but lacks explicit guidance on tool selection.

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/brendan-ch/canvas-mcp'

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