Conversation
… agents Register 8 tools on document.modelContext so browser-integrated AI agents can search and read posts, navigate the site, and read comments without DOM scraping. - content: search-posts, get-post (backed by build-time /search-index.json) - navigation: get-page-context, navigate-to-post, goto-section - comments: list-comments, check-comment-auth, draft-comment Safety boundaries: - navigate-to-post uses a route allowlist, so /keystatic and /api are excluded by construction; prefix matching rejects /postsevil-style confusions - draft-comment only fills the existing textarea and scrolls to it — publishing to GitHub Issues stays a user action - client code re-implements commentKey() instead of importing @/lib/comments, which transitively pulls server-only env readers into the browser bundle Progressive enhancement: BaseLayout ships a 229-byte feature check; the 12KB tool chunk loads via dynamic import only when a WebMCP host exists, and the search index is fetched only on first content-tool use. Browsers without WebMCP are untouched. Origin trial token comes from PUBLIC_WEBMCP_ORIGIN_TRIAL_TOKEN; unset emits no meta tag. Register at https://developer.chrome.com/origintrials before deploying.
✅ Deploy Preview for priority-me ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
priority3
force-pushed
the
feat/webmcp-tools
branch
from
August 29, 2026 00:13
4b68283 to
da01d0f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
把站点能力以 WebMCP 工具形式注册到
document.modelContext,让浏览器内置 AI agent 不用靠 DOM 抓取就能检索文章、导航站点、读评论。规划文档在
.trellis/tasks/08-28-webmcp-tools/(prd / design / implement)。8 个工具
search-postsget-post/search-index.jsonget-page-contextnavigate-to-postgoto-sectionlocation、.prose h2-h4[id]list-commentscheck-comment-authdraft-comment/api/comments、[data-comments-input]三条安全边界
navigate-to-post用路由白名单,/keystatic和/api是「构造上排除」而非显式封禁。前缀匹配是=== prefix || startsWith(prefix + '/'),所以/postsevil这类混淆会被拒。draft-comment只填草稿不提交 —— 发评论会以访客自己的 GitHub 身份不可逆地写入 Issue。工具把文本填进现有 textarea、滚动聚焦,然后交还给用户点「发表评论」。@/lib/comments—— 它看着是一堆纯函数,实际会传递依赖到@/lib/github和@/lib/comments-token(读 server env)。所以page-context.ts里重写了commentKey(),这个重复是刻意的,已在 spec 里标注同步要求。渐进增强
BaseLayout只多了 7 行。首屏仅 229 bytes 的特性检测;12KB 工具代码走动态import(),只有存在 WebMCP 宿主时才下载;搜索索引更晚,首次内容工具调用时才 fetch。不支持 WebMCP 的浏览器完全不受影响。已验证
pnpm checkpnpm builddist/search-index.json15 篇 / 34KB//evil.example、javascript:、/keystatic、/postsevil),7 项合法路径全放行findPost、display:false不可检索origin-trialmeta;评论区data-*钩子完好索引是 15 篇不是 16 ——
toy-record.md带display: false被正确排除。顺带发现:posts/[...slug].astro用的是未过滤的getCollection,所以隐藏文章仍会生成页面,只是不进列表和索引。已写进 spec。draft-comment不提交表单这条只做了静态检查(grep确认代码里没有submit()/requestSubmit()/.click()),没有浏览器实测。工具的实际调用需要 Chrome 149+ 带 origin trial token 或 flag,或 ChatGPT Desktop。需要实测的清单:
(await document.modelContext.getTools()).map(t => t.name)列出 8 个工具search-posts({ query: 'vue' })命中vue3-contributionnavigate-to-post({ path: 'https://evil.example' })被拒draft-comment({ text: '测试' })后文本入框、滚动到评论区、GitHub 无新增评论注意 deploy preview 的域名(
deploy-preview-N--*.netlify.app)与 origin trial token 绑定的razet.me不匹配,所以 preview 上只能用带 flag 的 Chrome 测。前置项(合并后)
razet.me注册 WebMCP trialPUBLIC_WEBMCP_ORIGIN_TRIAL_TOKEN未完成这些也可以合并 —— 不配 token 就不输出 meta 标签,工具保持休眠,站点不受影响。
回滚
从
BaseLayout.astro删掉<WebMcp />和 origin-trial meta 两行即完全禁用,其余文件成为死代码,不影响运行。