Designing Read-Only AI Products People Can Trust只读 AI 产品怎么设计,别人才敢放心用
Connecting an AI assistant to university portals: the hard part was deciding what to cut, not reverse-engineering the APIs.把 AI 助手接进大学课程平台,最难的从来不是逆向接口,而是决定哪些事坚决不做。
Most demos of AI agents follow the same script: connect a language model to your email, calendar, or workplace tools, and watch it click buttons on your behalf. It makes for a thrilling two-minute video—and a terrible default for any real system where a single hallucinated tool call carries lasting consequences.
University coursework is one of those systems. Every semester at Monash, a single unit fragments across three portals that refuse to talk to each other: lecture slides and forum clarifications live on Ed Discussion, deadlines and quiz reviews sit in Moodle, and lab task sheets, tutor feedback, and extension dates live in OnTrack. Answering an ordinary question—what is due this Friday, did the lecturer clarify question three, what did my tutor comment on last week's lab—means opening three tabs and fighting single sign-on all over again.
When I built Learning MCP to connect AI assistants to all three portals, the most tempting engineering path was to expose every capability the underlying platforms offered. The better product path turned out to be the exact opposite: borrowing the low-level connectors, refusing to ship write access, auditing supposedly harmless "read" endpoints for hidden side effects, and being blunt about what cloud hosting can and cannot protect.
Borrow the pipes, own the product boundary
If you treat a campus integration purely as a coding challenge, you immediately lose weeks reverse-engineering Moodle's HTML quirks, Ed Discussion's thread payloads, and OnTrack's task snapshots from scratch. Open-source MIT-licensed CLI clients for all three platforms—bunizao's edstem-cli, moodle-cli, and ontrack-cli—had already done that messy, thankless protocol work cleanly.
What didn't exist was a usable multi-user cloud product on top of them. A local CLI works for a power user sitting at one laptop terminal, and falls apart the moment a student switches machines, opens an AI assistant on their phone, or wants to connect a remote OAuth-capable MCP client without installing Node and babysitting expiring university cookies.
Bundling those three upstream clients directly into the Workers—pinned by exact commit hash and file SHA-256 digest, with generated TypeScript declarations verified before every deployment—freed me to focus on the real product surface above the pipes: cloud identity and per-user isolation, silent session renewal across university SSO, cross-platform course unification, and a strict safety boundary over tools, files, and consent.
Why cloud sign-in and silent renewal decide retention
In a developer prototype, getting the first login to work feels like the finish line. In a real product, the actual retention killer is getting silently logged out three days later.
From a student's perspective, connecting university accounts should happen once—and never inside an AI chat window. Whenever an assistant asks to connect a platform, Learning MCP generates an account-bound browser link valid for ten minutes so credentials never touch the conversation transcript. There are zero hardcoded institution defaults baked into the deployment either: each user provides their own public HTTPS Moodle and OnTrack base links on first connection, the service pins those exact origins to their account, and switching institutions requires an explicit disconnect that wipes sessions and course links first.
Underneath that experience sits a hard trust boundary. The suite is split into two Cloudflare Workers communicating strictly over a private Service Binding: a public Worker serving Streamable HTTP MCP, OAuth 2.0 (with PKCE and resource indicators), and account pages, and a private broker Worker—with its own per-user Durable Objects and a separate encryption key—that owns all Moodle and OnTrack sign-in and renewal.
Because an MCP client's OAuth refresh token only refreshes its own grant with our server and does nothing for Moodle or OnTrack, the private broker runs an HTTP-first renewal layer. For Moodle, it maintains 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 serialized Cloudflare Browser Run session using saved SSO cookies or optional user-approved credentials. If a university requires a push approval, passkey, or device check, the product surfaces a curated, actionable error instead of looping silently in the background.
Why read-only has to be structural, not a prompt
The upstream CLIs support rich write operations: uploading assignments, starting and finishing Moodle quizzes, posting Ed forum replies, marking lessons read, and sending OnTrack chat messages. In an AI-assisted study tool, exposing those actions is a brutally asymmetric bet. Saving a student ten seconds on a form click is never worth the risk of a confused model submitting an unfinished quiz or posting an off-target reply under their real name.
Asking the model in a system prompt to "confirm before submitting" is not a real product boundary—prompts are suggestions, not access controls. Instead, Learning MCP enforces read-only behavior at the capability-catalog layer. 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—are generated alongside their Zod schemas, TypeScript contracts, and backend allowlists from a single catalog where write operations simply do not exist.
The same principle shaped how courses are unified across portals. University systems 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 attach the wrong syllabus. Instead, fresh enrollment discovery builds an encrypted ten-minute preview flagging every code or semester mismatch as an explicit warning; the user reviews it once and commits the batch atomically, with stale-snapshot checks rejecting silent concurrent drift.
Good product work on top of powerful primitives is rarely about exposing every switch—it is about making the safe path effortless and making the irreversible path impossible by construction.
Auditing "read" endpoints for hidden side effects
The most surprising part of building a strictly read-only AI product was discovering that cutting obvious write commands wasn't enough. Several upstream endpoints that look like pure reads on paper still mutate state quietly on the server:
- OnTrack task chat history: simply fetching a task's chat messages marks non-discussion tutor comments as read. Rather than letting an AI assistant silently clear a student's unread notifications while summarizing a week's work, I withheld chat history completely and exposed only unread counts from the project snapshot.
- Ed Discussion lessons and slides: standard reads trigger view tracking, so asking an assistant to summarize upcoming lectures would falsely mark unread lessons complete. Every lesson and slide fetch explicitly disables view tracking.
- Attendance codes: finding an attendance code mentioned in a lecture thread or Moodle announcement is one of the highest-frequency student requests, while automated attendance submission crosses an academic-integrity line. The suite searches Ed and Moodle text and returns candidate codes with direct source links, dates, and an explicit partial-coverage disclaimer—while prohibiting submission outright.
Every AI product wired into legacy web systems runs into these quiet traps. Treating "read-only" as an endpoint-by-endpoint audit rather than a marketing label is what keeps an assistant from leaving footprints where the user never expected them.
Treating coursework files and forum text as untrusted input
A study assistant isn't genuinely useful if it can only read short JSON titles—real coursework lives in lecture PDFs, slide decks, Moodle books, and attachments. Yet the moment an AI tool downloads files and relays forum threads written by other people, it inherits a real security surface.
To keep file delivery predictable and safe, embedded binary MCP resources are capped at 16 MiB per file or batch, in-Worker PDF text extraction is capped at 200 pages (50 per request, explicitly noting that scans and diagrams still require fetching the original PDF), synced Moodle HTML strips executable content under a data-image-only Content Security Policy, and attachment downloads only follow freshly discovered links against an explicit resource-origin allowlist with at most five redirects—never forwarding platform credentials off-site and rejecting truncated bodies.
Because forum posts and course pages are untrusted text, every tool response and error also runs through a per-request output scrubber that redacts recognized credential fields, credential-bearing URL parameters, and known session secrets. Binary attachment envelopes can only be constructed by the file-delivery helper itself, so hostile text pasted into a course thread can never spoof an attachment by mimicking its JSON structure.
Writing an honest threat model
The final trust boundary is how you talk about stored credentials. When a cloud service holds OAuth tokens, university session cookies, or opted-in renewal material, it is tempting to slap "encrypted in the cloud" on the landing page and move on.
That phrasing dodges the only question a technical user actually cares about: encrypted from whom? Encrypting tokens and sessions inside per-user Durable Objects protects data at rest, but whoever operates the deployment and holds its encryption keys can still decrypt them. Pretending otherwise erodes trust the moment someone reads the architecture.
Instead, Learning MCP ships for self-hosting under a source-available noncommercial license, requires versioned notice and terms acceptance before any credentials are touched, keeps password and authenticator retention default-off behind separate opt-ins, and gives operators a CLI that can list and revoke OAuth grants without ever exposing credentials. On the user side, the escape hatches are just as clear: "Forget saved sign-in" wipes stored 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.
Building trustworthy AI products rarely comes down to a cleverer prompt. It comes down to shrinking the blast radius, hunting down hidden side effects inside ordinary reads, and telling users the unvarnished truth about where trust begins and ends.
现在大多数 AI Agent 演示都按同一套剧本拍:把模型接上邮箱、日历或者办公软件,看着它自己一路点按钮、发消息、填表单。两分钟的演示视频确实看得人心痒,但放到现实里,只要模型犯一次糊涂就会造成真实损失的系统,这套做法就是灾难。
大学的课程系统正好踩在这个点上。在蒙纳士大学,每个学期一门课都会拆散在三个互不相通的平台里:课件和答疑在 Ed Discussion,截止日期、测验复盘和成绩在 Moodle,实验任务书、助教批注和延期记录又在 OnTrack。想查一个再普通不过的问题——这周五到底有什么要交、讲师有没有澄清第三题、助教上周实验留了什么评语——就得切三个标签页,再跟学校单点登录折腾一遍。
做 Learning MCP 把 AI 助手接入这三个平台时,顺着工程师惯性走,最容易想到的是把底层支持的所有接口一股脑全放开。但后来证明,真正立得住的产品路线恰好相反:底层连接器借现成的,写权限一刀切掉,连看起来人畜无害的「读取」接口也要挨个排查隐性副作用,最后再把云端托管能守住什么、守不住什么,老老实实摊开讲清楚。
管道借现成的,产品边界自己扛
如果把接通校园平台纯当成一道写代码的题,你很快就会陷进 Moodle 各种历史遗留 HTML、Ed Discussion 的帖子嵌套和 OnTrack 的任务快照里,光啃协议就能耗掉几周。其实这三个平台早就有现成的 MIT 开源命令行工具:bunizao 写的 edstem-cli、moodle-cli 和 ontrack-cli 已经把这层脏活累活打理得很干净。
真正缺的,是盖在命令行上面的多用户云端产品。本地 CLI 自己坐在电脑前用没问题,可一旦换台设备、在手机上用 AI 助手,或者想直接连一个远程 OAuth MCP 客户端,不想装 Node 也不想三天两头重登校园 Cookie,本地脚本立刻就不好使了。
于是我把这三个上游客户端直接打包进 Workers,精确锁死提交哈希和文件 SHA-256 摘要,每次发布前自动核对生成的 TypeScript 类型声明。省下来的精力全扑在管道之上的产品体验:多用户账号隔离、跨校园 SSO 的静默续期、跨平台统一课程视图,以及一套锁死工具、文件和授权的安全边界。
决定留存的不是第一次登录,而是三天后会不会掉线
写玩具原型时,跑通第一次登录就能开香槟了。做成正经产品才发现,真正把人劝退的从来不是第一次绑定,而是过三天悄悄失效、又得重新扫验证码。
从学生的使用习惯出发,绑定学校账号应当只做一次,而且绝不能把密码打进 AI 对话框里。每次助手需要连新平台,Learning MCP 都会生成一个绑定当前账号、十分钟过期的网页链接,整个登录过程严格停在浏览器里,半个字都不沾聊天记录。整套部署也没有写死任何学校默认地址:第一次绑定时由用户自己填 Moodle 和 OnTrack 的公开 HTTPS 域名,系统把它钉死在账号上;以后想换学校,必须先手动断开,把旧会话和课程关联清干净。
在这层体验底下,我立了一道硬隔离。服务拆成两个 Cloudflare Workers,彼此只靠私有 Service Binding 通信:外层的公开 Worker 负责 Streamable HTTP MCP、OAuth 2.0(含 PKCE 与 resource indicator)和账号页面;内层的私有代理 Worker 独享按用户隔离的 Durable Objects 和独立加密密钥,全权接管 Moodle 和 OnTrack 的登录与续期。
MCP 客户端自己的 OAuth 刷新令牌只能续它和我们服务器之间的授权,帮不了 Moodle 和 OnTrack 续命。所以私有代理里专门做了一层 HTTP 优先的续期逻辑。面对 Moodle,它维护按域名和路径隔离的 Cookie 容器,定期触活会话,拉一次最新仪表盘核对身份、提取新 CSRF 密钥,并防着迟到的旧响应把刚轮换的新 Cookie 冲掉。面对 OnTrack,则用私有刷新 Cookie 换新访问令牌,顺手校验用户名没串号、过期时间合理。只有 HTTP 续期明确被拒(绝不是碰上临时网络抖动或身份不匹配),代理才会退一步拉起串行化的 Cloudflare Browser Run,试着复用已存 SSO Cookie 或用户显式授权的凭据。万一学校弹出手机推送审批、通行密钥或设备校验,系统会直接返回一句人能看懂的报错,绝不在后台傻等死循环。
只读要靠结构锁死,不能指望提示词听话
上游 CLI 的写能力其实很全:交作业、点开并提交 Moodle 测验、在 Ed 论坛回帖、把课件标已读、给 OnTrack 助教发消息。但在 AI 学习工具里开放写权限,这笔账极不划算。帮学生省下点按钮的十秒钟,根本不值得冒模型发懵交掉半成品测验、或者顶着实名发一条莫名其妙回帖的风险。
在系统提示词里写一句「提交前先问用户」算不上安全边界,提示词只是商量,不是权限控制。Learning MCP 直接在能力目录层把写操作连根拔掉:五十多个只读 MCP 工具(涵盖 Ed 课件、幻灯片与帖子,Moodle 截止时间、成绩、反馈、论坛与测验记录,OnTrack 任务书、按课程时区计入延期后的实际截止日与未读数),连同 Zod Schema、TypeScript 契约和后端白名单,全由同一份目录生成,写接口压根就没写进目录里。
跨平台把课程归并到一起时,用的也是同样的稳妥思路。三个平台对同一门课的叫法很少统一:有的把本研合开课写成斜杠组合,有的在后面拼校区缩写,有的学期编号不同。拿标题模糊匹配自动合并,早晚把两门课的大纲挂串。所以我们改成两步走:先拉取各平台最新选课,生成一份加密的十分钟预览,凡是代码或学期对不上的都标成显式提醒;学生看一眼确认无误,再一次性原子提交,同时靠快照校验挡住并发修改。
在强大工具之上做产品,很少是把所有开关统统摊在桌面上,而是让安全的路最好走,并从结构上让不可逆的误操作根本没机会发生。
查一查那些「只读」接口里的隐性副作用
做到后来我才发现,光砍掉明面上的写命令还不够。好几个名字听起来纯读取的上游接口,背后其实会悄悄改服务器状态:
- OnTrack 任务聊天记录:只要拉一次某个任务的聊天消息,系统就会顺手把非讨论类的助教批注标成已读。为了不让 AI 助手帮学生总结本周进度时把未读提醒悄悄清零,我干脆不暴露聊天记录,只从项目快照里读未读数。
- Ed Discussion 课件与幻灯片:默认拉取会触发观看进度统计,问一句「下周课件讲什么」,没看过的课就被标成已学完。所以每次拉取课件和幻灯片都显式关掉了观看追踪。
- 考勤码:查讲师在帖子或 Moodle 公告里发的考勤码,是学生最高频的需求之一,可自动代签又明显越了学术诚信的红线。套件只搜 Ed 和 Moodle 文本,把候选码连同原文直达链接、日期和非全覆盖说明一并返回,提交考勤则彻底禁掉。
只要把 AI 接进传统网页系统,这类暗坑几乎避不开。把「只读」当成逐个接口的实测审计,而不是贴在首页的宣传词,助手才不会在用户看不见的地方到处留脚印。
课程文件和论坛帖子,一律当不可信输入处理
如果学习助手只能读几行标题,那它基本帮不上忙。真正的资料全在 PDF 讲义、幻灯片、Moodle 电子书和附件里。可一旦 AI 工具开始下文件、转述别人写的论坛帖子,攻击面就实打实打开了。
为了把风险兜住,原生 MCP 内嵌二进制资源限制在单文件或单批 16 MiB 以内;Worker 内置的 PDF 文本提取封顶 200 页(单次请求最多 50 页,并明确提醒扫描件和图表还得看原 PDF);同步下来的 Moodle HTML 在只放行 data-image 的内容安全策略下清掉可执行脚本;附件下载只走新发现的链接,对照来源白名单最多允许五次重定向,绝不向外站带平台凭据,残缺截断的响应体直接拒收。
至于论坛帖子和课程页面,一律按不可信文本对待。每条工具返回和报错出站前都要过一遍按请求运行的清洗器,把已知凭据字段、带凭据的 URL 参数和会话密钥全抹掉。二进制附件只能由文件交付辅助函数构造,论坛里有人塞一段精心构造的文本,也不可能靠模仿 JSON 长相冒充附件。
坦诚的威胁模型,比「云端加密」四个字更值钱
最后一道信任关,是怎么跟用户交代凭据存放在哪。云端服务替人保管 OAuth 令牌、校园 Cookie 乃至用户授权的续期凭据时,最偷懒的做法是在官网写一句「全程云端加密」,然后一笔带过。
可懂行的用户只在乎一个问题:对谁加密?把令牌和会话加密存进按用户隔离的 Durable Objects,确实能防数据库裸奔,但运营这套服务的管理员手握密钥,理论上依然解得开。糊弄过去,只要有人翻一遍架构文档,好感立刻归零。
所以 Learning MCP 从一开始就以非商用源码可见许可面向自托管发布。系统在碰任何凭据之前必须走版本化的告知与条款确认;保存密码和验证器密钥默认关闭,且拆成两项独立开关;管理员 CLI 能列出和吊销 OAuth 授权,却永远看不到明文凭据。给用户留的退路也很干脆:点「忘记已保存的登录信息」会清掉密码、验证器密钥和共享 SSO Cookie,但不影响当前正在用的平台会话;真要断开某个平台,则把会话、续期材料和课程关联连根清干净。
把 AI 产品做得让人敢用,很少靠把提示词调得多花哨,靠的是把爆炸半径压到最小、把普通读取里的隐性副作用一个个揪出来,再把信任的边界原原本本讲给用户听。