Canvas MCP - AI-Powered Course Management Assistant

An intelligent assistant that integrates Canvas LMS, Google Calendar, and Gmail through Claude AI (via OpenRouter). Manage your courses, assignments, calendar events, and emails through natural language conversations.

πŸš€ Features

Canvas Integration

  • View Courses: List all your Canvas courses with details
  • Assignment Management: View upcoming assignments, create new assignments, and delete assignments
  • Daily Briefing: Get a comprehensive overview of your courses and upcoming assignments
  • Time Zone Support: Automatic timezone handling for assignment due dates

Google Calendar Integration

  • Event Management: List, create, update, and delete calendar events
  • Smart Scheduling: Natural language event creation with automatic date/time parsing
  • Event Search: Find events by date range or keywords

Gmail Integration

  • Email Reading: Read and search through your emails
  • Email Sending: Send emails with attachments
  • Inbox Management: Search and filter your inbox

AI-Powered Interface

  • Natural Language: Interact with all services using plain English
  • Context-Aware: Maintains conversation history for better understanding
  • Multi-Tool Execution: Automatically uses the right tools to answer your queries

πŸ“‹ Prerequisites

  • Python 3.8 or higher
  • OpenRouter API key (Get one here)
  • Canvas API key (from your Canvas account settings)
  • Google Cloud Project with Calendar and Gmail APIs enabled
  • OAuth 2.0 credentials for Google services

πŸ› οΈ Installation

  1. Clone the repository:

    git clone <repository-url>
    cd mcp-datathon
    
  2. Install dependencies:

    pip install -r requirements.txt
    
  3. Set up environment variables:

Create a .env file in the root directory:

   # Required
   OPENROUTER_API_KEY=your_openrouter_api_key
   CANVAS_API_KEY=your_canvas_api_key

   # Optional - Custom paths for Google credentials
   CALENDAR_CREDENTIALS_PATH=credentials.json
   CALENDAR_TOKEN_PATH=calendar_token.json
   GMAIL_CREDENTIALS_PATH=credentials.json
   GMAIL_TOKEN_PATH=token.json
   USER_TIMEZONE=America/New_York

πŸ”§ Setup

Canvas API Setup

  1. Log in to your Canvas account
  2. Go to Account β†’ Settings β†’ Approved Integrations
  3. Click + New Access Token
  4. Give it a purpose (e.g., "MCP Server")
  5. Copy the generated token and add it to your .env file as CANVAS_API_KEY

Google Services Setup

The project uses OAuth 2.0 for Google Calendar and Gmail access. You can use the same credentials file for both services.

1. Enable APIs in Google Cloud Console

  1. Go to Google Cloud Console
  2. Create a new project or select an existing one
  3. Navigate to APIs & Services β†’ Library
  4. Enable both Calendar API and Gmail API

2. Create OAuth 2.0 Credentials

  1. Navigate to APIs & Services β†’ Credentials
  2. Click Create Credentials β†’ OAuth client ID
  3. Configure the OAuth consent screen:
    • User Type: External (for personal use) or Internal (for Google Workspace)
    • Fill in required app information
    • Add your email to test users (if using External)
  4. For Application type, select Desktop app
  5. Download the credentials file and save it as credentials.json in the project root

3. Authenticate Google Services

For Calendar:

python authenticate_calendar.py

For Gmail:

python authenticate_gmail.py

These scripts will:

  • Open a browser window for OAuth authentication
  • Save tokens to calendar_token.json and token.json respectively
  • Only need to be run once (tokens are reused until revoked)

For detailed setup instructions, see:

πŸƒ Running the Application

Development Mode

  1. Start the FastAPI backend: bash uvicorn backend.api:app --reload --port 8000

The backend will be available at http://localhost:8000

  1. Start the Streamlit frontend: bash streamlit run frontend.py

The frontend will open at http://localhost:8501

  1. Open your browser:
    • Navigate to http://localhost:8501
    • Start chatting with the assistant!

Using MCP Servers Directly

You can also use the MCP servers directly with Claude Desktop or other MCP-compatible clients:

Canvas MCP Server:

python mcp_server.py

Calendar MCP Server:

python calendar_mcp_server.py

Gmail MCP Server:

python gmail_mcp_server.py

πŸ’¬ Example Queries

  • Canvas:

    • "What courses do I have?"
    • "Show me assignments due in the next week"
    • "Create an assignment in my CS101 course due next Friday"
    • "Give me my daily briefing"
  • Calendar:

    • "What events do I have tomorrow?"
    • "Create a calendar event for tomorrow at 2pm called 'Team Meeting'"
    • "Show me all events this week"
  • Gmail:

    • "Show me my recent emails"
    • "Send an email to example@email.com with subject 'Hello'"
    • "Search for emails from my professor"

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Streamlit UI   β”‚  (frontend.py)
β”‚   (Frontend)    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚ HTTP
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  FastAPI Backendβ”‚  (backend/api.py)
β”‚   (Backend)     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β”œβ”€β”€β–Ί OpenRouter API (Claude AI)
         β”‚
         └──► Service Layer (backend/service_layer.py)
                  β”‚
                  β”œβ”€β”€β–Ί Canvas MCP Server (mcp_server.py)
                  β”œβ”€β”€β–Ί Calendar MCP Server (calendar_mcp_server.py)
                  └──► Gmail MCP Server (gmail_mcp_server.py)

Components

  • Frontend (frontend.py): Streamlit web interface for user interaction
  • Backend (backend/api.py): FastAPI server that handles queries and integrates with OpenRouter
  • Service Layer (backend/service_layer.py): Wraps MCP server functions for programmatic access
  • MCP Servers: Individual servers for Canvas, Calendar, and Gmail integrations
    • mcp_server.py: Canvas LMS integration
    • calendar_mcp_server.py: Google Calendar integration
    • gmail_mcp_server.py: Gmail integration

πŸ“ Project Structure

mcp-datathon/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ api.py              # FastAPI backend server
β”‚   └── service_layer.py    # MCP service wrapper
β”œβ”€β”€ frontend.py             # Streamlit frontend
β”œβ”€β”€ mcp_server.py           # Canvas MCP server
β”œβ”€β”€ calendar_mcp_server.py  # Calendar MCP server
β”œβ”€β”€ gmail_mcp_server.py     # Gmail MCP server
β”œβ”€β”€ authenticate_calendar.py # Calendar OAuth setup
β”œβ”€β”€ authenticate_gmail.py   # Gmail OAuth setup
β”œβ”€β”€ requirements.txt        # Python dependencies
β”œβ”€β”€ README.md               # This file
β”œβ”€β”€ README_FRONTEND.md      # Frontend-specific docs
β”œβ”€β”€ FRONTEND_SETUP.md       # Detailed frontend setup
β”œβ”€β”€ CALENDAR_SETUP.md       # Calendar setup guide
β”œβ”€β”€ GMAIL_SETUP.md          # Gmail setup guide
β”œβ”€β”€ RENDER_DEPLOYMENT.md    # Backend deployment guide
└── STREAMLIT_DEPLOYMENT.md # Frontend deployment guide

🚒 Deployment

Backend Deployment (Render)

The FastAPI backend can be deployed to Render. See RENDER_DEPLOYMENT.md for detailed instructions.

Quick steps:

  1. Create a new Web Service on Render
  2. Connect your GitHub repository
  3. Set environment variables in Render dashboard
  4. Deploy!

Frontend Deployment (Streamlit Cloud)

The Streamlit frontend can be deployed to Streamlit Cloud. See STREAMLIT_DEPLOYMENT.md for detailed instructions.

Quick steps:

  1. Push your code to GitHub
  2. Go to Streamlit Cloud
  3. Connect your repository
  4. Set environment variables
  5. Deploy!

πŸ” Security Notes

  • Never commit .env files, credentials.json, or token files to version control
  • Add these to .gitignore: .env credentials.json *token.json calendar_token.json
  • Keep your API keys secure and rotate them regularly
  • For production, use environment variables or secure secret management services

πŸ› Troubleshooting

Backend Connection Issues

  • Error: "Backend not accessible"
    • Ensure the backend is running on port 8000
    • Check that API_URL in frontend.py matches your backend URL
    • Verify firewall settings allow local connections

Canvas API Errors

  • 401 Unauthorized: Check that your CANVAS_API_KEY is correct and not expired
  • 403 Forbidden: Verify your API key has the necessary permissions

Google OAuth Issues

  • Token expired: Re-run the authentication scripts (authenticate_calendar.py or authenticate_gmail.py)
  • Scope errors: Ensure both Calendar and Gmail APIs are enabled in Google Cloud Console
  • Redirect URI mismatch: Make sure you're using "Desktop app" credentials type

OpenRouter API Issues

  • Rate limiting: OpenRouter has rate limits on free tier accounts
  • Model unavailable: Check that anthropic/claude-3.5-sonnet is available, or change the model in backend/api.py

πŸ“š API Endpoints

Backend API

  • POST /chat: Process a user query and return AI response

    {
    "query": "What courses do I have?",
    "conversation_history": []
    }
    
  • GET /health: Health check endpoint

  • GET /tools: Get all available MCP tools

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

πŸ“ License

This project is part of a Datathon submission.

πŸ”— Additional Resources

πŸ“ž Support

For issues and questions:

  • Check the setup guides in the *.md files
  • Review the troubleshooting section above
  • Open an issue on the repository

Built with ❀️ for the Datathon

Built With

Share this project:

Updates