From b8990fdfc2950431bcf37ec5e28bd79e9f855862 Mon Sep 17 00:00:00 2001 From: Alex Clarke Date: Tue, 7 Jul 2026 15:35:04 -0600 Subject: [PATCH] feat: Added a new oauth.redirectHost field to make it possible to further extend MCP support --- src/main.rs | 1 + src/mcp/mod.rs | 2 ++ src/mcp/oauth.rs | 4 +++- src/repl/mod.rs | 5 +++++ 4 files changed, 11 insertions(+), 1 deletion(-) 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.");