pub struct McpClient { /* private fields */ }Expand description
A connected client. Cheap to clone, and clones share the connection.
Implementations§
Source§impl McpClient
impl McpClient
Sourcepub async fn connect(
options: ClientOptions,
transport: Transport,
) -> Result<McpClient, McpError>
pub async fn connect( options: ClientOptions, transport: Transport, ) -> Result<McpClient, McpError>
Opens transport and performs the initialize handshake.
Sourcepub async fn connect_with_stderr(
options: ClientOptions,
transport: Transport,
) -> Result<McpClient, Box<(McpError, Option<String>)>>
pub async fn connect_with_stderr( options: ClientOptions, transport: Transport, ) -> Result<McpClient, Box<(McpError, Option<String>)>>
McpClient::connect, failing with a stdio server’s stderr too, as
pi reads it for every failed connection.
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Whether the connection is open.
Sourcepub fn server(&self) -> Option<ServerInfo>
pub fn server(&self) -> Option<ServerInfo>
What the server said in initialize.
Sourcepub fn on_notification(
&self,
method: &str,
listener: impl Fn(&Value) + Send + Sync + 'static,
)
pub fn on_notification( &self, method: &str, listener: impl Fn(&Value) + Send + Sync + 'static, )
Calls listener with the parameters of every method notification.
Sourcepub fn on_close(&self, listener: impl Fn() + Send + Sync + 'static)
pub fn on_close(&self, listener: impl Fn() + Send + Sync + 'static)
Calls listener once when the connection closes, for any reason.
Sourcepub async fn request(
&self,
method: &str,
params: Option<Value>,
options: RequestOptions,
) -> Result<Value, McpError>
pub async fn request( &self, method: &str, params: Option<Value>, options: RequestOptions, ) -> Result<Value, McpError>
Sends a request and waits for its result.
Sourcepub async fn list_tools(
&self,
options: RequestOptions,
) -> Result<Vec<Tool>, McpError>
pub async fn list_tools( &self, options: RequestOptions, ) -> Result<Vec<Tool>, McpError>
Every tool, following pagination.
Sourcepub async fn list_resources(
&self,
kind: ResourceKind,
options: RequestOptions,
) -> Result<Vec<Value>, McpError>
pub async fn list_resources( &self, kind: ResourceKind, options: RequestOptions, ) -> Result<Vec<Value>, McpError>
Every resource or resource template, following pagination.
Sourcepub async fn list_resources_page(
&self,
kind: ResourceKind,
cursor: Option<String>,
options: RequestOptions,
) -> Result<(Vec<Value>, Option<String>), McpError>
pub async fn list_resources_page( &self, kind: ResourceKind, cursor: Option<String>, options: RequestOptions, ) -> Result<(Vec<Value>, Option<String>), McpError>
One page of resources or resource templates from cursor, and the
next cursor.
Sourcepub async fn read_resource(
&self,
uri: &str,
options: RequestOptions,
) -> Result<Value, McpError>
pub async fn read_resource( &self, uri: &str, options: RequestOptions, ) -> Result<Value, McpError>
Reads one resource.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for McpClient
impl !UnwindSafe for McpClient
impl Forget for McpClient
impl Freeze for McpClient
impl Send for McpClient
impl Sync for McpClient
impl Unpin for McpClient
impl UnsafeUnpin for McpClient
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