Skip to main content

ProxyHandlerManager

Struct ProxyHandlerManager 

Source
pub struct ProxyHandlerManager { /* private fields */ }
Expand description

MCP 代理管理器

使用 RAII 模式管理 MCP 服务:

  • 从 map 中移除 mcp_id 时,自动释放对应的进程资源
  • 不需要显式调用 cleanup 方法(但仍提供显式清理接口)

Implementations§

Source§

impl ProxyHandlerManager

Source

pub fn add_mcp_service( &self, mcp_id: String, mcp_type: McpType, mcp_router_path: McpRouterPath, cancellation_token: CancellationToken, )

添加 MCP 服务(RAII 模式)

使用新的 RAII 结构创建服务,当服务被移除时会自动清理资源

Source

pub fn add_mcp_service_status_and_proxy( &self, mcp_service_status: McpServiceStatus, proxy_handler: Option<McpHandler>, )

添加 MCP 服务状态(兼容旧 API)

保持与现有代码的兼容性,内部转换为新的 RAII 结构

注意:last_accessed 会被重置为当前时间(插入视为新访问)

Source

pub fn get_all_mcp_service_status(&self) -> Vec<McpServiceStatus>

获取所有的 MCP 服务状态(兼容旧 API)

优化:先快速收集所有 keys,然后逐个获取详细信息 避免 iter() 长时间锁住多个分片,让其他写操作有机会执行

Source

pub fn get_mcp_service_status(&self, mcp_id: &str) -> Option<McpServiceStatus>

获取 MCP 服务状态(兼容旧 API)

Source

pub fn update_last_accessed(&self, mcp_id: &str)

更新最后访问时间

使用 entry API 确保原子性操作

Source

pub fn update_mcp_service_status( &self, mcp_id: &str, status: CheckMcpStatusResponseStatus, )

修改 MCP 服务状态 (Ready/Pending/Error)

使用 entry API 确保原子性操作

Source

pub fn get_proxy_handler(&self, mcp_id: &str) -> Option<McpHandler>

获取 MCP Handler

Source

pub fn get_mcp_config(&self, mcp_id: &str) -> Option<McpConfig>

获取服务的 MCP 配置(用于自动重启)

Source

pub fn add_proxy_handler(&self, mcp_id: &str, proxy_handler: McpHandler)

添加 MCP Handler 到已存在的服务

使用 entry API 确保原子性操作

Source

pub fn contains_service(&self, mcp_id: &str) -> bool

检查服务是否存在

Source

pub fn service_count(&self) -> usize

获取服务数量

Source

pub async fn register_mcp_config(&self, mcp_id: &str, config: McpConfig)

注册 MCP 配置到缓存

Source

pub async fn get_mcp_config_from_cache(&self, mcp_id: &str) -> Option<McpConfig>

从缓存获取 MCP 配置

Source

pub async fn unregister_mcp_config(&self, mcp_id: &str)

从缓存删除 MCP 配置

Source

pub async fn cleanup_resources(&self, mcp_id: &str) -> Result<()>

清理资源 (RAII 模式简化版)

通过 RAII 模式,从 DashMap 中移除服务会自动:

  1. 触发 McpProcessGuard::drop()
  2. 取消 CancellationToken
  3. 关联的子进程收到信号退出

此方法额外清理路由和缓存

Source

pub async fn cleanup_all_resources(&self) -> Result<()>

系统关闭,清理所有资源

RAII 模式下,清除 DashMap 会自动释放所有资源

Source

pub fn remove_service(&self, mcp_id: &str) -> bool

仅移除服务(依赖 RAII 自动清理进程)

从 DashMap 中移除服务,触发 RAII 自动清理。 不会清理路由和缓存,适用于需要快速移除服务的场景。

Source

pub fn reset_probe_failures(&self, mcp_id: &str)

重置健康检查失败计数

使用 get_mut 避免为不存在的服务创建空 entry

Source

pub fn increment_probe_failures(&self, mcp_id: &str) -> u32

增加健康检查失败计数,返回增加后的值

使用 entry API 确保原子性操作

Source

pub async fn cleanup_resources_for_restart(&self, mcp_id: &str) -> Result<()>

清理资源用于重启(保留配置缓存)

与 cleanup_resources 不同,此方法不会清理配置缓存, 允许后续使用缓存的配置重新启动服务。

Trait Implementations§

Source§

impl Debug for ProxyHandlerManager

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ProxyHandlerManager

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
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> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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