From af344b70876d0f26ff91e44decafdb9d9d290371 Mon Sep 17 00:00:00 2001 From: oudecheng <13802883547@139.com> Date: Mon, 17 Aug 2026 15:52:34 +0800 Subject: [PATCH] =?UTF-8?q?perf(mcp):=20=E5=A2=9E=E5=8A=A0=20tool=20?= =?UTF-8?q?=E8=B0=83=E7=94=A8=E5=85=A8=E9=93=BE=E8=B7=AF=E5=BE=80=E8=BF=94?= =?UTF-8?q?=E8=80=97=E6=97=B6=20debug=20=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 记录 roundtrip_ms(含 stdio 传输 + server 派发 + 工具执行 + 回传), 与 server 侧 duration_ms 对比可定位慢在哪一段。 --- src/mcp/tool_adapter.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/mcp/tool_adapter.rs b/src/mcp/tool_adapter.rs index 9e483c4..32498c1 100644 --- a/src/mcp/tool_adapter.rs +++ b/src/mcp/tool_adapter.rs @@ -100,6 +100,7 @@ impl PicoBotTool for McpToolWrapper { } async fn execute(&self, args: serde_json::Value) -> anyhow::Result { + let mcp_start = std::time::Instant::now(); tracing::debug!( server_key = %self.server_key, tool = %self.tool_name, @@ -131,6 +132,15 @@ impl PicoBotTool for McpToolWrapper { 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 let output = extract_text_content(&result); let is_error = result.is_error.unwrap_or(false);