8 Commits

Author SHA1 Message Date
xfy
cc88a7e90a fix(mcp): 修正 Oh-My-Pi 配置格式与路径
三处错误(据 omp 客户端实际报错):
1. 字段名 transport→type,值 streamable-http→http:omp 不识别 transport,
   遇未知字段退化为 stdio 因缺 command 报错丢弃
2. 路径 ~/.pi/agent/mcp.json→.mcp.json / ~/.omp/agent/mcp.json / ~/.mcp.json
3. omp 与 Claude Code 的 JSON 体现完全相同,差异仅在配置文件路径
2026-07-28 16:39:43 +08:00
xfy
3f3bf411ca feat(mcp): 添加 OpenCode 客户端配置(第二位)
OpenCode 用 opencode.json(非 mcp.json),根键 mcp(非 mcpServers),
远程端点 type: remote(非 streamable-http),带 $schema 与 enabled 字段。
来源:2026 opencode.ai 官方文档。同步更新骨架屏形状数组(0..7)。
2026-07-28 16:34:15 +08:00
xfy
2d995d6eaa refactor(mcp): Oh-My-Pi 配置移至首位
将 Oh-My-Pi 客户端配置排在第一,同步调整骨架屏形状数组顺序。
2026-07-28 16:15:23 +08:00
xfy
1b772f4534 feat(mcp): 客户端配置代码块添加语法高亮
将配置片段 DTO 从扁平字段重构为 snippets Vec(含 content/content_html),
高亮在服务端经 highlight_code 完成(JSON 配置用 json 语法,CLI 用 bash),
前端以 dangerous_inner_html 渲染并包 .md-content 匹配 highlight.css 作用域。

补 json/bash 语法解析测试,确认两者均产出彩色 span 而非纯文本回退。
2026-07-28 15:53:20 +08:00
xfy
53376a0373 fix(mcp): 修正 Claude Code / Cursor 客户端配置格式(联网核实 2026)
Some checks failed
CI / check (push) Has been cancelled
CI / build (push) Has been cancelled
依据 2026 官方文档联网核实所有 MCP 客户端配置格式,发现两处错误:

1. Claude Code .mcp.json:type 值应为 "http",不是 "streamable-http"。
   Claude Code 用 streamable-http 会静默失败/卡在 connecting 状态。
2. Cursor ~/.cursor/mcp.json:不应带 type 字段——Cursor 按远程 URL 自动
   识别 streamable-http,仅需 url + headers。此前 cursor_json 直接
   clone claude_code_json,继承了错误的 type 字段。

其余配置核实无误:Cline(streamableHttp 驼峰 + disabled/autoApprove)、
Claude Code CLI(--transport http --header)、Oh-My-Pi(transport 字段)。

改动:
- 拆分 cursor_json,不再 clone claude_code_json
- 更新对应 doc 注释(config.rs / mcp_tokens.rs DTO)
- claude_code 测试断言改为 type=="http"
- cursor_json_equals_claude_code_json → cursor_json_has_no_type_field
2026-07-28 15:10:01 +08:00
xfy
78fb51a310 feat(mcp): 客户端配置新增 Oh-My-Pi 片段
在 /admin/mcp 客户端配置展示区增加 Oh-My-Pi(omp)的 MCP 配置片段,
位于 Cline 与「通用」之间。

Oh-My-Pi 的 mcpServers 条目与 Claude Code/Cursor 的关键差异:字段名
是 transport(而非 type),值仍为 streamable-http,auth 同样走
headers.Authorization。配置文件落在 ~/.pi/agent/mcp.json(全局)或
.pi/mcp.json(项目级)。

改动:
- ClientConfigs / McpClientConfigs 新增 omp_json 字段
- generate_client_configs 生成 omp 片段
- ConfigCard 增加 ConfigSnippet 行
- 新增测试 omp_json_uses_transport_field_not_type,并纳入 pretty 校验循环

格式依据:2026 pi.dev / oh-my-pi 官方文档(联网核实)。
2026-07-28 15:04:33 +08:00
xfy
60360f6b49 fix(mcp): reveal/revoke 令牌时将字符串 id 解析为 Uuid
reveal_mcp_token / revoke_mcp_token 把前端传来的 String id 直接绑到
$1::uuid,tokio-postgres 解析参数类型为 uuid 后拒绝 String,报
'cannot convert between the Rust type String and the Postgres type uuid'
导致 /api/reveal_mcp_token 500。

参照 assets/delete.rs 的做法,绑定前用 uuid::Uuid::parse_str 转换;
解析失败按令牌不存在处理(reveal 返回 None、revoke 静默无操作),
与函数既有的'避免探测'语义一致。
2026-07-28 14:42:14 +08:00
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