修复: 前端UX一致性(Dashboard状态映射/状态徽章全局/Knowledge下一条与失败反馈/Ideas筛选与错误条/ConfirmDialog安全/快捷菜单状态机/分页越界) + 后端校验(queue/count-list一致/软删拒改/父聚合/promote CAS/MCP状态机收口/update白名单剔除id/created_at) + 销账
This commit is contained in:
@@ -152,13 +152,35 @@ where
|
||||
let resp = dispatch(ctx, config.read_only, req.id.clone(), method).await;
|
||||
write_response(&mut writer, &resp).await?;
|
||||
if let Some(name) = tool_name {
|
||||
fire_write_hook(config, &name);
|
||||
// MC-5(MCP-6):仅业务成功才触发写回调——防业务失败(如 update_project 非法 status、
|
||||
// create_project 空名等 result.isError=true)仍假触发 df-data-changed。
|
||||
if is_success_tool_call(&resp) {
|
||||
fire_write_hook(config, &name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// 判定 tools/call 响应是否为「业务成功」(写回调触发条件)。
|
||||
///
|
||||
/// - JSON-RPC 层 `error` 非空(协议错/未识别方法)→ 失败
|
||||
/// - `result` 内 `isError=true`(MCP 业务错,handler 返 `CallToolResult::error`)→ 失败
|
||||
/// - 其余(正常 result / initialize/ping 等非 tools/call)→ 成功
|
||||
///
|
||||
/// MC-5(MCP-6):stdio(main_loop)与 HTTP(server_http on_tool_call)共用此判定,
|
||||
/// 保证两 transport 对「业务失败不触发写回调」语义一致。
|
||||
pub(crate) fn is_success_tool_call(resp: &Response) -> bool {
|
||||
if resp.error.is_some() {
|
||||
return false;
|
||||
}
|
||||
match &resp.result {
|
||||
Some(v) => !matches!(v.get("isError"), Some(Value::Bool(true))),
|
||||
None => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// 方法分发 → 构造 Response。
|
||||
///
|
||||
/// `id`:JSON-RPC 请求 id(回响应时原样回填;通知由 main_loop 已过滤)。
|
||||
@@ -626,4 +648,31 @@ mod tests {
|
||||
*calls.lock().unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn main_loop_no_write_callback_on_business_failure() {
|
||||
// MC-5(MCP-6):业务失败(handler 返 isError=true)不得触发写回调(防假 df-data-changed)。
|
||||
// create_project 空名(name 为纯空白)→ MC-6 拒空 → isError=true。
|
||||
let ctx = test_ctx().await;
|
||||
let calls: Arc<Mutex<Vec<String>>> = Arc::new(Mutex::new(Vec::new()));
|
||||
let calls_cb = calls.clone();
|
||||
let config = ServerConfig {
|
||||
on_write_call: Some(Arc::new(move |name| {
|
||||
calls_cb.lock().unwrap().push(name.to_string());
|
||||
})),
|
||||
..test_config(false).await
|
||||
};
|
||||
let (mut tx, rx) = tokio::io::duplex(1024);
|
||||
let line = r#"{"jsonrpc":"2.0","id":10,"method":"tools/call","params":{"name":"create_project","arguments":{"name":" ","description":"d"}}}"#;
|
||||
tx.write_all(format!("{line}\n").as_bytes()).await.unwrap();
|
||||
drop(tx);
|
||||
main_loop(rx, tokio::io::sink(), &ctx, &config)
|
||||
.await
|
||||
.unwrap();
|
||||
assert!(
|
||||
calls.lock().unwrap().is_empty(),
|
||||
"业务失败(isError=true)不应触发写回调,实际: {:?}",
|
||||
*calls.lock().unwrap()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user