mirror of
https://github.com/openai/codex.git
synced 2026-11-23 23:10:47 +00:00
Box MCP transport setup and initialization retry futures (#63356)
## Why MCP startup and connection recovery both create transports and run the initialization handshake. They can share the same future polling code. ## What changed Return a `BoxFuture` from transport creation and box the entire initialization retry loop once per call. Startup and recovery use the same polling implementations in `rmcp-client`. GitOrigin-RevId: 582318654ed1d519a4cf25a09126a5a5b93a4b4e
This commit is contained in:
@@ -1430,7 +1430,14 @@ impl RmcpClient {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn create_pending_transport(
|
||||
// Keep the transport future's polling code in this crate for both startup and recovery.
|
||||
fn create_pending_transport(
|
||||
transport_recipe: &TransportRecipe,
|
||||
) -> BoxFuture<'_, Result<PendingTransport>> {
|
||||
Box::pin(Self::create_pending_transport_inner(transport_recipe))
|
||||
}
|
||||
|
||||
async fn create_pending_transport_inner(
|
||||
transport_recipe: &TransportRecipe,
|
||||
) -> Result<PendingTransport> {
|
||||
match transport_recipe {
|
||||
|
||||
@@ -5,6 +5,7 @@ use std::time::Instant;
|
||||
use anyhow::Result;
|
||||
use anyhow::anyhow;
|
||||
use codex_exec_server::ExecServerError;
|
||||
use futures::future::BoxFuture;
|
||||
use http::StatusCode;
|
||||
use rmcp::service::RoleClient;
|
||||
use rmcp::service::RunningService;
|
||||
@@ -23,15 +24,26 @@ use super::RmcpClient;
|
||||
const JSON_RPC_INTERNAL_ERROR_CODE: i64 = -32603;
|
||||
pub(super) const STREAMABLE_HTTP_RETRY_DELAYS_MS: [u64; 2] = [250, 1_000];
|
||||
|
||||
type InitializedConnection = (
|
||||
Arc<RunningService<RoleClient, ElicitationClientService>>,
|
||||
Option<OAuthRuntime>,
|
||||
);
|
||||
|
||||
impl RmcpClient {
|
||||
pub(super) async fn connect_pending_transport_with_initialize_retries(
|
||||
// Box the entire retry loop once so startup and recovery share the handshake code.
|
||||
pub(super) fn connect_pending_transport_with_initialize_retries<'a>(
|
||||
&'a self,
|
||||
initial_transport: PendingTransport,
|
||||
initialize_context: &'a InitializeContext,
|
||||
) -> BoxFuture<'a, Result<InitializedConnection>> {
|
||||
Box::pin(self.connect_with_retries(initial_transport, initialize_context))
|
||||
}
|
||||
|
||||
async fn connect_with_retries(
|
||||
&self,
|
||||
initial_transport: PendingTransport,
|
||||
initialize_context: &InitializeContext,
|
||||
) -> Result<(
|
||||
Arc<RunningService<RoleClient, ElicitationClientService>>,
|
||||
Option<OAuthRuntime>,
|
||||
)> {
|
||||
) -> Result<InitializedConnection> {
|
||||
let timeout = initialize_context.timeout;
|
||||
let should_retry = match &initial_transport {
|
||||
PendingTransport::InProcess { .. } | PendingTransport::Stdio { .. } => false,
|
||||
|
||||
Reference in New Issue
Block a user