Show MCP server failures in the UI instead of debug log
MCP server spawn failures were going to dbglog where the user wouldn't see them. Route through the agent's notify so they appear on the status bar. Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
parent
3e0d52c451
commit
15f3be27ce
2 changed files with 16 additions and 6 deletions
|
|
@ -140,7 +140,7 @@ fn registry() -> &'static TokioMutex<Registry> {
|
|||
})
|
||||
}
|
||||
|
||||
async fn ensure_init() -> Result<()> {
|
||||
async fn ensure_init(agent: Option<&std::sync::Arc<super::super::Agent>>) -> Result<()> {
|
||||
let mut reg = registry().lock().await;
|
||||
if !reg.servers.is_empty() { return Ok(()); }
|
||||
let configs = crate::config::get().mcp_servers.clone();
|
||||
|
|
@ -148,14 +148,24 @@ async fn ensure_init() -> Result<()> {
|
|||
let args: Vec<&str> = cfg.args.iter().map(|s| s.as_str()).collect();
|
||||
match McpServer::spawn(&cfg.name, &cfg.command, &args).await {
|
||||
Ok(server) => reg.servers.push(server),
|
||||
Err(e) => dbglog!("warning: MCP server {} failed: {:#}", cfg.name, e),
|
||||
Err(e) => {
|
||||
let msg = format!("MCP server {} failed: {:#}", cfg.name, e);
|
||||
dbglog!("{}", msg);
|
||||
if let Some(a) = agent {
|
||||
if let Ok(mut st) = a.state.try_lock() {
|
||||
st.notify(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(super) async fn call_tool(name: &str, args: &serde_json::Value) -> Result<String> {
|
||||
ensure_init().await?;
|
||||
pub(super) async fn call_tool(name: &str, args: &serde_json::Value,
|
||||
agent: Option<&std::sync::Arc<super::super::Agent>>,
|
||||
) -> Result<String> {
|
||||
ensure_init(agent).await?;
|
||||
let mut reg = registry().lock().await;
|
||||
let server = reg.servers.iter_mut()
|
||||
.find(|s| s.tools.iter().any(|t| t.name == name))
|
||||
|
|
@ -178,7 +188,7 @@ pub(super) async fn call_tool(name: &str, args: &serde_json::Value) -> Result<St
|
|||
}
|
||||
|
||||
pub(super) async fn tool_definitions_json() -> Vec<String> {
|
||||
let _ = ensure_init().await;
|
||||
let _ = ensure_init(None).await;
|
||||
let reg = registry().lock().await;
|
||||
reg.servers.iter()
|
||||
.flat_map(|s| s.tools.iter())
|
||||
|
|
|
|||
|
|
@ -164,7 +164,7 @@ pub async fn dispatch_with_agent(
|
|||
None => true,
|
||||
};
|
||||
if allowed {
|
||||
if let Ok(result) = mcp_client::call_tool(name, args).await {
|
||||
if let Ok(result) = mcp_client::call_tool(name, args, agent.as_ref()).await {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue