pub struct Client<T: Transport> { /* private fields */ }
Expand description
An MCP client for connecting to MCP servers and invoking their tools.
The Client
provides a high-level API for interacting with MCP servers,
including initialization, tool discovery, and tool invocation.
Implementations§
Source§impl<T: Transport> Client<T>
impl<T: Transport> Client<T>
Sourcepub fn builder(transport: T) -> ClientBuilder<T>
pub fn builder(transport: T) -> ClientBuilder<T>
Sourcepub fn set_protocol_version(self, protocol_version: ProtocolVersion) -> Self
pub fn set_protocol_version(self, protocol_version: ProtocolVersion) -> Self
Sourcepub async fn initialize(&self) -> Result<InitializeResponse>
pub async fn initialize(&self) -> Result<InitializeResponse>
Initializes the connection with the MCP server.
This sends the initialize request to the server, negotiates protocol version and capabilities, and establishes the session.
§Returns
A Result
containing the server’s initialization response if successful
Sourcepub async fn assert_initialized(&self) -> Result<(), Error>
pub async fn assert_initialized(&self) -> Result<(), Error>
Checks if the client has been initialized.
§Returns
A Result
indicating if the client is initialized
Sourcepub async fn request(
&self,
method: &str,
params: Option<Value>,
options: RequestOptions,
) -> Result<Value>
pub async fn request( &self, method: &str, params: Option<Value>, options: RequestOptions, ) -> Result<Value>
Sourcepub async fn list_tools(
&self,
cursor: Option<String>,
request_options: Option<RequestOptions>,
) -> Result<ToolsListResponse>
pub async fn list_tools( &self, cursor: Option<String>, request_options: Option<RequestOptions>, ) -> Result<ToolsListResponse>
Sourcepub async fn call_tool(
&self,
name: &str,
arguements: Option<Value>,
) -> Result<CallToolResponse>
pub async fn call_tool( &self, name: &str, arguements: Option<Value>, ) -> Result<CallToolResponse>
Sourcepub async fn list_resources(
&self,
cursor: Option<String>,
request_options: Option<RequestOptions>,
) -> Result<ResourcesListResponse>
pub async fn list_resources( &self, cursor: Option<String>, request_options: Option<RequestOptions>, ) -> Result<ResourcesListResponse>
Sourcepub async fn read_resource(&self, uri: Url) -> Result<Resource>
pub async fn read_resource(&self, uri: Url) -> Result<Resource>
pub async fn subscribe_to_resource(&self, uri: Url) -> Result<()>
pub async fn unsubscribe_to_resource(&self, uri: Url) -> Result<()>
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Client<T>where
T: Freeze,
impl<T> !RefUnwindSafe for Client<T>
impl<T> Send for Client<T>
impl<T> Sync for Client<T>
impl<T> Unpin for Client<T>where
T: Unpin,
impl<T> !UnwindSafe for Client<T>
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