feat: Added a new oauth.redirectHost field to make it possible to further extend MCP support
This commit is contained in:
@@ -163,6 +163,7 @@ async fn main() -> Result<()> {
|
||||
url,
|
||||
spec.oauth.as_ref().and_then(|o| o.client_id.as_deref()),
|
||||
spec.oauth.as_ref().and_then(|o| o.callback_port),
|
||||
spec.oauth.as_ref().and_then(|o| o.redirect_host.as_deref()),
|
||||
)
|
||||
.await?;
|
||||
println!("Authentication saved. '{server_name}' is now available for use.");
|
||||
|
||||
@@ -64,6 +64,8 @@ pub(crate) struct McpOAuthConfig {
|
||||
pub client_id: Option<String>,
|
||||
#[serde(rename = "callbackPort", skip_serializing_if = "Option::is_none")]
|
||||
pub callback_port: Option<u16>,
|
||||
#[serde(rename = "redirectHost", skip_serializing_if = "Option::is_none")]
|
||||
pub redirect_host: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
|
||||
|
||||
+3
-1
@@ -81,14 +81,16 @@ pub async fn run_mcp_oauth_flow(
|
||||
server_url: &str,
|
||||
configured_client_id: Option<&str>,
|
||||
callback_port: Option<u16>,
|
||||
redirect_host: Option<&str>,
|
||||
) -> Result<()> {
|
||||
let metadata = discover_oauth_metadata(server_url).await?;
|
||||
|
||||
let host = redirect_host.unwrap_or("127.0.0.1");
|
||||
let bind_addr = format!("127.0.0.1:{}", callback_port.unwrap_or(0));
|
||||
let listener = TcpListener::bind(&bind_addr)?;
|
||||
let port = listener.local_addr()?.port();
|
||||
drop(listener);
|
||||
let redirect_uri = format!("http://localhost:{port}/callback");
|
||||
let redirect_uri = format!("http://{host}:{port}/callback");
|
||||
|
||||
let client_id = if let Some(id) = configured_client_id {
|
||||
id.to_string()
|
||||
|
||||
@@ -646,11 +646,16 @@ pub async fn run_repl_command(
|
||||
.and_then(|o| o.client_id.as_deref());
|
||||
let callback_port =
|
||||
spec.oauth.as_ref().and_then(|o| o.callback_port);
|
||||
let redirect_host = spec
|
||||
.oauth
|
||||
.as_ref()
|
||||
.and_then(|o| o.redirect_host.as_deref());
|
||||
mcp::oauth::run_mcp_oauth_flow(
|
||||
server_name,
|
||||
url,
|
||||
client_id,
|
||||
callback_port,
|
||||
redirect_host,
|
||||
)
|
||||
.await?;
|
||||
println!("Authentication saved.");
|
||||
|
||||
Reference in New Issue
Block a user