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 体现完全相同,差异仅在配置文件路径
This commit is contained in:
xfy 2026-07-28 16:39:43 +08:00
parent 3f3bf411ca
commit cc88a7e90a
2 changed files with 13 additions and 10 deletions

View File

@ -306,7 +306,7 @@ pub async fn get_mcp_client_configs(token: String) -> Result<McpClientConfigs, S
); );
// (标题, 内容, 语言)JSON 配置用 json 语法高亮CLI 一行命令用 bash。 // (标题, 内容, 语言)JSON 配置用 json 语法高亮CLI 一行命令用 bash。
let entries: [(&str, String, &str); 7] = [ let entries: [(&str, String, &str); 7] = [
("Oh-My-Pi~/.pi/agent/mcp.json 或 .pi/mcp.json", c.omp_json, "json"), ("Oh-My-Pi项目根 .mcp.json / ~/.omp/agent/mcp.json 或 ~/.mcp.json", c.omp_json, "json"),
("OpenCode~/.config/opencode/opencode.json 或项目根 opencode.json", c.opencode_json, "json"), ("OpenCode~/.config/opencode/opencode.json 或项目根 opencode.json", c.opencode_json, "json"),
("Claude Code.mcp.json / ~/.claude.json", c.claude_code_json, "json"), ("Claude Code.mcp.json / ~/.claude.json", c.claude_code_json, "json"),
("Cursor~/.cursor/mcp.json", c.cursor_json, "json"), ("Cursor~/.cursor/mcp.json", c.cursor_json, "json"),

View File

@ -25,8 +25,9 @@ pub struct ClientConfigs {
/// Cline`cline_mcp_settings.json`)。`type: "streamableHttp"`(注意驼峰,非 `sse` /// Cline`cline_mcp_settings.json`)。`type: "streamableHttp"`(注意驼峰,非 `sse`
/// 额外带 `disabled` / `autoApprove` 字段。 /// 额外带 `disabled` / `autoApprove` 字段。
pub cline_json: String, pub cline_json: String,
/// Oh-My-Pi`~/.pi/agent/mcp.json` 全局 / `.pi/mcp.json` 项目级)。与其它客户端的 /// Oh-My-Pi项目根 `.mcp.json` / 全局 `~/.omp/agent/mcp.json` 或 `~/.mcp.json`)。
/// 关键差异:字段名是 `transport`(而非 `type`),值仍为 `streamable-http`。 /// omp 的协议字段是 `type: "http"`(与 Claude Code 同形),**不识别** `transport` /
/// `streamable-http`——后者会让 omp 退化为 stdio 并因缺 `command` 字段报错丢弃。
pub omp_json: String, pub omp_json: String,
/// OpenCode`opencode.json` 全局 `~/.config/opencode/opencode.json` / 项目根)。 /// OpenCode`opencode.json` 全局 `~/.config/opencode/opencode.json` / 项目根)。
/// 关键差异schema 根键是 `mcp`(非 `mcpServers`),远程端点用 `type: "remote"` /// 关键差异schema 根键是 `mcp`(非 `mcpServers`),远程端点用 `type: "remote"`
@ -91,12 +92,13 @@ pub fn generate_client_configs(base_url: &str, token: &str) -> ClientConfigs {
} }
} }
}); });
// --- Oh-My-Pitype = "http"(与 Claude Code 同形。omp 不识别 transport/streamable-http
// --- Oh-My-Pi字段名是 transport非 type值仍为 streamable-http --- // 遇未知字段会退化为 stdio 并因缺 command 报错丢弃。与 Claude Code 的 JSON 体相同,
// 差异仅在配置文件路径(见上方字段文档)。
let omp_json = serde_json::json!({ let omp_json = serde_json::json!({
"mcpServers": { "mcpServers": {
SERVER_NAME: { SERVER_NAME: {
"transport": "streamable-http", "type": "http",
"url": mcp_url, "url": mcp_url,
"headers": { "Authorization": auth_header } "headers": { "Authorization": auth_header }
} }
@ -215,13 +217,14 @@ mod tests {
} }
#[test] #[test]
fn omp_json_uses_transport_field_not_type() { fn omp_json_uses_type_http_not_transport() {
let cfg = generate_client_configs(BASE, TOKEN); let cfg = generate_client_configs(BASE, TOKEN);
let v: serde_json::Value = serde_json::from_str(&cfg.omp_json).unwrap(); let v: serde_json::Value = serde_json::from_str(&cfg.omp_json).unwrap();
let entry = &v["mcpServers"]["yggdrasil"]; let entry = &v["mcpServers"]["yggdrasil"];
// 关键差异:字段名是 transport非 type // omp 协议字段是 type: "http"(与 Claude Code 同形)。
assert_eq!(entry["transport"], "streamable-http"); assert_eq!(entry["type"], "http");
assert!(entry.get("type").is_none(), "omp 配置不应含 type 字段"); // 不应含 transport 字段——会让 omp 退化为 stdio 报错。
assert!(entry.get("transport").is_none(), "omp 配置不应含 transport 字段");
assert_eq!(entry["url"], "https://rua.plus/mcp"); assert_eq!(entry["url"], "https://rua.plus/mcp");
assert_eq!(entry["headers"]["Authorization"], format!("Bearer {TOKEN}")); assert_eq!(entry["headers"]["Authorization"], format!("Bearer {TOKEN}"));
} }