Overview
The Canvas LMS integration allows Maxw AI to:- Import and index course materials for semantic search
- Access assignments, pages, and course content programmatically
- Search across all courses with natural language queries
- Track due dates and assignment details
- Generate study materials from course content
Credential Storage
Canvas API credentials are stored securely in theuser.settings JSONB column in the database. This flexible storage approach allows for easy configuration without schema migrations.
User Settings Schema
Credentials are stored as part of the user settings object:/home/daytona/workspace/source/apps/web/src/db/schema/types.ts:3
The
canvasDomain should be the base domain without protocol (e.g., canvas.university.edu)Document Indexing with Upstash
Maxw AI uses Upstash Search to provide fast semantic search across all Canvas course materials. Documents are indexed, chunked, and stored for efficient retrieval.Indexing Strategy
Fetch Course Data
The system fetches all active courses, assignments, and pages from Canvas API using the stored credentials.
Convert HTML to Markdown
HTML content in
description and body fields is converted to Markdown using Turndown for better readability and indexing.Chunk Large Documents
Documents exceeding 4000 characters are automatically split into smaller chunks while preserving metadata.
Chunking Configuration
Implementation:/home/daytona/workspace/source/apps/web/src/ai/utils/upstash-helpers.ts:14
Document Structure
Each indexed document contains:AI Tools
Maxw AI provides two Canvas-specific tools for the AI agent:searchContent Tool
Implementation:/home/daytona/workspace/source/apps/web/src/ai/tools/canvas/search-content.ts:5
Searches indexed Canvas content using natural language queries.
- Semantic search with reranking enabled
- Returns top 10 most relevant results
- Includes relevance score (0-1)
- Can be called directly or from Python code execution
getClassAssignments Tool
Implementation:/home/daytona/workspace/source/apps/web/src/ai/tools/canvas/get-class-assignments.ts:14
Fetches assignments from Canvas API programmatically. This tool is only callable via Python code execution.
past- Past due assignmentsoverdue- Overdue assignmentsundated- Assignments without due datesungraded- Ungraded submissionsunsubmitted- Not yet submittedupcoming- Due soonfuture- Future assignments
When called without
classId, the tool fetches assignments from ALL courses in parallel and adds _classId and _className fields to each assignment.Importing Course Materials
To update the Canvas search index with the latest course materials: Implementation:/home/daytona/workspace/source/apps/web/src/ai/utils/upstash-helpers.ts:251
Update Process
API Authentication Flow
All Canvas API requests use the stored credentials for authentication: Implementation:/home/daytona/workspace/source/apps/web/src/app/classes/classes-actions.ts:15
Configuration Requirements
Environment Variables
Environment Variables
Database Schema
Database Schema
The
user table must include the settings JSONB column:Canvas API Token
Canvas API Token
Users must generate a Canvas API token:
- Log into Canvas
- Navigate to Account → Settings
- Scroll to “Approved Integrations”
- Click ”+ New Access Token”
- Set purpose and expiration
- Copy the generated token
Error Handling
The Canvas integration returns specific error strings for common failure cases:- “Unauthorized” - User session is invalid or expired
- “Settings not configured” - Canvas credentials are missing from user settings
- String error message - Canvas API returned an error (e.g., invalid token)
Best Practices
- Incremental Indexing: Consider implementing incremental updates instead of re-indexing all content every time.
- Rate Limiting: Canvas API has rate limits. The current implementation uses parallel requests but doesn’t implement explicit rate limiting.
- Caching: Consider caching frequently accessed course data to reduce API calls.
- Token Rotation: Implement token refresh mechanisms for long-lived sessions.
- Error Recovery: Handle partial failures gracefully when processing multiple courses.
Related Components
- Upstash Search Client: Configured in
upstash-helpers.ts:22 - Canvas Types: Comprehensive TypeScript definitions in
/home/daytona/workspace/source/apps/web/src/types/canvas.ts - Canvas Helper Functions: URL generation and utilities in
canvas-helpers.tsandcanvas-llm-helpers.ts - Classes Actions: Server actions for Canvas API calls in
classes-actions.ts