fix: MCP preferred version, and http retries (#12066)

This commit is contained in:
Jack Amadeo
2026-09-14 20:35:19 +00:00
committed by GitHub
parent 90bac074db
commit 23dfa080ff
4 changed files with 101 additions and 20 deletions
+1 -3
View File
@@ -75,7 +75,7 @@ use goose_providers::errors::ProviderError;
use goose_providers::thinking::{ThinkingEffort, ThinkingEffortSupport};
use rmcp::model::{
CallToolRequestParams, CallToolResult, ContentBlock, ElicitationAction, ErrorCode, ErrorData,
GetPromptResult, Prompt, ProtocolVersion, Tool,
GetPromptResult, Prompt, Tool,
};
use serde_json::Value;
use tokio::sync::{mpsc, Mutex};
@@ -94,8 +94,6 @@ fn provider_creation_error(error: anyhow::Error, context: impl fmt::Display) ->
error.context(message)
}
pub const MCP_PROTOCOL_VERSION: ProtocolVersion = ProtocolVersion::V_2026_07_28;
fn normalize_legacy_provider_thinking_effort(
mut model_config: goose_providers::model::ModelConfig,
effort_support: &ThinkingEffortSupport,
+95 -15
View File
@@ -5,6 +5,7 @@ use futures::stream::{self, FuturesUnordered, StreamExt};
use futures::Stream;
use futures::{future, FutureExt};
use once_cell::sync::Lazy;
use rmcp::model::ProtocolVersion;
use rmcp::service::{ClientInitializeError, ServiceError};
use rmcp::transport::streamable_http_client::{
StreamableHttpClientTransportConfig, StreamableHttpError,
@@ -766,6 +767,21 @@ pub(crate) fn substitute_env_vars(value: &str, env_map: &HashMap<String, String>
const GOOSE_USER_AGENT: reqwest::header::HeaderValue =
reqwest::header::HeaderValue::from_static(concat!("goose/", env!("CARGO_PKG_VERSION")));
fn should_retry_legacy_after_empty_discover(
result: &Result<McpClient, ClientInitializeError>,
capabilities: &GooseMcpClientCapabilities,
) -> bool {
capabilities.protocol_version.is_none()
&& result.as_ref().is_err_and(|error| {
error.to_string().contains("empty sse stream")
|| matches!(
error,
ClientInitializeError::ConnectionClosed(context)
if context == "discover response"
)
})
}
#[allow(clippy::too_many_arguments)]
async fn connect_with_auth(
auth_manager: rmcp::transport::AuthorizationManager,
@@ -801,20 +817,42 @@ async fn connect_with_auth(
.map_err(|_| ExtensionError::ConfigError("could not construct http client".to_string()))?;
let auth_client = AuthClient::new(auth_http_client, auth_manager);
let transport = StreamableHttpClientTransport::with_client(
auth_client,
auth_client.clone(),
StreamableHttpClientTransportConfig::with_uri(uri),
);
Ok(McpClient::connect(
let mut result = McpClient::connect(
transport,
timeout,
provider,
client_name,
capabilities,
provider.clone(),
client_name.clone(),
capabilities.clone(),
roots_dir.to_path_buf(),
action_required,
extension_manager,
action_required.clone(),
extension_manager.clone(),
)
.await?)
.await;
if should_retry_legacy_after_empty_discover(&result, &capabilities) {
let transport = StreamableHttpClientTransport::with_client(
auth_client,
StreamableHttpClientTransportConfig::with_uri(uri),
);
let mut legacy_capabilities = capabilities;
legacy_capabilities.protocol_version = Some(ProtocolVersion::V_2025_11_25);
result = McpClient::connect(
transport,
timeout,
provider,
client_name,
legacy_capabilities,
roots_dir.to_path_buf(),
action_required,
extension_manager,
)
.await;
}
Ok(result?)
}
/// Connection parameters needed to re-establish an authorized streamable HTTP
@@ -1174,7 +1212,7 @@ async fn create_streamable_http_client(
.map_err(|_| ExtensionError::ConfigError("could not construct http client".to_string()))?;
let transport = StreamableHttpClientTransport::with_client(
http_client,
http_client.clone(),
StreamableHttpClientTransportConfig::with_uri(uri),
);
@@ -1249,7 +1287,7 @@ async fn create_streamable_http_client(
}
}
let client_res = McpClient::connect(
let mut client_res = McpClient::connect(
transport,
timeout_duration,
provider.clone(),
@@ -1261,6 +1299,28 @@ async fn create_streamable_http_client(
)
.await;
// TODO: Remove these compatibility retries, including the authenticated path in
// connect_with_auth, once rmcp handles empty discovery SSE responses upstream.
if should_retry_legacy_after_empty_discover(&client_res, &capabilities) {
let transport = StreamableHttpClientTransport::with_client(
http_client,
StreamableHttpClientTransportConfig::with_uri(uri),
);
let mut legacy_capabilities = capabilities.clone();
legacy_capabilities.protocol_version = Some(ProtocolVersion::V_2025_11_25);
client_res = McpClient::connect(
transport,
timeout_duration,
provider.clone(),
client_name.clone(),
legacy_capabilities,
roots_dir.to_path_buf(),
action_required.clone(),
extension_manager.clone(),
)
.await;
}
if should_attempt_oauth_fallback(&client_res) {
let challenge = auth_challenge_from_result(&client_res);
match oauth_flow_with_challenge(
@@ -1343,23 +1403,43 @@ async fn create_unix_socket_http_client(
custom_headers.insert(header_name, header_value);
}
let config = StreamableHttpClientTransportConfig::with_uri(uri).custom_headers(custom_headers);
let transport = StreamableHttpClientTransport::with_client(unix_client, config);
let config =
StreamableHttpClientTransportConfig::with_uri(uri).custom_headers(custom_headers.clone());
let transport = StreamableHttpClientTransport::with_client(unix_client.clone(), config);
let timeout_duration = Duration::from_secs(resolve_timeout(timeout));
let client_res = McpClient::connect(
let mut client_res = McpClient::connect(
transport,
timeout_duration,
provider.clone(),
client_name.clone(),
capabilities.clone(),
roots_dir.to_path_buf(),
action_required,
extension_manager,
action_required.clone(),
extension_manager.clone(),
)
.await;
if should_retry_legacy_after_empty_discover(&client_res, &capabilities) {
let config =
StreamableHttpClientTransportConfig::with_uri(uri).custom_headers(custom_headers);
let transport = StreamableHttpClientTransport::with_client(unix_client, config);
let mut legacy_capabilities = capabilities;
legacy_capabilities.protocol_version = Some(ProtocolVersion::V_2025_11_25);
client_res = McpClient::connect(
transport,
timeout_duration,
provider.clone(),
client_name.clone(),
legacy_capabilities,
roots_dir.to_path_buf(),
action_required,
extension_manager,
)
.await;
}
if should_attempt_oauth_fallback(&client_res) {
tracing::warn!(
"Extension '{}' returned 401 over Unix domain socket transport; \
+4 -1
View File
@@ -717,7 +717,10 @@ impl McpClient {
.serve_with_lifecycle(
transport,
ClientLifecycleMode::Auto {
preferred_versions: vec![ProtocolVersion::V_2026_07_28],
preferred_versions: vec![
ProtocolVersion::V_2026_07_28,
ProtocolVersion::V_2025_11_25,
],
legacy_version: Some(ProtocolVersion::V_2025_11_25),
},
)
+1 -1
View File
@@ -26,7 +26,7 @@ mod tool_schema_normalize;
pub mod types;
pub mod validate_extensions;
pub use agent::{Agent, AgentConfig, ExtensionLoadResult, GoosePlatform, MCP_PROTOCOL_VERSION};
pub use agent::{Agent, AgentConfig, ExtensionLoadResult, GoosePlatform};
pub use container::Container;
pub use execute_commands::{context_management_unsupported_message, COMPACT_TRIGGERS};
pub use extension::{ExtensionConfig, ExtensionError};