pub struct MockClient { /* private fields */ }Expand description
In-memory MCP client used for plan unit tests. Each tool is registered
with a closure that maps the call arguments to a CallOutcome. The
mock is fully synchronous internally; concurrency is provided by tokio.
Implementations§
Source§impl MockClient
impl MockClient
Sourcepub fn register<F>(self, tool: Tool, handler: F) -> Self
pub fn register<F>(self, tool: Tool, handler: F) -> Self
Registers a tool with a synchronous handler. The handler is invoked
on every call_tool; it can return any CallOutcome variant to
simulate crashes, hangs, or protocol errors.
Sourcepub fn register_async<F, Fut>(self, tool: Tool, handler: F) -> Self
pub fn register_async<F, Fut>(self, tool: Tool, handler: F) -> Self
Registers a tool with an async handler. Useful when testing
cancellation: the handler can await indefinitely and rely on
the caller’s cancellation to drop it.
Sourcepub fn reconnect_count(&self) -> usize
pub fn reconnect_count(&self) -> usize
Returns the number of times reconnect has been invoked.
Trait Implementations§
Source§impl Default for MockClient
impl Default for MockClient
Source§impl McpExec for MockClient
impl McpExec for MockClient
Source§fn list_tools<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<Tool>, ClientError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn list_tools<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<Tool>, ClientError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Lists every tool exposed by the server.
Source§fn call_tool<'life0, 'life1, 'async_trait>(
&'life0 self,
name: &'life1 str,
arguments: Value,
_timeout: Duration,
) -> Pin<Box<dyn Future<Output = CallOutcome> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn call_tool<'life0, 'life1, 'async_trait>(
&'life0 self,
name: &'life1 str,
arguments: Value,
_timeout: Duration,
) -> Pin<Box<dyn Future<Output = CallOutcome> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Calls a tool, applying
timeout. Returns a CallOutcome that the
caller pattern-matches; this method itself never errors.Source§fn reconnect<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), ClientError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn reconnect<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), ClientError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Tears down the transport and rebuilds it. Used after a hang/crash
so subsequent calls can succeed. Concurrent callers see either the
old or the new transport, never a torn state.
Auto Trait Implementations§
impl !Freeze for MockClient
impl RefUnwindSafe for MockClient
impl Send for MockClient
impl Sync for MockClient
impl Unpin for MockClient
impl UnsafeUnpin for MockClient
impl UnwindSafe for MockClient
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
Mutably borrows from an owned value. Read more