pub struct BaseMCPClient<P> {
pub params: P,
/* private fields */
}Expand description
MCP客户端基础实现 / Base MCP client implementation
Fields§
§params: P服务器参数 / Server parameters
Implementations§
Source§impl<P> BaseMCPClient<P>
impl<P> BaseMCPClient<P>
Sourcepub fn set_state_change_callback<F>(&mut self, callback: F)
pub fn set_state_change_callback<F>(&mut self, callback: F)
设置状态变化回调 / Set state change callback
Sourcepub async fn get_state(&self) -> ClientState
pub async fn get_state(&self) -> ClientState
获取当前状态 / Get current state
Sourcepub fn get_state_notifier(&self) -> Receiver<ClientState>
pub fn get_state_notifier(&self) -> Receiver<ClientState>
获取状态变化通知器 / Get state change notifier
Sourcepub async fn update_state(&self, new_state: ClientState)
pub async fn update_state(&self, new_state: ClientState)
更新状态 / Update state
Sourcepub async fn can_connect(&self) -> bool
pub async fn can_connect(&self) -> bool
检查是否可以连接 / Check if can connect
Sourcepub async fn can_disconnect(&self) -> bool
pub async fn can_disconnect(&self) -> bool
检查是否可以断开 / Check if can disconnect
Trait Implementations§
Source§impl<P> MCPClientProtocol for BaseMCPClient<P>
impl<P> MCPClientProtocol for BaseMCPClient<P>
Source§fn state(&self) -> ClientState
fn state(&self) -> ClientState
获取客户端状态 / Get client state
Source§fn connect<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), MCPClientError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn connect<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), MCPClientError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
连接MCP服务器 / Connect to MCP server
Source§fn disconnect<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), MCPClientError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn disconnect<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), MCPClientError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
断开连接 / Disconnect
Source§fn list_tools<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<Tool>, MCPClientError>> + 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>, MCPClientError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
获取可用工具列表 / Get available tools list
Source§fn call_tool<'life0, 'life1, 'async_trait>(
&'life0 self,
_tool_name: &'life1 str,
_params: Value,
) -> Pin<Box<dyn Future<Output = Result<CallToolResult, MCPClientError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn call_tool<'life0, 'life1, 'async_trait>(
&'life0 self,
_tool_name: &'life1 str,
_params: Value,
) -> Pin<Box<dyn Future<Output = Result<CallToolResult, MCPClientError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
调用工具 / Call tool
Source§fn list_windows<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<Resource>, MCPClientError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn list_windows<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<Resource>, MCPClientError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
列出窗口资源 / List window resources
Source§fn get_window_detail<'life0, 'async_trait>(
&'life0 self,
_resource: Resource,
) -> Pin<Box<dyn Future<Output = Result<ReadResourceResult, MCPClientError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn get_window_detail<'life0, 'async_trait>(
&'life0 self,
_resource: Resource,
) -> Pin<Box<dyn Future<Output = Result<ReadResourceResult, MCPClientError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
获取窗口详情 / Get window detail
Source§fn subscribe_window<'life0, 'async_trait>(
&'life0 self,
_resource: Resource,
) -> Pin<Box<dyn Future<Output = Result<(), MCPClientError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn subscribe_window<'life0, 'async_trait>(
&'life0 self,
_resource: Resource,
) -> Pin<Box<dyn Future<Output = Result<(), MCPClientError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
订阅窗口资源更新 / Subscribe to window resource updates
Source§fn unsubscribe_window<'life0, 'async_trait>(
&'life0 self,
_resource: Resource,
) -> Pin<Box<dyn Future<Output = Result<(), MCPClientError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn unsubscribe_window<'life0, 'async_trait>(
&'life0 self,
_resource: Resource,
) -> Pin<Box<dyn Future<Output = Result<(), MCPClientError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
取消订阅窗口资源更新 / Unsubscribe from window resource updates
Source§fn health_check<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = HealthCheckResult> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn health_check<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = HealthCheckResult> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
执行健康检查 / Perform health check
默认实现通过检查状态和尝试 list_tools 来验证连接
Default implementation checks state and tries list_tools to verify connection
Auto Trait Implementations§
impl<P> Freeze for BaseMCPClient<P>where
P: Freeze,
impl<P> !RefUnwindSafe for BaseMCPClient<P>
impl<P> Send for BaseMCPClient<P>where
P: Send,
impl<P> Sync for BaseMCPClient<P>where
P: Sync,
impl<P> Unpin for BaseMCPClient<P>where
P: Unpin,
impl<P> UnsafeUnpin for BaseMCPClient<P>where
P: UnsafeUnpin,
impl<P> !UnwindSafe for BaseMCPClient<P>
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> 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 moreSource§impl<Source, Target> OctetsInto<Target> for Sourcewhere
Target: OctetsFrom<Source>,
impl<Source, Target> OctetsInto<Target> for Sourcewhere
Target: OctetsFrom<Source>,
type Error = <Target as OctetsFrom<Source>>::Error
Source§fn try_octets_into(
self,
) -> Result<Target, <Source as OctetsInto<Target>>::Error>
fn try_octets_into( self, ) -> Result<Target, <Source as OctetsInto<Target>>::Error>
Performs the conversion.
Source§fn octets_into(self) -> Target
fn octets_into(self) -> Target
Performs an infallible conversion.