Learning MCP

Turning three local university CLIs into a cloud MCP product—and deciding where to build, where to borrow, and where to draw the line把三个本地大学 CLI 做成云端 MCP 产品:哪些自己建、哪些借现成的,以及哪些红线坚决不碰

Every semester at Monash, a single course fragments across at least three portals that refuse to talk to each other. Forum clarifications and lecture slides live on Ed Discussion. Deadlines, quizzes, and grades sit inside Moodle. Lab tasks, tutor feedback, and submission progress live in OnTrack. Answering a basic question—what is due this week, did the lecturer clarify question three, what did my tutor comment on Friday's lab—means clicking through three separate tabs and fighting university single sign-on all over again.

If you approach this purely as an engineering problem, the obvious instinct is to start reverse-engineering three campus APIs from scratch. Approaching it as a product problem led me somewhere much better. Open-source CLI clients for all three platforms already existed—bunizao's MIT-licensed edstem-cli, moodle-cli, and ontrack-cli had already done the messy, thankless work of speaking to Ed, Moodle, and OnTrack. What didn't exist was a usable, multi-user cloud product on top of them.

Learning MCP is the product layer I designed and built around those upstream clients: zero local installation, remote OAuth 2.0 for any MCP client, cloud SSO with silent session renewal, one unified mental model of your courses, and strict read-only safety boundaries so an AI assistant can help you study without ever touching a submit button.

在蒙纳士大学,每个学期一门课都会拆散在至少三个互不相通的平台里:课件和答疑在 Ed Discussion,截止日期、测验和成绩在 Moodle,实验任务、助教批注和提交进度在 OnTrack。想查一件再基本不过的事——这周有什么要交、讲师有没有澄清第三题、助教周五实验评了什么——就得切三个标签页,再跟学校单点登录折腾一遍。

顺着工程师惯性走,最容易想到的是从零逆向三套校园 API。可换到产品视角,反而走出了好得多的路。三个平台早已有现成的开源 CLI:bunizao 的 MIT 项目 edstem-cli、moodle-cli 和 ontrack-cli 已经把和 Ed、Moodle、OnTrack 打交道的脏活累活干完了。真正缺的,是盖在它们上面的多用户云端产品。

Learning MCP 就是我围绕这几个上游客户端搭出来的产品层:不用本地安装、给任意 MCP 客户端提供远程 OAuth 2.0、带静默续期的云端 SSO、统一的课程视图,以及硬锁死的只读边界——让 AI 助手真正帮你学习,却永远碰不到提交按钮。

What bunizao solved, and the product gap I built forbunizao 解决了什么,我又补上了哪块缺口

The clearest way to understand Learning MCP is to draw the line between the platform connectors and the product itself. bunizao's edstem-cli, moodle-cli, and ontrack-cli own the low-level protocol layer: parsing Moodle's HTML and web-service quirks, walking Ed Discussion's lesson and thread payloads, and normalizing OnTrack's project snapshots, task sheets, and special-consideration extensions. Rather than re-implementing that surface and fighting API drift alone, I bundled those three MIT-licensed clients directly into the Workers—pinned by exact commit hash and file SHA-256 digest, with generated TypeScript declarations (no permissive index signatures) verified automatically before every deployment.1

A local CLI, however, only works for a power user sitting at one laptop terminal. The moment you switch machines, open an AI assistant on your phone, or try to plug a remote OAuth-capable MCP client into your coursework, local tools fall apart: students have to install Node, manage three separate configs, babysit expiring university cookies, and hope an agent doesn't accidentally invoke a write command. My job was everything above the connector layer—turning three single-user terminal utilities into a multi-user cloud service that feels effortless to connect and predictable to trust.

That meant owning four product surfaces from scratch: cloud identity and per-user isolation, silent session renewal across university SSO, cross-platform course unification with explicit user confirmation, and a strict read-only governance boundary over tools, files, and consent.

看懂 Learning MCP 最简单的办法,是在平台连接器和产品本身之间划一条线。bunizao 的 edstem-cli、moodle-cli 和 ontrack-cli 搞定了底层协议:啃下 Moodle 各种历史遗留 HTML 和接口怪癖、遍历 Ed Discussion 课件和帖子、整理 OnTrack 项目快照、任务书与延期记录。我没去重复造轮子,而是把这三个 MIT 客户端直接打包进 Workers,精确锁死提交哈希和文件 SHA-256 摘要,生成严格 TypeScript 类型声明(禁用宽泛索引签名),每次发布前自动校验。1

但本地 CLI 只适合守在单台电脑前的极客。一旦换台机器、在手机上开 AI 助手,或者想连一个远程 OAuth MCP 客户端,不想装 Node、不想天天伺候过期 Cookie,本地工具立刻失灵。我的工作是连接器上面的一切:把三个单人命令行工具,变成连起来顺手、用起来放心的多用户云端服务。

这意味着从零扛起四块产品面:云端账号与多用户隔离、跨校园 SSO 的静默续期、带人工确认的跨平台课程归并,以及锁死工具、文件和授权的只读治理边界。

Making cloud sign-in feel effortless without cutting corners让云端登录顺手,同时绝不偷工减料

From a user's perspective, connecting university accounts should happen once—and never inside an AI chat window. When an assistant asks to connect a platform, the suite generates an account-bound web link valid for ten minutes so credentials stay strictly on the browser page, outside the conversation. There are zero institution-specific defaults baked into the deployment either: every user supplies their own public HTTPS Moodle and OnTrack base links on first connection, and the system pins those exact origins to their account. Switching to a different university host requires explicitly disconnecting first, which wipes that platform's session and course links so credentials can never drift across institutions.

Even choosing what counts as an account identity was a product decision. Early prototypes anchored accounts to whichever platform you happened to log into first, which got messy fast. I retired platform-based sign-in and anchored each suite account to a single verified identity—either an active, unexpired Okta provider session verified directly on the provider's own origin, or a verified Ed Discussion user ID—while keeping legacy platform-anchored records strictly isolated rather than silently auto-merging accounts.

Underneath that flow sits a hard trust boundary. I split the service into two Cloudflare Workers connected only through a private Service Binding: a public Worker that serves Streamable HTTP MCP, OAuth 2.0 (with PKCE and resource indicators), and account pages, and a completely private broker Worker—with its own per-user Durable Objects and a separate encryption key—that owns all Moodle and OnTrack sign-in and session renewal. During interactive Okta sign-in, the broker holds one live Cloudflare Browser Run session inside a serialized Durable Object for up to five minutes, handles real-world login quirks (password-first detection, SAML handoffs, code-authenticator selection), discovers whichever multi-factor methods the live page actually offers, submits each code at most once, and aborts after three errors without ever writing temporary codes to durable storage.2

The real retention killer in tools like this isn't the first login—it's getting logged out three days later. Because an MCP client's OAuth refresh token only refreshes its own grant with our server and does nothing for Moodle or OnTrack, I designed an HTTP-first renewal layer inside the private broker.3 For Moodle, it keeps a domain- and path-scoped cookie jar, touches the session, fetches a fresh dashboard to verify the same platform identity and extract the session-bound CSRF key, and prevents delayed responses from overwriting a newer cookie rotation. For OnTrack, it exchanges private refresh cookies for a new access token while verifying username continuity and future expiry. Only when HTTP renewal is genuinely rejected—never on a transient outage or identity mismatch—does the broker fall back to a cloud browser using saved SSO cookies or optional user-approved credentials. If a university requires a push approval, passkey, or device check, the suite surfaces a curated, actionable error instead of looping silently.

从学生习惯出发,绑定学校账号应当一次搞定,而且绝不能把密码打进 AI 对话框。每次助手要连新平台,套件会生成一个绑定当前账号、十分钟有效的网页链接,让凭据严格留在浏览器里,半个字不进聊天记录。整套部署也没写死任何学校默认地址:第一次连接由用户自己填 Moodle 和 OnTrack 的公开 HTTPS 根地址,系统把它钉死在账号上;换学校必须先手动断开,把旧会话和课程关联清干净,杜绝凭据跨校串号。

就连「什么算账号身份」也是个产品决定。早期原型按你最先登哪个平台锚定账号,很快变得一团乱。后来我退役了平台锚定登录,把每个套件账号钉在单一可核验身份上——要么是在提供方源站直接验过的未过期 Okta 会话,要么是已验证的 Ed Discussion 用户 ID——旧版平台记录则严格隔离,绝不悄悄自动合并。

这层体验底下是一道硬隔离。服务拆成两个只靠私有 Service Binding 通信的 Cloudflare Workers:外层公开 Worker 管 Streamable HTTP MCP、OAuth 2.0(含 PKCE 与 resource indicator)和账号页;内层私有代理 Worker 独享按用户隔离的 Durable Objects 与独立加密密钥,全权接管 Moodle 和 OnTrack 登录与续期。交互式 Okta 登录期间,代理在串行 Durable Object 里持有最长五分钟的 Cloudflare Browser Run 会话,处理真实登录怪癖(密码优先检测、SAML 跳转、验证码方式选择),动态发现页面实际支持的多因素方式,每个验证码最多交一次,错三次立刻中止,临时码绝不落盘。2

这类工具真正的留存杀手不是第一次登录,而是三天后悄悄掉线。MCP 客户端自己的 OAuth 刷新令牌只能续它和我们服务器之间的授权,救不了 Moodle 和 OnTrack。所以我在私有代理里做了 HTTP 优先续期层。3 面对 Moodle,它维护按域名和路径隔离的 Cookie 容器,触活会话、拉新仪表盘核对身份并提取新 CSRF 密钥,同时防着迟到的旧响应冲掉新轮换的 Cookie。面对 OnTrack,用私有刷新 Cookie 换新访问令牌并校验用户名连续性与过期时间。只有 HTTP 续期明确被拒(绝不在临时网络抖动或身份不匹配时),代理才退一步拉起云端浏览器复用已存 SSO Cookie 或用户授权凭据。万一学校弹出推送审批、通行密钥或设备校验,套件直接返回清晰可操作的报错,绝不在后台死循环。

One mental model for courses, and deciding what not to ship一套课程视图,以及决定哪些功能坚决不做

Students don't think in platform IDs; they think in courses. Yet university portals rarely agree on naming—one lists a cross-listed undergraduate/postgraduate unit with a slash, another appends a campus suffix, and a third labels the semester differently. Auto-linking courses by fuzzy title match would inevitably pull the wrong syllabus, and splitting slash-separated labels into separate aliases would create ambiguous lookups. Instead, I designed a two-step binding flow: fresh enrollment discovery across whichever platforms a student connected (even Moodle alone) proposes candidates while keeping composite labels intact, and builds an encrypted, ten-minute preview flagging every code or semester mismatch as an explicit warning. The user reviews the preview once and commits the whole batch atomically, with stale-snapshot checks rejecting silent concurrent changes.

Even more important was deciding what capabilities to cut. bunizao's upstream clients support rich write operations—uploading assignments, starting and finishing Moodle quizzes, posting Ed forum replies, marking lessons read, sending OnTrack chat messages. In an AI-assisted product, shipping write access is a lopsided bet where one hallucinated tool call can cost a student real marks. So I built a single capability catalog that acts as a strict product gate: it generates over fifty read-only MCP tools—covering Ed lessons, slides, and threads; Moodle deadlines, grades, feedback, forums, and quiz attempt reviews; and OnTrack task sheets, effective due dates with extensions in the bound course timezone, and unread counts—alongside their Zod schemas, TypeScript contracts, and backend allowlists, while keeping every write operation excluded at the catalog level.

Designing a truly read-only product turned out to mean auditing upstream 'read' endpoints for hidden side effects too. On OnTrack, simply reading task chat history marks non-discussion comments as read—so I deliberately withheld chat history and exposed only unread counts from the project snapshot. On Ed Discussion, lesson and slide reads explicitly disable view tracking so browsing your syllabus doesn't mark unread lectures complete. And for attendance codes—one of the highest-frequency student requests—the suite searches Ed and Moodle text and returns candidate codes with direct source links, dates, and an explicit partial-coverage disclaimer, while prohibiting attendance submission outright.

Good product work on top of open-source primitives isn't rebuilding the pipes—it's deciding which pipes to expose, which hidden side effects to block, and how to make the safe path the easy path.

学生脑子里没有平台 ID,只有课程。可学校三个平台偏偏很少把课名写一致:一个把本研合开课写成斜杠组合,一个拼校区后缀,另一个学期格式不同。拿标题模糊匹配自动绑定早晚挂错大纲,把斜杠拆成别名又会制造歧义。于是改成两步绑定:拉取已连平台的最新选课(哪怕只连了 Moodle),保留复合标签原貌,生成加密十分钟预览,把每处代码或学期对不上的地方标成显式提醒;用户核对一遍再原子提交,靠快照校验挡住并发覆盖。

更关键的是决定砍掉哪些能力。bunizao 的上游客户端写功能很全:交作业、点开并提交 Moodle 测验、发 Ed 回帖、标课件已读、发 OnTrack 聊天。在 AI 学习产品里放开写权限,这笔账极不划算,一次幻觉调用就可能坑掉真实成绩。所以我建了单一能力目录充当硬闸门:五十多个只读 MCP 工具(涵盖 Ed 课件、幻灯片与帖子,Moodle 截止时间、成绩、反馈、论坛与测验复盘,OnTrack 任务书、按绑定课程时区算上延期后的实际截止日与未读数),连同 Zod Schema、TypeScript 契约和后端白名单,全从同一份目录生成,写操作在目录层压根不存在。

真正做只读,还得把上游「读」接口里的隐性副作用挨个查一遍。在 OnTrack,光拉一次任务聊天记录就会把非讨论类批注标已读,所以我干脆扣下聊天记录,只从项目快照读未读数。在 Ed Discussion,读课件和幻灯片会触发观看进度统计,每次拉取都显式关掉观看追踪。至于学生最常问的考勤码,套件只搜 Ed 和 Moodle 文本,把候选码连同原文直达链接、日期与非全覆盖声明一并返回,提交考勤彻底禁止。

在开源原语之上做产品,不是重造管道,而是决定放开哪几根、拦住哪些隐性副作用,让安全的路变成最顺手的路。

Files, redaction, and an honest threat model文件交付、脱敏与坦诚的威胁模型

Real coursework lives in PDFs, slide decks, Moodle books, and attachments, so a read-only suite isn't genuinely useful unless it can deliver files safely.4 I capped native MCP embedded binary resources at 16 MiB per file or batch, added in-Worker PDF text extraction (capped at 200 pages, 50 per request, explicitly noting that scans and diagrams require fetching the original PDF), stripped executable HTML from synced Moodle pages under a data-image-only Content Security Policy, and designed a stateless SHA-256 sync contract so clients don't re-download unchanged bytes. Attachment downloads only follow freshly discovered links against an explicit resource-origin allowlist (at most five redirects), never send platform credentials off-site, and reject partial or truncated bodies.

Because forum posts and course pages are untrusted input, every tool response and error passes through a per-request output scrubber that redacts recognized credential fields, credential-bearing URL parameters, and known session secrets. Binary resources can only be constructed by the file-delivery helper, so hostile text in a course thread can't spoof an attachment by mimicking its JSON shape.

Finally, I wanted the product's trust model to be completely honest rather than hiding behind 'encrypted in the cloud' marketing.5 Encrypting tokens, sessions, and opted-in credentials inside per-user Durable Objects protects data at rest, but whoever operates the deployment and holds its keys can still decrypt them. That is why Learning MCP ships for self-hosting under a source-available noncommercial license, with versioned notice and terms acceptance before credentials are ever touched, separate default-off opt-ins for password and authenticator retention, an operator CLI that can list and revoke OAuth grants without ever exposing credentials, and clean user escape hatches: 'Forget saved sign-in' wipes passwords, authenticator secrets, and shared SSO cookies while leaving active platform sessions intact, and disconnecting a platform removes its session, renewal material, and course links completely.6

真正的学习资料全在 PDF、幻灯片、Moodle 电子书和附件里,不能安全交文件的只读套件称不上好用。4 我把原生 MCP 内嵌二进制资源卡在单文件或单批 16 MiB,加入 Worker 内 PDF 文本提取(封顶 200 页、单次 50 页,明确提醒扫描件和图表还得看原 PDF),在只放行 data-image 的 CSP 下清掉同步 Moodle 页面里的可执行 HTML,并用无状态 SHA-256 同步契约避免重复下未变字节。附件下载只走新发现链接,对照来源白名单最多五次重定向,绝不向外站带平台凭据,残缺响应体直接拒收。

因为论坛帖子和课程页面属于不可信输入,每条工具返回和报错出站前都会过一遍按请求运行的清洗器,抹掉已知凭据字段、带凭据 URL 参数和会话密钥。二进制资源只能由文件交付辅助函数构造,课程帖子里塞进来的恶意文本不可能靠模仿 JSON 长相冒充附件。

最后,我希望产品的信任模型完全敞亮,不拿「云端加密」四个字打马虎眼。5 把令牌、会话和用户授权凭据加密存进按用户隔离的 Durable Objects 确实能防静态泄漏,但运营部署、手握密钥的人理论上依然解得开。正因如此,Learning MCP 以非商用源码可见许可面向自托管发布:碰凭据前必经版本化告知与条款同意;保存密码与验证器默认关闭、拆成两项独立授权;管理员 CLI 可列出和吊销 OAuth 授权却永不碰明文凭据;给用户留的退路也很干脆——「忘记已保存登录」清掉密码、验证器密钥和共享 SSO Cookie 但保留当前活跃会话,断开平台则彻底清空会话、续期材料与课程关联。6

Notes注释

  1. Upstream clients are bundled from bunizao's MIT-licensed edstem-cli, moodle-cli, and ontrack-cli. Deployment scripts verify bundled source integrity and upstream freshness before publishing; each vendored client retains its upstream MIT license notice.↩︎上游客户端打包自 bunizao 的 MIT 项目 edstem-cli、moodle-cli 与 ontrack-cli。发布前脚本自动核对打包源码完整性与上游新鲜度,每个内置客户端均保留原始 MIT 许可声明。↩︎
  2. The interactive login transaction follows Cloudflare's Durable Object browser-reuse pattern with Playwright keep-alive, bound to an opaque account handle, a suite browser cookie, and a rotating single-use nonce. Only curated error codes and fixed MFA method identifiers leave the browser; raw provider page text stays untrusted and private.↩︎交互登录事务走 Cloudflare Durable Object 浏览器复用模式与 Playwright 保活,绑定不透明账号句柄、套件浏览器 Cookie 与单次轮换 nonce。离开浏览器的只有精选错误码与固定 MFA 方式标识,原始页面文本保持不可信与私密。↩︎
  3. Broker operations are serialized per user with brief renewal reuse to avoid duplicate exchanges and a one-minute per-platform backoff on failures. There is no scheduled background keep-alive job.↩︎代理操作按用户串行化,带短暂续期复用避免重复换票,失败时按平台退避一分钟;不存在后台定时保活任务。↩︎
  4. On Ed Discussion, four interactive views (forum catch-up, thread activity, lesson progress, and lesson guides) reuse upstream view builders inside a display-only MCP App with local-only practice questions—making zero platform writes—while falling back to text and structured data on clients without MCP App support.↩︎在 Ed Discussion 上,四个交互视图(论坛速览、帖子动态、课件进度、课件指南)在纯展示 MCP App 内复用上游视图构造器并附带纯本地练习题(零平台写入),不支持 MCP App 的客户端优雅回退到文本与结构化数据。↩︎
  5. OAuth consent pages restrict form-action strictly to the current client's registered callback origin while keeping every other page at form-action 'self', preserving Origin, CSRF, PKCE, and single-use nonce checks. OAuth scopes are split cleanly into reading coursework, managing course bindings, and offline refresh access.↩︎OAuth 授权页将 form-action 严格锁到当前客户端注册的回调来源,其余页面锁死 form-action 'self',保留 Origin、CSRF、PKCE 与单次 nonce 校验。OAuth 权限拆成读取课程、管理课程绑定与离线刷新三档。↩︎
  6. Both Workers are covered by unit tests and workerd runtime integration suites against controlled platform and SSO fixtures. As the README notes plainly, fixture tests verify protocol and isolation logic, not a specific university's live identity provider—a real two-user check remains part of every deployment.↩︎两个 Worker 均配齐单元测试和面向受控平台/SSO 夹具的 workerd 运行时集成测试。正如 README 坦白写的,夹具测试验的是协议和隔离逻辑,不是某所学校的线上身份源——每次上线前仍需做真实双用户核验。↩︎

Product architecture, two-Worker Cloudflare suite, private SSO broker, OAuth 2.0 layer, capability catalog, and safety boundaries built in TypeScript on top of bunizao's MIT-licensed Ed, Moodle, and OnTrack CLI clients.基于 bunizao 的 MIT 许可 Ed、Moodle、OnTrack CLI 客户端,以 TypeScript 构建双 Worker Cloudflare 套件、私有 SSO 代理、OAuth 2.0 层、能力目录与安全边界。

Stack: TypeScript, Cloudflare Workers, MCP, Durable Objects, OAuth.技术栈:TypeScript、Cloudflare Workers、MCP、Durable Objects、OAuth。