yggdrasil/src/api/mod.rs
xfy 9eac025b3e feat(mcp): 完整工具面 + token 管理 + 管理页(T2-T5 并行实现 + 合并)
T2 token 管理(src/api/mcp_tokens.rs):create/list/reveal/revoke + get_mcp_client_configs
服务端函数,均经 get_current_admin_user 鉴权;TokenLifetime 枚举(1/7/30/90天/永不过期)。
src/mcp/config.rs 生成 4 种客户端配置(Claude Code/Cursor/Cline/通用 + CLI)。
src/pages/admin/mcp.rs 令牌管理页:列表 + 新建表单 + 一次性明文展示/重查 + 撤销 +
配置片段卡片。路由 /admin/mcp,导航项加入 admin_layout。

T3 read 工具 + Resources(tools/read.rs, resources.rs):search_posts/get_post/list_tags
(read 作用域,仅已发布);published-post Resources(post://{slug},游标分页)。
search_published 提取为共享函数。

T4 write 工具(tools/{posts,comments,tags,media}.rs):create/update/publish/trash/delete_post、
评论审核、标签 CRUD、媒体 base64 上传(WebP 转码 + 去重)。复用既有 helper 的 SQL 与
缓存失效(moka + ssr_cache)。write 作用域,可读草稿。

T5 admin 工具(tools/{settings,runner}.rs):get/update_settings、run_code(沙箱执行)。
admin 作用域。

合并(server.rs):用 rmcp tool_router 的「命名路由 + 组合」模式,7 个工具组在
YggMcpServer 上 impl,combined_router 用 + 合并成单一 ServerHandler。各工具组鉴权
独立,经 Extension<Parts> 读 McpPrincipal + scope.grants 校验。

新增依赖 base64 0.22(媒体上传解码)。验证:server/web 双目标编译通过、clippy
--all-features -D warnings 干净、659 单测 + 1 集成全绿(+20 新测试)。
2026-07-28 11:53:32 +08:00

47 lines
1.4 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//! API 层根模块。
//!
//! 按职责划分子模块,包含两类接口:
//! - Dioxus server function`#[server(Name, "/api")]`),如 `auth`、`posts`
//! - Axum 手动路由处理器,如 `upload`、`image`。
/// 认证相关的 Dioxus server function。
pub mod auth;
/// 素材管理assets/asset_refs的 Dioxus server function。
pub mod assets;
/// 代码运行接口与数据结构。
pub mod code_runner;
/// 评论相关接口。
pub mod comments;
/// CSRF 防护中间件。
pub mod csrf;
/// 数据库管理接口(运行状态 / SQL 控制台 / 导出 / 备份恢复)。
pub mod database;
/// 应用错误类型与转换。
pub mod error;
/// 健康检查端点liveness / readiness
pub mod health;
/// 图片服务的 Axum 处理器。
pub mod image;
/// KaTeX 服务端数学公式渲染server-only
#[cfg(feature = "server")]
pub mod katex;
/// MCP 访问令牌管理(签发 / 列表 / 重查 / 撤销)的 Dioxus server function。
pub mod mcp_tokens;
/// Markdown 渲染与 HTML 清理。
pub mod markdown;
/// mhchem 化学公式转译器(\ce/\pu → LaTeXserver-only
#[cfg(feature = "server")]
pub mod mhchem;
/// 文章 CRUD 相关接口。
pub mod posts;
/// 限流工具。
pub mod rate_limit;
/// HTML 消毒器。
pub mod sanitizer;
/// 回收站与站点配置接口。
pub mod settings;
/// URL slug 生成与校验。
pub mod slug;
/// 图片上传的 Axum 处理器。
pub mod upload;