pub struct McpServerManager { /* private fields */ }Expand description
Manages multiple MCP server connections behind interior mutability so
per-server startup tasks can insert as they finish while synchronous
consumers (has_server, all_specs) keep working.
Implementations§
Source§impl McpServerManager
impl McpServerManager
Sourcepub fn new(configs: &HashMap<String, McpServerConfig>) -> Self
pub fn new(configs: &HashMap<String, McpServerConfig>) -> Self
Empty manager pre-seeded with deterministic server-name aliases.
Sourcepub fn alias_for(&self, raw_name: &str) -> String
pub fn alias_for(&self, raw_name: &str) -> String
Sanitized alias for a raw server name (assigned at construction). Falls back to sanitizing on the fly for names outside the config set (defensive; callers always pass configured names).
Sourcepub async fn start_server(
&self,
name: &str,
config: &McpServerConfig,
) -> Result<Vec<McpToolSpec>>
pub async fn start_server( &self, name: &str, config: &McpServerConfig, ) -> Result<Vec<McpToolSpec>>
Spawn + initialize + list_tools for one server, bounded by
[MCP_STARTUP_TIMEOUT]; inserts the runtime and returns the
sanitized specs for the reducer’s Msg::McpServerReady.
Sourcepub fn all_specs(&self) -> Vec<(String, McpToolSpec)>
pub fn all_specs(&self) -> Vec<(String, McpToolSpec)>
All discovered tools as (raw server name, sanitized spec) pairs, cloned out so no lock is held by the caller. Order: server name.
Sourcepub fn has_server(&self, name: &str) -> bool
pub fn has_server(&self, name: &str) -> bool
True iff the named server started and has an active client, even if it advertised zero tools. Accepts raw or sanitized names.
Sourcepub fn has_servers(&self) -> bool
pub fn has_servers(&self) -> bool
Check if any MCP servers are active.
Sourcepub async fn call_tool(
&self,
server: &str,
tool: &str,
arguments: &Value,
) -> Result<McpToolResult>
pub async fn call_tool( &self, server: &str, tool: &str, arguments: &Value, ) -> Result<McpToolResult>
Call a tool on a specific server. server and tool accept
sanitized names (the advertised form) or raw names (an off-script
model echoing a server’s own tool listing still routes).
§Concurrency
Multiple concurrent calls to the same server serialize at the
transport layer (StdioTransport holds a mutex over stdin writes and
uses a shared pending-response map for JSON-RPC correlation). Calls to
different servers run fully in parallel. The registry read lock is
dropped before awaiting the call.
Sourcepub fn format_tool_result(
result: &McpToolResult,
) -> (String, Option<Vec<String>>)
pub fn format_tool_result( result: &McpToolResult, ) -> (String, Option<Vec<String>>)
Convert an MCP tool result into text suitable for a tool result message. Images are returned separately for multimodal attachment. Audio is attached through the same channel — adapters that don’t support audio will silently drop it. Resource links + embedded resources render as text so the model can follow up with another tool call.
Sourcepub async fn shutdown(&self)
pub async fn shutdown(&self)
Gracefully shut down all MCP servers. Sets the shutting-down flag first so straggler startup tasks reap their own clients.
Sourcepub async fn stop_server(&self, name: &str) -> bool
pub async fn stop_server(&self, name: &str) -> bool
Stop a single named server: kill its child via the transport. The
stdout-reader task then exits on EOF — no explicit abort needed. Returns
true if a server matched (raw or sanitized name).
The registry entry lingers, but the client is flagged shut down, so a
later call_tool to a stopped server returns a clean “has been
stopped” error rather than a broken-pipe transport failure.
Auto Trait Implementations§
impl !Freeze for McpServerManager
impl RefUnwindSafe for McpServerManager
impl Send for McpServerManager
impl Sync for McpServerManager
impl Unpin for McpServerManager
impl UnsafeUnpin for McpServerManager
impl UnwindSafe for McpServerManager
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for 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 more