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,
|
url,
|
||||||
spec.oauth.as_ref().and_then(|o| o.client_id.as_deref()),
|
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.callback_port),
|
||||||
|
spec.oauth.as_ref().and_then(|o| o.redirect_host.as_deref()),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
println!("Authentication saved. '{server_name}' is now available for use.");
|
println!("Authentication saved. '{server_name}' is now available for use.");
|
||||||
|
|||||||
@@ -64,6 +64,8 @@ pub(crate) struct McpOAuthConfig {
|
|||||||
pub client_id: Option<String>,
|
pub client_id: Option<String>,
|
||||||
#[serde(rename = "callbackPort", skip_serializing_if = "Option::is_none")]
|
#[serde(rename = "callbackPort", skip_serializing_if = "Option::is_none")]
|
||||||
pub callback_port: Option<u16>,
|
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)]
|
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
|
||||||
|
|||||||
+3
-1
@@ -81,14 +81,16 @@ pub async fn run_mcp_oauth_flow(
|
|||||||
server_url: &str,
|
server_url: &str,
|
||||||
configured_client_id: Option<&str>,
|
configured_client_id: Option<&str>,
|
||||||
callback_port: Option<u16>,
|
callback_port: Option<u16>,
|
||||||
|
redirect_host: Option<&str>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let metadata = discover_oauth_metadata(server_url).await?;
|
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 bind_addr = format!("127.0.0.1:{}", callback_port.unwrap_or(0));
|
||||||
let listener = TcpListener::bind(&bind_addr)?;
|
let listener = TcpListener::bind(&bind_addr)?;
|
||||||
let port = listener.local_addr()?.port();
|
let port = listener.local_addr()?.port();
|
||||||
drop(listener);
|
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 {
|
let client_id = if let Some(id) = configured_client_id {
|
||||||
id.to_string()
|
id.to_string()
|
||||||
|
|||||||
@@ -646,11 +646,16 @@ pub async fn run_repl_command(
|
|||||||
.and_then(|o| o.client_id.as_deref());
|
.and_then(|o| o.client_id.as_deref());
|
||||||
let callback_port =
|
let callback_port =
|
||||||
spec.oauth.as_ref().and_then(|o| o.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(
|
mcp::oauth::run_mcp_oauth_flow(
|
||||||
server_name,
|
server_name,
|
||||||
url,
|
url,
|
||||||
client_id,
|
client_id,
|
||||||
callback_port,
|
callback_port,
|
||||||
|
redirect_host,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
println!("Authentication saved.");
|
println!("Authentication saved.");
|
||||||
|
|||||||
Reference in New Issue
Block a user