pub struct ConnectionRefresher<S, F>{ /* private fields */ }Expand description
Connection refresher that wraps an MCP client and handles automatic reconnection.
This is similar to adk-go’s connectionRefresher struct. It transparently
retries operations after reconnecting when the underlying session fails.
§Type Parameters
S- The service type for the MCP clientF- The factory type for creating new connections
§Example
use adk_tool::mcp::{ConnectionRefresher, ConnectionFactory};
struct MyFactory { /* ... */ }
#[async_trait::async_trait]
impl ConnectionFactory<MyService> for MyFactory {
async fn create_connection(&self) -> Result<RunningService<RoleClient, MyService>, String> {
// Create and return a new connection
}
}
let refresher = ConnectionRefresher::new(initial_client, Arc::new(factory));
// Operations automatically retry on connection failure
let tools = refresher.list_tools().await?;
let result = refresher.call_tool(params).await?;Implementations§
Source§impl<S, F> ConnectionRefresher<S, F>
impl<S, F> ConnectionRefresher<S, F>
Sourcepub fn new(client: RunningService<RoleClient, S>, factory: Arc<F>) -> Self
pub fn new(client: RunningService<RoleClient, S>, factory: Arc<F>) -> Self
Create a new connection refresher with an initial client and factory.
§Arguments
client- The initial MCP client connectionfactory- Factory for creating new connections when needed
Sourcepub fn lazy(factory: Arc<F>) -> Self
pub fn lazy(factory: Arc<F>) -> Self
Create a new connection refresher without an initial connection.
The first operation will trigger a connection.
Sourcepub fn with_config(self, config: RefreshConfig) -> Self
pub fn with_config(self, config: RefreshConfig) -> Self
Set the refresh configuration.
Sourcepub fn with_max_attempts(self, attempts: u32) -> Self
pub fn with_max_attempts(self, attempts: u32) -> Self
Set the maximum number of reconnection attempts.
Sourcepub async fn list_tools(&self) -> Result<RetryResult<Vec<McpTool>>, String>
pub async fn list_tools(&self) -> Result<RetryResult<Vec<McpTool>>, String>
List all tools from the MCP server with automatic reconnection.
Handles pagination internally and restarts from scratch if reconnection occurs (per MCP spec, cursors don’t persist across sessions).
Sourcepub async fn call_tool(
&self,
params: CallToolRequestParams,
) -> Result<RetryResult<CallToolResult>, String>
pub async fn call_tool( &self, params: CallToolRequestParams, ) -> Result<RetryResult<CallToolResult>, String>
Call a tool on the MCP server with automatic reconnection.
Sourcepub async fn cancellation_token(
&self,
) -> Option<RunningServiceCancellationToken>
pub async fn cancellation_token( &self, ) -> Option<RunningServiceCancellationToken>
Get the cancellation token for the current connection.
Sourcepub async fn is_connected(&self) -> bool
pub async fn is_connected(&self) -> bool
Check if currently connected.
Auto Trait Implementations§
impl<S, F> Freeze for ConnectionRefresher<S, F>
impl<S, F> !RefUnwindSafe for ConnectionRefresher<S, F>
impl<S, F> Send for ConnectionRefresher<S, F>
impl<S, F> Sync for ConnectionRefresher<S, F>
impl<S, F> Unpin for ConnectionRefresher<S, F>
impl<S, F> UnsafeUnpin for ConnectionRefresher<S, F>
impl<S, F> !UnwindSafe for ConnectionRefresher<S, F>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request