pub struct MCPClient { /* private fields */ }Expand description
An MCP client that provides tools from an MCP server.
Implementations§
Source§impl MCPClient
impl MCPClient
Sourcepub fn new(config: MCPServerConfig) -> Self
pub fn new(config: MCPServerConfig) -> Self
Creates a new MCP client with the given configuration.
Sourcepub fn stdio(
name: impl Into<String>,
command: impl Into<String>,
args: Vec<String>,
) -> Self
pub fn stdio( name: impl Into<String>, command: impl Into<String>, args: Vec<String>, ) -> Self
Creates an MCP client with stdio transport.
Sourcepub fn sse(name: impl Into<String>, url: impl Into<String>) -> Self
pub fn sse(name: impl Into<String>, url: impl Into<String>) -> Self
Creates an MCP client with SSE transport.
Sourcepub fn with_filters(self, filters: ToolFilters) -> Self
pub fn with_filters(self, filters: ToolFilters) -> Self
Sets tool filters for this client.
Sourcepub fn with_prefix(self, prefix: impl Into<String>) -> Self
pub fn with_prefix(self, prefix: impl Into<String>) -> Self
Sets a prefix for tool names.
Sourcepub fn with_timeout(self, timeout_secs: u64) -> Self
pub fn with_timeout(self, timeout_secs: u64) -> Self
Sets the connection timeout.
Sourcepub async fn is_connected(&self) -> bool
pub async fn is_connected(&self) -> bool
Checks if the client is connected.
Sourcepub async fn connection_state(&self) -> ConnectionState
pub async fn connection_state(&self) -> ConnectionState
Returns the current connection state.
Sourcepub async fn connect(&self) -> Result<()>
pub async fn connect(&self) -> Result<()>
Connects to the MCP server and discovers available tools.
Sourcepub async fn disconnect(&self) -> Result<()>
pub async fn disconnect(&self) -> Result<()>
Disconnects from the MCP server.
Trait Implementations§
Source§impl ToolProvider for MCPClient
impl ToolProvider for MCPClient
Source§fn load_tools<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<Arc<dyn AgentTool>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn load_tools<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<Arc<dyn AgentTool>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Loads and returns the tools in this provider.
Source§fn add_consumer(&self, consumer_id: &str)
fn add_consumer(&self, consumer_id: &str)
Adds a consumer to this tool provider.
Source§fn remove_consumer(&self, consumer_id: &str)
fn remove_consumer(&self, consumer_id: &str)
Removes a consumer from this tool provider.
Auto Trait Implementations§
impl !Freeze for MCPClient
impl !RefUnwindSafe for MCPClient
impl Send for MCPClient
impl Sync for MCPClient
impl Unpin for MCPClient
impl !UnwindSafe 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
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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>
Converts
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>
Converts
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 moreCreates a shared type from an unshared type.