Skip to content

Commit d977735

Browse files
committed
fix: improve error handling for MCP client initialization and opening with context messages
1 parent df8de85 commit d977735

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/agent/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use crate::tools::web_fetch::WebFetchTool;
2323
use crate::tools::web_search::WebSearchTool;
2424
use crate::tools::write_to_file::WriteToFileTool;
2525
use crate::Config;
26+
use anyhow::Context;
2627
use anyhow::Result;
2728
use futures::StreamExt;
2829
use itertools::Itertools;
@@ -222,14 +223,13 @@ impl Agent {
222223
.unwrap_or(ProtocolVersion::V2025_03_26),
223224
)
224225
.build();
225-
match mcp_client.open().await {
226-
Ok(_) => {}
227-
Err(e) => {
228-
tracing::error!("Failed to open MCP client: {}", e);
229-
continue;
230-
}
231-
}
232-
mcp_client.initialize().await?;
226+
mcp_client
227+
.open()
228+
.await
229+
.with_context(|| format!("Failed to open MCP client at {}", config.url))?;
230+
mcp_client.initialize().await.with_context(|| {
231+
format!("Failed initialize MCP client at {}", config.url)
232+
})?;
233233
let tools_list_res = mcp_client.list_tools(None, None).await?;
234234

235235
agent_builder = tools_list_res

0 commit comments

Comments
 (0)