使用说明
Canvas LMS MCP服务器
一个模型上下文协议(MCP)服务器,将Canvas LMS与Claude集成在一起,实现 Chalmers Canvas课程的自然语言访问权限,包括模块、页面、, 成绩、日历事件、公告、讨论和作业提交。
特性
13种工具,满足Canvas学生的全方位需求:
课程结构 (处理所有教师风格)
| 工具 | 说明 |
|---|---|
list_courses |
获取所有活动课程及其结构类型 |
get_course_details |
本课程的详细信息+导航提示 |
get_course_modules |
每周嵌入项目的模块结构 |
get_course_pages |
列出所有维基页面(阅读材料、说明等) |
get_course_home_page |
主登录页面内容(对维基视图课程至关重要) |
get_course_files |
可下载的文件,带有智能回退建议 |
get_course_syllabus |
评分政策、要求、课程目标 |
学生特色
| 工具 | 说明 |
|---|---|
get_assignments |
课程的所有作业 |
get_upcoming_deadlines |
所有课程的所有未来截止日期 |
get_course_grades |
您在特定课程中的成绩/分数 |
get_all_grades |
所有课程的成绩概览 |
get_assignment_submission |
提交状态+教师反馈 |
get_announcements |
最近的公告(一门课程或全部课程) |
get_calendar_events |
课程讲座和活动 |
get_all_calendar_events |
所有课程的完整时间表 |
讨论
| 工具 | 说明 |
|---|---|
get_course_discussions |
带有回复/未读计数的论坛主题 |
get_discussion_entries |
阅读实际帖子和回复 |
Canvas课程结构——工作原理
教师们对Canvas课程的结构不同。这 default_view 字段(可见
在 list_courses 和 get_course_details)告诉您要使用哪些工具:
default_view |
这意味着什么 | 最好的开始工具 |
|---|---|---|
modules |
每周结构 | get_course_modules |
wiki |
主页是内容中心 | get_course_home_page |
syllabus |
以教学大纲为重点 | get_course_syllabus |
assignments |
以任务为中心 | get_assignments |
get_course_details 总是返回a navigation_hint 告诉克劳德
接下来该调用哪个工具。
先决条件
- Python 3.10或更高版本
- Chalmers Canvas帐户位于 canvas.charmers.se
- Claude桌面(用于集成)
获取Canvas访问令牌
- 首选 canvas.charmers.se 并登录
- 点击 账户 (左侧边栏)→ 设置
- 滚动到 已批准的集成
- 点击 +新访问令牌
- 集 目的:“克劳德MCP集成”
- 可选择设置安全到期日期
- 点击 生成令牌
- 立即复制令牌 --它只显示一次
安装
# 1. Navigate to the project directory
cd /Users/theatornqvist/canvas-mcp
# 2. Create and activate virtual environment
python3 -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
# 3. Install dependencies
pip install -r requirements.txt
# 4. Configure environment
cp .env.example .env
# Edit .env and set CANVAS_TOKEN=your_actual_token_here
测试服务器
# Quick startup check (Ctrl+C to stop)
python server.py
# No output = working correctly. Errors appear on stderr.
Claude桌面集成
编辑您的Claude Desktop配置:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
{
"mcpServers": {
"canvas-lms": {
"command": "/Users/theatornqvist/canvas-mcp/.venv/bin/python",
"args": ["/Users/theatornqvist/canvas-mcp/server.py"],
"env": {
"CANVAS_TOKEN": "your_canvas_token_here",
"CANVAS_BASE_URL": "https://canvas.chalmers.se/api/v1"
}
}
}
}
保存后完全重新启动Claude Desktop。
使用示例
浏览不同的课程结构
"What courses am I enrolled in?"
→ list_courses — see default_view for each course
"Tell me about my NLP course"
→ get_course_details — returns navigation_hint: "use get_course_modules"
"Show week 3 content from the NLP course"
→ get_course_modules — shows weekly structure with all embedded items
"What's on the Applied ML home page?"
→ get_course_home_page — critical for wiki-view courses
"List all pages in my Machine Learning course"
→ get_course_pages — shows all wiki pages
"What files are available in DAT450?"
→ get_course_files — with smart suggestions if empty
成绩和表现
"How am I doing in all my courses?"
→ get_all_grades
"What's my grade in the NLP course?"
→ get_course_grades(course_id)
"Did I submit the last homework?"
→ get_assignment_submission(course_id, assignment_id)
"What feedback did I get on lab 2?"
→ get_assignment_submission — includes teacher comments
截止日期和日历
"What's due this week?"
→ get_upcoming_deadlines
"What do I have today?"
→ get_all_calendar_events(days_ahead=1)
"What's my schedule this week?"
→ get_all_calendar_events(days_ahead=7)
"When is the next lecture for DAT315?"
→ get_calendar_events(course_id)
公告
"Any new announcements?"
→ get_announcements (all courses, last 14 days)
"Did the NLP teacher post anything?"
→ get_announcements(course_id=NLP_COURSE_ID)
"Show me announcements from the last month"
→ get_announcements(days_back=30)
讨论
"What's being discussed in the forum?"
→ get_course_discussions(course_id)
"Read the week 3 discussion"
→ get_discussion_entries(course_id, topic_id)
"Summarize what people are saying about the midterm"
→ get_discussion_entries(course_id, topic_id)
常见模式
模式1:未知的课程结构
You: "Show me the content for my Applied ML course"
Claude:
1. list_courses → finds Applied ML, default_view = "wiki"
2. get_course_home_page → gets the rich home page content
OR if empty: get_course_pages → lists all wiki pages
模式2:寻找特定材料
You: "Find the lecture slides for week 3 in NLP"
Claude:
1. list_courses → finds NLP course ID
2. get_course_modules → finds "Week 3" module
3. Looks for File/Page items in that module
模式3:检查成绩+反馈
You: "How did I do on the last assignment in DAT450?"
Claude:
1. get_assignments(course_id) → finds the latest assignment + its ID
2. get_assignment_submission(course_id, assignment_id) → grade + comments
模式4:日常计划
You: "What do I have going on today and this week?"
Claude:
1. get_all_calendar_events(days_ahead=7) → schedule
2. get_upcoming_deadlines → nearest assignment deadlines
3. get_announcements → any recent teacher posts
工具参考
list_courses
[{
"id": 12345,
"name": "Natural Language Processing",
"course_code": "DAT450",
"enrollment_term": "HT 2024",
"default_view": "modules",
"total_students": 85
}]
get_course_modules
{
"modules": [{
"id": 111,
"name": "Week 3: Sequence Models",
"position": 3,
"items_count": 5,
"items": [
{"type": "File", "title": "Lecture 3 Slides", "html_url": "..."},
{"type": "Assignment", "title": "Lab 1", "html_url": "..."},
{"type": "ExternalUrl", "title": "Paper reading", "external_url": "..."}
]
}],
"count": 8
}
get_all_grades
[{
"course_id": 12345,
"course_name": "Natural Language Processing",
"course_code": "DAT450",
"current_score": 87.5,
"current_grade": "B+",
"final_score": 85.0,
"final_grade": "B"
}]
获取_分配_提交
{
"assignment_name": "Lab 2: Sequence Labelling",
"submitted": true,
"submitted_at": "2024-10-15T22:30:00Z",
"workflow_state": "graded",
"score": 95.0,
"grade": "A",
"late": false,
"submission_comments": [
{"comment": "Great work on the CRF section!", "author_name": "Dr. Smith"}
]
}
get_all_calendar_events
[{
"title": "Lecture 5: Transformers",
"course_name": "Natural Language Processing",
"start_at": "2024-10-17T10:00:00Z",
"end_at": "2024-10-17T12:00:00Z",
"location_name": "Room HC4"
}]
项目结构
canvas-mcp/
├── server.py # MCP server with all 13 tool definitions
├── canvas_api.py # Canvas API wrapper (all HTTP calls + error handling)
├── requirements.txt # Dependencies
├── .env.example # Environment variable template
├── .env # Your actual token (NOT in git)
├── .gitignore # Protects .env and caches
└── README.md # This file
错误处理
所有工具都能优雅地处理错误并返回描述性消息:
| HTTP代码 | 含义 | 响应 |
|---|---|---|
| 401 | 标记错误 | “身份验证失败。请检查CANVAS_token。” |
| 403 | 选项卡已禁用 | “文件选项卡已禁用。请尝试get_curse_modules。” |
| 404 | 没有这样的资源 | “没有设置主页。请尝试get_curse_modules。” |
| 429 | 速率限制 | “已超出速率限制。请稍候。” |
| 空 | 无数据 | “找不到模块。请尝试get_curse_home_page。” |
空结果总是包含 suggestions 现场使用替代工具进行尝试。
安全
- Token存在于
.env(仅限本地,不包括在git中) - 令牌也在Claude Desktop配置中(仅限本地,不发送到任何地方)
- 代码库中任何地方都没有记录令牌
- 画布速率限制:约3000个请求/小时——正常使用远低于此值
故障排除
服务器未启动
# Verify dependencies are installed
.venv/bin/pip list | grep mcp
# Check .env exists and has your token
cat .env
“身份验证失败” --检查您的CANVAS_TOKEN是否正确且未过期。 如果需要,从画布设置生成一个新的画布。
Claude Desktop不显示Canvas工具 --验证配置中的绝对Python路径
火柴 .venv/bin/python 并完全重新启动Claude Desktop。
所有课程返回空模块 --使用 list_courses 先检查 default_view
对于每门课程,然后调用该视图类型的相应工具。
未来的增强功能
- 提交作业
- 发布讨论回复
- 下载文件内容
- 大型课程分页(>100个文件/模块)
- 用于重复查询的缓存层
- 通知/推送式公告