Skip to main content

BaseMCPClient

Struct BaseMCPClient 

Source
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>
where P: Send + Sync + 'static + Clone,

Source

pub fn new(params: P) -> Self

创建新的基础客户端 / Create new base client

Source

pub fn set_state_change_callback<F>(&mut self, callback: F)
where F: Fn(ClientState, ClientState) + Send + Sync + 'static,

设置状态变化回调 / Set state change callback

Source

pub async fn get_state(&self) -> ClientState

获取当前状态 / Get current state

Source

pub fn get_state_notifier(&self) -> Receiver<ClientState>

获取状态变化通知器 / Get state change notifier

Source

pub async fn update_state(&self, new_state: ClientState)

更新状态 / Update state

Source

pub async fn can_connect(&self) -> bool

检查是否可以连接 / Check if can connect

Source

pub async fn can_disconnect(&self) -> bool

检查是否可以断开 / Check if can disconnect

Trait Implementations§

Source§

impl<P> MCPClientProtocol for BaseMCPClient<P>
where P: Send + Sync + Clone + 'static,

Source§

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,

连接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,

断开连接 / 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,

获取可用工具列表 / 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,

调用工具 / 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,

列出窗口资源 / 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,

获取窗口详情 / 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,

订阅窗口资源更新 / 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,

取消订阅窗口资源更新 / 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,

执行健康检查 / 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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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 more
Source§

impl<Source, Target> OctetsInto<Target> for Source
where Target: OctetsFrom<Source>,

Source§

type Error = <Target as OctetsFrom<Source>>::Error

Source§

fn try_octets_into( self, ) -> Result<Target, <Source as OctetsInto<Target>>::Error>

Performs the conversion.
Source§

fn octets_into(self) -> Target
where Self::Error: Into<Infallible>,

Performs an infallible conversion.
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more