Skip to main content

McpServerManager

Struct McpServerManager 

Source
pub struct McpServerManager { /* private fields */ }
Expand description

Manages the lifecycle of one or more MCP servers.

Implementations§

Source§

impl McpServerManager

Source

pub fn new() -> Self

Creates an empty server manager with no registered servers.

Source

pub fn with_namespace(self, namespace: McpToolNamespace) -> Self

Sets the tool naming strategy for every adapter built by this manager.

Source

pub fn set_namespace(&mut self, namespace: McpToolNamespace) -> &mut Self

Replaces the tool naming strategy in place.

Source

pub fn namespace(&self) -> &McpToolNamespace

Returns the active tool naming strategy.

Source

pub fn with_handler_config(self, handler_config: McpHandlerConfig) -> Self

Replaces the McpHandlerConfig applied to every connection this manager opens.

Source

pub fn set_handler_config( &mut self, handler_config: McpHandlerConfig, ) -> &mut Self

Sets the McpHandlerConfig in place.

Source

pub fn handler_config(&self) -> &McpHandlerConfig

Returns the active McpHandlerConfig.

Source

pub fn with_server(self, config: McpServerConfig) -> Self

Registers a server configuration. Returns self for chaining.

Source

pub fn with_server_options( self, config: McpServerConfig, options: McpServerOptions, ) -> Self

Registers a server configuration with lifecycle options. Returns self for chaining.

Source

pub fn register_server(&mut self, config: McpServerConfig) -> &mut Self

Registers a server configuration by mutable reference.

Source

pub fn register_server_with_options( &mut self, config: McpServerConfig, options: McpServerOptions, ) -> &mut Self

Registers a server configuration and lifecycle options by mutable reference.

Source

pub fn connected_server( &self, server_id: &McpServerId, ) -> Option<&McpServerHandle>

Returns the handle for a connected server, or None if not connected.

Source

pub fn connected_servers(&self) -> Vec<&McpServerHandle>

Returns handles for all currently connected servers.

Source

pub fn subscribe_catalog_events(&self) -> Receiver<McpCatalogEvent>

Subscribes to MCP catalog and lifecycle events.

Source

pub async fn connect_server( &mut self, server_id: &McpServerId, ) -> Result<McpServerHandle, McpError>

Connects a single registered server by its identifier.

Source

pub async fn connect_all(&mut self) -> Result<Vec<McpServerHandle>, McpError>

Connects all registered servers concurrently.

Source

pub async fn connect_all_settled(&mut self) -> McpConnectAllSettled

Connects all registered servers concurrently and waits for every connection attempt to settle.

Unlike Self::connect_all, this method does not fail fast. Every server is attempted in parallel; successful connections are installed into the manager and tool catalog, while each failed connection is returned with its McpServerId and McpError.

Source

pub async fn refresh_server( &mut self, server_id: &McpServerId, ) -> Result<McpDiscoverySnapshot, McpError>

Re-discovers capabilities for a connected server.

Source

pub async fn refresh_changed_catalogs( &mut self, ) -> Result<Vec<McpCatalogEvent>, McpError>

Processes pending server list-change notifications.

Source

pub async fn disconnect_server( &mut self, server_id: &McpServerId, ) -> Result<(), McpError>

Disconnects a server and removes it from active connections.

Source

pub async fn resolve_auth( &mut self, resolution: AuthResolution, ) -> Result<(), McpError>

Stores or clears authentication credentials for a server.

Source

pub fn tool_registry(&self) -> ToolRegistry

Builds a one-shot snapshot ToolRegistry of every tool across all connected servers. Use source instead when wiring the manager into an [agentkit_loop::Agent] so tool catalog changes flow through automatically.

Source

pub fn source(&self) -> CatalogReader

Returns the manager’s federated CatalogReader.

The manager keeps an internal CatalogWriter in sync with every connect, disconnect, and catalog refresh; the returned reader sees the added/removed/changed tool sets via [ToolSource::drain_catalog_events]. Pass it to [agentkit_loop::AgentBuilder::tools] alongside any frozen native ToolRegistry.

Each call returns a fresh reader subscription — events emitted before this call are not replayed. Call once at agent setup time and reuse.

Source

pub fn capability_provider(&self) -> McpCapabilityProvider

Builds a combined McpCapabilityProvider from all connected servers.

Trait Implementations§

Source§

impl Default for McpServerManager

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more