feat: Updated the REPL mcp auth path to use the prettified error messaging
This commit is contained in:
@@ -1,8 +1,9 @@
|
|||||||
use crate::mcp::{
|
use crate::mcp::{
|
||||||
ConnectedServer, JsonField, McpServer, McpTransportType, oauth, spawn_mcp_server,
|
ConnectedServer, JsonField, McpServer, McpTransportType, is_auth_required_error, oauth,
|
||||||
|
spawn_mcp_server,
|
||||||
};
|
};
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::{Result, anyhow};
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
@@ -106,7 +107,18 @@ impl McpFactory {
|
|||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
let handle = spawn_mcp_server(spec, log_path, bearer_token).await?;
|
let handle = spawn_mcp_server(spec, log_path, bearer_token)
|
||||||
|
.await
|
||||||
|
.map_err(|e| {
|
||||||
|
if is_auth_required_error(&e) {
|
||||||
|
anyhow!(
|
||||||
|
"MCP server '{name}' requires OAuth authentication. \
|
||||||
|
Run `coyote --auth-mcp {name}` or `.mcp auth {name}` in the REPL to authenticate."
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
e
|
||||||
|
}
|
||||||
|
})?;
|
||||||
self.insert_active(key, &handle);
|
self.insert_active(key, &handle);
|
||||||
Ok(handle)
|
Ok(handle)
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-3
@@ -287,8 +287,7 @@ impl McpRegistry {
|
|||||||
Err(e) if is_auth_required_error(&e) => {
|
Err(e) if is_auth_required_error(&e) => {
|
||||||
warn!(
|
warn!(
|
||||||
"MCP server '{id}' requires OAuth authentication. \
|
"MCP server '{id}' requires OAuth authentication. \
|
||||||
Run `coyote --auth-mcp {id}` or `.mcp auth {id}` in the REPL to authenticate, \
|
Run `coyote --auth-mcp {id}` or `.mcp auth {id}` in the REPL to authenticate."
|
||||||
then restart Coyote."
|
|
||||||
);
|
);
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
}
|
}
|
||||||
@@ -409,7 +408,7 @@ fn merge_bearer_token(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_auth_required_error(e: &Error) -> bool {
|
pub(crate) fn is_auth_required_error(e: &Error) -> bool {
|
||||||
e.chain()
|
e.chain()
|
||||||
.any(|cause| cause.to_string().contains("Auth required"))
|
.any(|cause| cause.to_string().contains("Auth required"))
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-4
@@ -653,10 +653,7 @@ pub async fn run_repl_command(
|
|||||||
callback_port,
|
callback_port,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
println!(
|
println!("Authentication saved.");
|
||||||
"Authentication saved. \
|
|
||||||
Restart Coyote to connect to '{server_name}'."
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user