Skip to main content

AgentBlockClientHandler

Struct AgentBlockClientHandler 

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

Custom MCP client handler that holds per-server Lua callback registries.

AgentBlockClientHandler is cloned into each RunningService<RoleClient, _>. The inner Arc<Mutex<…>> lets all clones share the same registry map so that a callback registered via the Lua bridge after connect is immediately visible to the handler running on the rmcp task.

The server_name field is set per-connection (by McpManager::connect / connect_http) before clone() so that create_message can look up the correct sampling handler by server name without needing the RequestContext to carry server identity.

§Subtask evolution

  • Subtask 1: skeleton — all notification methods are the default no-ops from rmcp.
  • Subtask 2: on_progress wired to handler_isle bytecode forwarding.
  • Subtask 3: on_logging_message log bridge + create_message sampling skeleton.
  • Subtask 4: progress/log notifications dispatched to main Isle via exec so user callbacks run with their upvalues intact (no bytecode dump/reload across VMs).
  • Subtask 5 (M-3): bounded notification channel replaces per-notification spawns to cap memory growth when a chatty server floods notifications faster than Lua can consume them.

Implementations§

Source§

impl AgentBlockClientHandler

Source

pub fn new() -> Self

Create a handler with an empty registry (no notification dispatch).

Used in concurrency tests and contexts where no Isle is available. Notifications received while main_isle is None are silently dropped (no Lua callback can execute without an Isle).

Source

pub fn mark_on_progress(&self, server_name: &str)

Mark that a Lua on_progress handler has been installed on the handler Isle for the given server.

Source

pub fn mark_on_log(&self, server_name: &str)

Mark that a Lua on_log handler has been installed on the handler Isle.

Source

pub fn mark_on_resource_updated(&self, server_name: &str)

Mark that a Lua on_resource_updated handler has been installed.

Source

pub fn mark_on_resource_list_changed(&self, server_name: &str)

Mark that a Lua on_resource_list_changed handler has been installed.

Source

pub fn mark_on_tool_list_changed(&self, server_name: &str)

Mark that a Lua on_tool_list_changed handler has been installed.

Source

pub fn mark_on_prompt_list_changed(&self, server_name: &str)

Mark that a Lua on_prompt_list_changed handler has been installed.

Source

pub fn trace_context_enabled(&self, server_name: &str) -> bool

Return whether trace context injection is enabled for the named server.

Source

pub fn mark_sampling(&self, server_name: &str)

Mark that a Lua sampling handler has been installed on the handler Isle.

Source

pub fn mark_roots(&self, server_name: &str)

Mark that a Lua roots handler has been installed on the handler Isle.

§Arguments
  • server_name — the server for which the roots handler was registered.
§Side effects

Creates a registry entry for the server if one does not yet exist, then sets roots = true so that list_roots requests are dispatched to the Lua callback rather than returning method_not_found.

Source

pub fn mark_elicitation(&self, server_name: &str)

Mark that a Lua elicitation handler has been installed on the handler Isle.

§Arguments
  • server_name — the server for which the elicitation handler was registered.
§Side effects

Creates a registry entry for the server if one does not yet exist, then sets elicitation = true so that create_elicitation requests are dispatched to the Lua callback rather than returning Decline (no-handler path).

Trait Implementations§

Source§

impl ClientHandler for AgentBlockClientHandler

Source§

fn list_roots( &self, _context: RequestContext<RoleClient>, ) -> impl Future<Output = Result<ListRootsResult, McpError>> + Send + '_

Handle an inbound roots/list request that arrives from the MCP server.

The server sends roots/list to ask the client which filesystem roots are available. This is a server→client request; the implementation looks up the Lua callback registered via mcp.set_roots_handler and returns its result.

§Returns
  • Ok(ListRootsResult) containing the roots the Lua handler returned.
  • Err(McpError::method_not_found) when no server name is wired, no roots handler is registered, or no handler Isle is available.
  • Err(McpError::internal_error) when the handler Isle exec fails or the Lua result cannot be parsed.
Source§

fn create_elicitation( &self, request: CreateElicitationRequestParams, _context: RequestContext<RoleClient>, ) -> impl Future<Output = Result<CreateElicitationResult, McpError>> + Send + '_

Handle an inbound elicitation/create request that arrives from the MCP server.

The server sends elicitation/create to ask the client to gather user input. This is a server→client request. Form variant is dispatched to the Lua callback registered via mcp.set_elicitation_handler; Url variant is always declined without reaching the Lua layer (crux Form-only dispatch constraint).

§Returns
  • Ok(CreateElicitationResult { action: Accept, content: Some(json), .. }) on accept.
  • Ok(CreateElicitationResult { action: Decline, .. }) on decline, cancel-as-decline, Url variant, or no handler registered (spec neutral — not an error).
  • Ok(CreateElicitationResult { action: Cancel, .. }) on cancel.
  • Err(McpError::method_not_found) when no server name is wired or no handler Isle is available (mirrors list_roots).
  • Err(McpError::internal_error) when the handler Isle exec fails or the Lua result fails 3-action contract validation.
Source§

fn on_progress( &self, params: ProgressNotificationParam, _context: NotificationContext<RoleClient>, ) -> impl Future<Output = ()> + Send + '_

Source§

fn on_logging_message( &self, params: LoggingMessageNotificationParam, _context: NotificationContext<RoleClient>, ) -> impl Future<Output = ()> + Send + '_

Source§

fn on_resource_updated( &self, params: ResourceUpdatedNotificationParam, _context: NotificationContext<RoleClient>, ) -> impl Future<Output = ()> + Send + '_

Source§

fn on_resource_list_changed( &self, _context: NotificationContext<RoleClient>, ) -> impl Future<Output = ()> + Send + '_

Source§

fn on_tool_list_changed( &self, _context: NotificationContext<RoleClient>, ) -> impl Future<Output = ()> + Send + '_

Source§

fn on_prompt_list_changed( &self, _context: NotificationContext<RoleClient>, ) -> impl Future<Output = ()> + Send + '_

Source§

fn create_message( &self, params: CreateMessageRequestParams, _context: RequestContext<RoleClient>, ) -> impl Future<Output = Result<CreateMessageResult, McpError>> + Send + '_

Source§

fn ping( &self, context: RequestContext<RoleClient>, ) -> impl Future<Output = Result<(), ErrorData>> + MaybeSendFuture

Source§

fn on_custom_request( &self, request: CustomRequest, context: RequestContext<RoleClient>, ) -> impl Future<Output = Result<CustomResult, ErrorData>> + MaybeSendFuture

Source§

fn on_cancelled( &self, params: CancelledNotificationParam, context: NotificationContext<RoleClient>, ) -> impl Future<Output = ()> + MaybeSendFuture

Source§

fn on_url_elicitation_notification_complete( &self, params: ElicitationResponseNotificationParam, context: NotificationContext<RoleClient>, ) -> impl Future<Output = ()> + MaybeSendFuture

Source§

fn on_custom_notification( &self, notification: CustomNotification, context: NotificationContext<RoleClient>, ) -> impl Future<Output = ()> + MaybeSendFuture

Source§

fn get_info(&self) -> InitializeRequestParams

Source§

impl Clone for AgentBlockClientHandler

Source§

fn clone(&self) -> AgentBlockClientHandler

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for AgentBlockClientHandler

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<R, S> DynService<R> for S
where R: ServiceRole, S: Service<R>,

Source§

fn handle_request( &self, request: <R as ServiceRole>::PeerReq, context: RequestContext<R>, ) -> Pin<Box<dyn Future<Output = Result<<R as ServiceRole>::Resp, ErrorData>> + Send + '_>>

Source§

fn handle_notification( &self, notification: <R as ServiceRole>::PeerNot, context: NotificationContext<R>, ) -> Pin<Box<dyn Future<Output = Result<(), ErrorData>> + Send + '_>>

Source§

fn get_info(&self) -> <R as ServiceRole>::Info

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

Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + 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: Sized + 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<H> Service<RoleClient> for H
where H: ClientHandler,

Source§

impl<S> ServiceExt<RoleClient> for S
where S: Service<RoleClient>,

Source§

fn serve_with_ct<T, E, A>( self, transport: T, ct: CancellationToken, ) -> impl Future<Output = Result<RunningService<RoleClient, S>, ClientInitializeError>> + MaybeSendFuture
where T: IntoTransport<RoleClient, E, A>, E: Error + Send + Sync + 'static, S: Sized,

Source§

fn into_dyn(self) -> Box<dyn DynService<R>>

Convert this service to a dynamic boxed service Read more
Source§

fn serve<T, E, A>( self, transport: T, ) -> impl Future<Output = Result<RunningService<R, Self>, <R as ServiceRole>::InitializeError>> + MaybeSendFuture
where T: IntoTransport<R, E, A>, E: Error + Send + Sync + 'static, Self: Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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<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