perf(mcp): 增加 tool 调用全链路往返耗时 debug 日志

记录 roundtrip_ms(含 stdio 传输 + server 派发 + 工具执行 + 回传),
与 server 侧 duration_ms 对比可定位慢在哪一段。
This commit is contained in:
oudecheng 2026-08-17 15:52:34 +08:00
parent 8a4799656c
commit af344b7087

View File

@ -100,6 +100,7 @@ impl PicoBotTool for McpToolWrapper {
} }
async fn execute(&self, args: serde_json::Value) -> anyhow::Result<ToolResult> { async fn execute(&self, args: serde_json::Value) -> anyhow::Result<ToolResult> {
let mcp_start = std::time::Instant::now();
tracing::debug!( tracing::debug!(
server_key = %self.server_key, server_key = %self.server_key,
tool = %self.tool_name, tool = %self.tool_name,
@ -131,6 +132,15 @@ impl PicoBotTool for McpToolWrapper {
call.await? call.await?
}; };
// MCP 全链路往返耗时(含 stdio 传输 + server 派发 + 工具执行 + 回传)。
// 与 server 侧 wrapper 进入时间戳、结果内 duration_ms 对比可定位慢在哪一段。
tracing::debug!(
server_key = %self.server_key,
tool = %self.tool_name,
roundtrip_ms = mcp_start.elapsed().as_millis() as u64,
"MCP tool call finished"
);
// Convert MCP CallToolResult to PicoBot ToolResult // Convert MCP CallToolResult to PicoBot ToolResult
let output = extract_text_content(&result); let output = extract_text_content(&result);
let is_error = result.is_error.unwrap_or(false); let is_error = result.is_error.unwrap_or(false);