pub struct McpClientCache { /* private fields */ }Expand description
Bounded cache of McpClient instances keyed by the
command-line string. Keeps a Vec of (key, client) pairs
in usage order — most-recently-used at the back. On cache
miss past cap, the front (oldest) entry is dropped.
Why a Vec rather than a HashMap + linked list: cap is
small (16 by default) so linear scan is cheaper than the
pointer chase, and a Vec lets us own the Clients directly
instead of through RefCell/Arc.
Subprocess death is detected lazily: when call_tool fails
the offending entry is dropped. Next call to the same
server respawns. A handler that sits idle long enough for
upstream MCP servers to be killed by ops will see one
Err per server before recovering.
Implementations§
Source§impl McpClientCache
impl McpClientCache
pub fn with_capacity(cap: usize) -> Self
Sourcepub fn call(
&mut self,
server: &str,
tool: &str,
args: Value,
) -> Result<Value, String>
pub fn call( &mut self, server: &str, tool: &str, args: Value, ) -> Result<Value, String>
Send a tools/call to the named server, spawning the
subprocess on cache miss and reusing it on hit. Returns
the server’s result JSON or an error message; on error,
the offending client is dropped so the next call respawns.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Number of cached subprocesses. Useful for tests and observability; not on the hot path.
pub fn is_empty(&self) -> bool
Trait Implementations§
Auto Trait Implementations§
impl Freeze for McpClientCache
impl RefUnwindSafe for McpClientCache
impl Send for McpClientCache
impl Sync for McpClientCache
impl Unpin for McpClientCache
impl UnsafeUnpin for McpClientCache
impl UnwindSafe for McpClientCache
Blanket Implementations§
impl<T> Allocation for T
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> 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