feat: add User-Agent header to MCP HTTP requests (#6988)
This commit is contained in:
@@ -363,6 +363,9 @@ fn substitute_env_vars(value: &str, env_map: &HashMap<String, String>) -> String
|
|||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const GOOSE_USER_AGENT: reqwest::header::HeaderValue =
|
||||||
|
reqwest::header::HeaderValue::from_static(concat!("goose/", env!("CARGO_PKG_VERSION")));
|
||||||
|
|
||||||
async fn create_streamable_http_client(
|
async fn create_streamable_http_client(
|
||||||
uri: &str,
|
uri: &str,
|
||||||
timeout: Option<u64>,
|
timeout: Option<u64>,
|
||||||
@@ -372,6 +375,9 @@ async fn create_streamable_http_client(
|
|||||||
provider: SharedProvider,
|
provider: SharedProvider,
|
||||||
) -> ExtensionResult<Box<dyn McpClientTrait>> {
|
) -> ExtensionResult<Box<dyn McpClientTrait>> {
|
||||||
let mut default_headers = HeaderMap::new();
|
let mut default_headers = HeaderMap::new();
|
||||||
|
|
||||||
|
default_headers.insert(reqwest::header::USER_AGENT, GOOSE_USER_AGENT);
|
||||||
|
|
||||||
for (key, value) in headers {
|
for (key, value) in headers {
|
||||||
let substituted_value = substitute_env_vars(value, all_envs);
|
let substituted_value = substitute_env_vars(value, all_envs);
|
||||||
default_headers.insert(
|
default_headers.insert(
|
||||||
@@ -405,7 +411,15 @@ async fn create_streamable_http_client(
|
|||||||
let am = oauth_flow(&uri.to_string(), &name.to_string())
|
let am = oauth_flow(&uri.to_string(), &name.to_string())
|
||||||
.await
|
.await
|
||||||
.map_err(|_| ExtensionError::SetupError("auth error".to_string()))?;
|
.map_err(|_| ExtensionError::SetupError("auth error".to_string()))?;
|
||||||
let auth_client = AuthClient::new(reqwest::Client::default(), am);
|
let mut auth_headers = HeaderMap::new();
|
||||||
|
auth_headers.insert(reqwest::header::USER_AGENT, GOOSE_USER_AGENT);
|
||||||
|
let auth_http_client = reqwest::Client::builder()
|
||||||
|
.default_headers(auth_headers)
|
||||||
|
.build()
|
||||||
|
.map_err(|_| {
|
||||||
|
ExtensionError::ConfigError("could not construct http client".to_string())
|
||||||
|
})?;
|
||||||
|
let auth_client = AuthClient::new(auth_http_client, am);
|
||||||
let transport = StreamableHttpClientTransport::with_client(
|
let transport = StreamableHttpClientTransport::with_client(
|
||||||
auth_client,
|
auth_client,
|
||||||
StreamableHttpClientTransportConfig {
|
StreamableHttpClientTransportConfig {
|
||||||
|
|||||||
Reference in New Issue
Block a user