pub struct McpConnectionManager { /* private fields */ }Expand description
Manages MCP connections with lifecycle, health checks, and CapabilityRegistry bridging.
McpConnectionManager owns the shared Arc<RwLock<LiveMcpConnection>>
handles. The same Arc is handed to McpCapability instances so that
tool calls go to the correct underlying server without locking the manager
itself.
Cancellation is provided through a tokio::sync::watch channel; call
McpConnectionManager::cancel to signal the health-check loop to stop.
Implementations§
Source§impl McpConnectionManager
impl McpConnectionManager
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Returns true if cancel has been called.
Sourcepub fn subscribe_cancel(&self) -> Receiver<bool>
pub fn subscribe_cancel(&self) -> Receiver<bool>
Returns a new watch::Receiver that fires when the manager is cancelled.
Useful for spawning the health-check loop on a separate task:
let mut cancel = manager.subscribe_cancel();
tokio::spawn(async move {
manager.health_check_loop(registry, interval, cancel).await;
});Sourcepub async fn connect_server(
&self,
config: &McpServerConfig,
registry: &CapabilityRegistry,
) -> Result<usize, McpClientError>
pub async fn connect_server( &self, config: &McpServerConfig, registry: &CapabilityRegistry, ) -> Result<usize, McpClientError>
Connect to a server and register its tools with the CapabilityRegistry.
Returns the number of tools that were registered.
Sourcepub async fn disconnect_server(&self, name: &str, registry: &CapabilityRegistry)
pub async fn disconnect_server(&self, name: &str, registry: &CapabilityRegistry)
Disconnect a server and unregister all its tools from the registry.
Sourcepub async fn connect_all(
&self,
configs: &[McpServerConfig],
registry: &CapabilityRegistry,
)
pub async fn connect_all( &self, configs: &[McpServerConfig], registry: &CapabilityRegistry, )
Connect to all enabled servers in configs, logging warnings for failures.
Sourcepub async fn server_statuses(&self) -> Vec<McpServerStatus>
pub async fn server_statuses(&self) -> Vec<McpServerStatus>
Status snapshot of all managed servers.
Sourcepub async fn connected_count(&self) -> usize
pub async fn connected_count(&self) -> usize
Number of servers whose transport channel is still alive.
Sourcepub async fn total_count(&self) -> usize
pub async fn total_count(&self) -> usize
Total number of registered servers (alive or not).
Sourcepub async fn get_connection(
&self,
name: &str,
) -> Option<Arc<RwLock<LiveMcpConnection>>>
pub async fn get_connection( &self, name: &str, ) -> Option<Arc<RwLock<LiveMcpConnection>>>
Get the shared connection arc for a server, for direct tool dispatch.
Sourcepub async fn health_check_loop(
&self,
registry: &CapabilityRegistry,
interval: Duration,
cancel_rx: Receiver<bool>,
)
pub async fn health_check_loop( &self, registry: &CapabilityRegistry, interval: Duration, cancel_rx: Receiver<bool>, )
Periodically pings all connections and reconnects any that have dropped.
This method runs until cancel is called (or the
provided cancel_rx fires). Intended to be spawned as a background task:
let cancel = manager.subscribe_cancel();
tokio::spawn(async move {
manager.health_check_loop(registry, Duration::from_secs(30), cancel).await;
});Trait Implementations§
Auto Trait Implementations§
impl !Freeze for McpConnectionManager
impl !RefUnwindSafe for McpConnectionManager
impl Send for McpConnectionManager
impl Sync for McpConnectionManager
impl Unpin for McpConnectionManager
impl UnsafeUnpin for McpConnectionManager
impl !UnwindSafe for McpConnectionManager
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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> 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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.