Struct McpRegistry
pub struct McpRegistry { /* private fields */ }Expand description
Registry of all connected MCP servers, with a flat tool index.
Implementations§
Source§impl McpRegistry
impl McpRegistry
Sourcepub async fn connect_all(configs: &[McpServerConfig]) -> Result<Self>
pub async fn connect_all(configs: &[McpServerConfig]) -> Result<Self>
Connect to all configured servers. Non-fatal: failures are logged and skipped.
Sourcepub fn server_handles(&self) -> Vec<(String, McpServer)>
pub fn server_handles(&self) -> Vec<(String, McpServer)>
Snapshot the live (server_name, McpServer) pairs registered
in this registry. Returned pairs are sorted by server_name
for deterministic ordering across ticks. Each McpServer is
a cheap Arc clone of the registered handle — re-inserting it
into another McpRegistry shares the underlying transport
(no disconnect, no new stdio child).
Used by the daemon heartbeat’s additive reconciliation layer
to preserve a healthy live connection across recovery ticks:
when current has a healthy server whose
identity still matches fresh, the daemon re-uses that
handle instead of forcing connect_all to spawn a duplicate
stdio child for the same endpoint.
Sourcepub async fn from_servers(servers: Vec<McpServer>) -> Self
pub async fn from_servers(servers: Vec<McpServer>) -> Self
Build a new registry from a list of pre-existing McpServer
handles. The handles are cheaply Arc-cloned; transports
remain alive across the move. The internal tool_index and
server_index are rebuilt from each handle’s advertised
capabilities (synchronous tools() call).
Companion to Self::server_handles: callers wanting to
carry a healthy live connection into a fresh registry (the
additive recovery path) read the handle via server_handles
and rebuild via from_servers.
Sourcepub fn tool_names(&self) -> Vec<String>
pub fn tool_names(&self) -> Vec<String>
All prefixed tool names across all connected servers.
Sourcepub async fn get_tool_def(&self, prefixed_name: &str) -> Option<McpToolDef>
pub async fn get_tool_def(&self, prefixed_name: &str) -> Option<McpToolDef>
Tool definition for a given prefixed name (cloned).
Sourcepub async fn call_tool(
&self,
prefixed_name: &str,
arguments: Value,
) -> Result<String>
pub async fn call_tool( &self, prefixed_name: &str, arguments: Value, ) -> Result<String>
Execute a tool by prefixed name.
pub fn is_empty(&self) -> bool
pub fn server_count(&self) -> usize
pub fn tool_count(&self) -> usize
Sourcepub fn server_names(&self) -> Vec<String>
pub fn server_names(&self) -> Vec<String>
Names of all connected servers.
Sourcepub fn health_check_all(&self) -> Vec<String>
pub fn health_check_all(&self) -> Vec<String>
Check health of every connected server. Returns names of dead servers.
Sourcepub async fn kill_dead_connections(&mut self) -> Vec<String>
pub async fn kill_dead_connections(&mut self) -> Vec<String>
Remove servers whose transport is dead. Returns the names of servers that were removed.
This is a no-op for the for_test_with_server_count registries used in
unit tests — those have no-op transports that always report alive, so
no server will ever be removed.
Sourcepub fn split_prefixed(prefixed: &str) -> Option<(String, String)>
pub fn split_prefixed(prefixed: &str) -> Option<(String, String)>
Split a <server>__<rest> prefixed name. Returns None if no prefix.
Sourcepub async fn server_supports_resources(&self, name: &str) -> bool
pub async fn server_supports_resources(&self, name: &str) -> bool
Whether the named server advertised resource capability.
Sourcepub async fn server_supports_prompts(&self, name: &str) -> bool
pub async fn server_supports_prompts(&self, name: &str) -> bool
Whether the named server advertised prompt capability.
Sourcepub async fn read_resource(
&self,
prefixed_uri: &str,
) -> Result<McpResourceContents>
pub async fn read_resource( &self, prefixed_uri: &str, ) -> Result<McpResourceContents>
Read a resource by prefixed uri (<server>__<uri>).
Sourcepub async fn get_prompt(
&self,
prefixed_name: &str,
arguments: Value,
) -> Result<McpGetPromptResult>
pub async fn get_prompt( &self, prefixed_name: &str, arguments: Value, ) -> Result<McpGetPromptResult>
Get a prompt by prefixed name (<server>__<name>).
Sourcepub async fn list_server_resources(
&self,
server: &str,
cursor: Option<String>,
) -> Result<(Vec<McpResourceDef>, Option<String>)>
pub async fn list_server_resources( &self, server: &str, cursor: Option<String>, ) -> Result<(Vec<McpResourceDef>, Option<String>)>
List one server’s resources with optional pagination cursor. Returns the
prefixed defs and the server’s next_cursor (if any). The cursor is the
opaque token from a prior page’s next_cursor for this same server.
Sourcepub async fn list_server_prompts(
&self,
server: &str,
cursor: Option<String>,
) -> Result<(Vec<McpPromptDef>, Option<String>)>
pub async fn list_server_prompts( &self, server: &str, cursor: Option<String>, ) -> Result<(Vec<McpPromptDef>, Option<String>)>
List one server’s prompts with optional pagination cursor. Returns the
prefixed defs and the server’s next_cursor (if any).
Sourcepub async fn list_all_resources(&self) -> Vec<(String, McpResourceDef)>
pub async fn list_all_resources(&self) -> Vec<(String, McpResourceDef)>
List resources across all servers that support them. Each entry’s uri is
returned prefixed with <server>__. Per-server errors are skipped.
Sourcepub async fn list_all_prompts(&self) -> Vec<(String, McpPromptDef)>
pub async fn list_all_prompts(&self) -> Vec<(String, McpPromptDef)>
List prompts across all servers that support them, prefixed by server.
Auto Trait Implementations§
impl Freeze for McpRegistry
impl !RefUnwindSafe for McpRegistry
impl Send for McpRegistry
impl Sync for McpRegistry
impl Unpin for McpRegistry
impl UnsafeUnpin for McpRegistry
impl !UnwindSafe for McpRegistry
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<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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