diff --git a/src/main.rs b/src/main.rs index 7d0f36f..c6c68be 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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."); diff --git a/src/mcp/mod.rs b/src/mcp/mod.rs index 710f641..6d8bb49 100644 --- a/src/mcp/mod.rs +++ b/src/mcp/mod.rs @@ -64,6 +64,8 @@ pub(crate) struct McpOAuthConfig { pub client_id: Option, #[serde(rename = "callbackPort", skip_serializing_if = "Option::is_none")] pub callback_port: Option, + #[serde(rename = "redirectHost", skip_serializing_if = "Option::is_none")] + pub redirect_host: Option, } #[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)] diff --git a/src/mcp/oauth.rs b/src/mcp/oauth.rs index b62d6c6..e40e0c5 100644 --- a/src/mcp/oauth.rs +++ b/src/mcp/oauth.rs @@ -81,14 +81,16 @@ pub async fn run_mcp_oauth_flow( server_url: &str, configured_client_id: Option<&str>, callback_port: Option, + 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() diff --git a/src/repl/mod.rs b/src/repl/mod.rs index 10ca56b..ecd1b56 100644 --- a/src/repl/mod.rs +++ b/src/repl/mod.rs @@ -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.");