Skip to main content

Module read

Module read 

Source
Expand description

MCP 读作用域工具组(知识库)。

三个 read 作用域工具,均经 Extension<http::request::Parts> 读取鉴权中间件 注入的 McpPrincipal,校验 scope.grants(TokenScope::Read)

  • search_posts:pg_trgm 模糊搜索已发布文章;
  • get_post:按 slug 取单篇已发布文章全文;
  • list_tags:标签 + 关联已发布文章数。

本模块只声明工具路由;server.rs(Main 装配)把 read_router() 合并进 复合 ServerHandler。SQL 与 src/api/posts/{search,read,tags}.rs 的 server-fn 一致,但不复用后者(它们走 cookie 鉴权的 FullstackContext), 这里直接走 crate::db::pool::get_conn()

Structs§

GetPostParams
get_post 入参。
PostResource
get_post 返回的单篇已发布文章(含正文)。
SearchHit
search_posts 命中项(精简,不含正文)。
SearchPostsParams
search_posts 入参。
TagCount
list_tags 返回的标签项。

Functions§

clean_tags 🔒
把行内的标签数组原地清洗(过滤空串),避免二次 Vec 分配。
get_published_by_slug
按 slug 取单篇已发布文章(草稿/已删除返回 None)。
list_all_tags
全部标签 + 各自关联的已发布文章数(镜像 src/api/posts/tags.rs::list_tags)。
mcp_internal 🔒
把内部错误统一包装成 MCP internal_error(带工具名便于排查)。
post_url 🔒
站内文章 URL:/post/{slug}(MCP 不知晓外部域名,给相对路径;客户端可拼接 APP_BASE_URL)。
require_read 🔒
从 request extensions 取 principal 并校验 read 作用域;不足返回 insufficient_scope。
search_published
src/api/posts/search.rs 一致的 pg_trgm word_similarity 查询。