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_progresswired tohandler_islebytecode forwarding. - Subtask 3:
on_logging_messagelog bridge +create_messagesampling skeleton. - Subtask 4: progress/log notifications dispatched to main Isle via
execso 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
impl AgentBlockClientHandler
Sourcepub fn new() -> Self
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).
Sourcepub fn mark_on_progress(&self, server_name: &str)
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.
Sourcepub fn mark_on_log(&self, server_name: &str)
pub fn mark_on_log(&self, server_name: &str)
Mark that a Lua on_log handler has been installed on the handler Isle.
Sourcepub fn mark_on_resource_updated(&self, server_name: &str)
pub fn mark_on_resource_updated(&self, server_name: &str)
Mark that a Lua on_resource_updated handler has been installed.
Sourcepub fn mark_on_resource_list_changed(&self, server_name: &str)
pub fn mark_on_resource_list_changed(&self, server_name: &str)
Mark that a Lua on_resource_list_changed handler has been installed.
Sourcepub fn mark_on_tool_list_changed(&self, server_name: &str)
pub fn mark_on_tool_list_changed(&self, server_name: &str)
Mark that a Lua on_tool_list_changed handler has been installed.
Sourcepub fn mark_on_prompt_list_changed(&self, server_name: &str)
pub fn mark_on_prompt_list_changed(&self, server_name: &str)
Mark that a Lua on_prompt_list_changed handler has been installed.
Sourcepub fn trace_context_enabled(&self, server_name: &str) -> bool
pub fn trace_context_enabled(&self, server_name: &str) -> bool
Return whether trace context injection is enabled for the named server.
Sourcepub fn mark_sampling(&self, server_name: &str)
pub fn mark_sampling(&self, server_name: &str)
Mark that a Lua sampling handler has been installed on the handler Isle.
Sourcepub fn mark_roots(&self, server_name: &str)
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.
Sourcepub fn mark_elicitation(&self, server_name: &str)
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
impl ClientHandler for AgentBlockClientHandler
Source§fn list_roots(
&self,
_context: RequestContext<RoleClient>,
) -> impl Future<Output = Result<ListRootsResult, McpError>> + Send + '_
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 + '_
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.
fn on_progress( &self, params: ProgressNotificationParam, _context: NotificationContext<RoleClient>, ) -> impl Future<Output = ()> + Send + '_
fn on_logging_message( &self, params: LoggingMessageNotificationParam, _context: NotificationContext<RoleClient>, ) -> impl Future<Output = ()> + Send + '_
fn on_resource_updated( &self, params: ResourceUpdatedNotificationParam, _context: NotificationContext<RoleClient>, ) -> impl Future<Output = ()> + Send + '_
fn on_resource_list_changed( &self, _context: NotificationContext<RoleClient>, ) -> impl Future<Output = ()> + Send + '_
fn on_tool_list_changed( &self, _context: NotificationContext<RoleClient>, ) -> impl Future<Output = ()> + Send + '_
fn on_prompt_list_changed( &self, _context: NotificationContext<RoleClient>, ) -> impl Future<Output = ()> + Send + '_
fn create_message( &self, params: CreateMessageRequestParams, _context: RequestContext<RoleClient>, ) -> impl Future<Output = Result<CreateMessageResult, McpError>> + Send + '_
fn ping( &self, context: RequestContext<RoleClient>, ) -> impl Future<Output = Result<(), ErrorData>> + MaybeSendFuture
fn on_custom_request( &self, request: CustomRequest, context: RequestContext<RoleClient>, ) -> impl Future<Output = Result<CustomResult, ErrorData>> + MaybeSendFuture
fn on_cancelled( &self, params: CancelledNotificationParam, context: NotificationContext<RoleClient>, ) -> impl Future<Output = ()> + MaybeSendFuture
fn on_url_elicitation_notification_complete( &self, params: ElicitationResponseNotificationParam, context: NotificationContext<RoleClient>, ) -> impl Future<Output = ()> + MaybeSendFuture
fn on_custom_notification( &self, notification: CustomNotification, context: NotificationContext<RoleClient>, ) -> impl Future<Output = ()> + MaybeSendFuture
fn get_info(&self) -> InitializeRequestParams
Source§impl Clone for AgentBlockClientHandler
impl Clone for AgentBlockClientHandler
Source§fn clone(&self) -> AgentBlockClientHandler
fn clone(&self) -> AgentBlockClientHandler
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for AgentBlockClientHandler
impl RefUnwindSafe for AgentBlockClientHandler
impl Send for AgentBlockClientHandler
impl Sync for AgentBlockClientHandler
impl Unpin for AgentBlockClientHandler
impl UnsafeUnpin for AgentBlockClientHandler
impl UnwindSafe for AgentBlockClientHandler
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<R, S> DynService<R> for Swhere
R: ServiceRole,
S: Service<R>,
impl<R, S> DynService<R> for Swhere
R: ServiceRole,
S: Service<R>,
fn handle_request( &self, request: <R as ServiceRole>::PeerReq, context: RequestContext<R>, ) -> Pin<Box<dyn Future<Output = Result<<R as ServiceRole>::Resp, ErrorData>> + Send + '_>>
fn handle_notification( &self, notification: <R as ServiceRole>::PeerNot, context: NotificationContext<R>, ) -> Pin<Box<dyn Future<Output = Result<(), ErrorData>> + Send + '_>>
fn get_info(&self) -> <R as ServiceRole>::Info
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>
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>
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