pub struct ClientRequester { /* private fields */ }Expand description
Client requester for making server→client requests from tools
This is passed to tools via ExecutionContext, allowing them to make requests to the client (roots/list, sampling/createMessage, etc.)
§Example
impl Tool for ListRootsTool {
async fn execute(&self, ctx: ExecutionContext<'_>) -> Result<Vec<Box<dyn Content>>, ToolError> {
if let Some(requester) = ctx.client_requester() {
match requester.request_roots(None).await {
Ok(roots) => {
let msg = format!("Found {} roots", roots.len());
Ok(vec![Box::new(TextContent::new(msg))])
}
Err(e) => Err(ToolError::Execution(e.to_string())),
}
} else {
Err(ToolError::Execution("No client requester available".into()))
}
}
}Implementations§
Source§impl ClientRequester
impl ClientRequester
Sourcepub fn new(
request_tx: UnboundedSender<JsonRpcClientRequest>,
multiplexer: Arc<RequestMultiplexer>,
supports_roots: bool,
supports_sampling: bool,
) -> Self
pub fn new( request_tx: UnboundedSender<JsonRpcClientRequest>, multiplexer: Arc<RequestMultiplexer>, supports_roots: bool, supports_sampling: bool, ) -> Self
Create a new client requester
Sourcepub fn supports_roots(&self) -> bool
pub fn supports_roots(&self) -> bool
Check if client supports roots capability
Sourcepub fn supports_sampling(&self) -> bool
pub fn supports_sampling(&self) -> bool
Check if client supports sampling capability
Sourcepub async fn request_roots(
&self,
timeout: Option<Duration>,
) -> Result<Vec<Root>, MultiplexerError>
pub async fn request_roots( &self, timeout: Option<Duration>, ) -> Result<Vec<Root>, MultiplexerError>
Request workspace roots from the client
Returns an error if the client doesn’t support roots capability.
Sourcepub async fn request_sampling(
&self,
params: CreateMessageParams,
timeout: Option<Duration>,
) -> Result<CreateMessageResult, MultiplexerError>
pub async fn request_sampling( &self, params: CreateMessageParams, timeout: Option<Duration>, ) -> Result<CreateMessageResult, MultiplexerError>
Request an LLM completion from the client
Returns an error if the client doesn’t support sampling capability.
Sourcepub async fn request_elicitation(
&self,
message: String,
requested_schema: Value,
timeout: Option<Duration>,
) -> Result<CreateElicitationResult, MultiplexerError>
pub async fn request_elicitation( &self, message: String, requested_schema: Value, timeout: Option<Duration>, ) -> Result<CreateElicitationResult, MultiplexerError>
Request user input elicitation from the client
Sends an elicitation/create request to the client and waits for the response.
The client must have the elicitation capability advertised.
§Arguments
message- The message to show the userschema- The schema defining the structure of requested inputtimeout- Optional timeout for the request
§Returns
The user’s response (accept/decline/cancel with optional data), or an error if:
- Client doesn’t support elicitation capability
- Request times out
- Transport error occurs
Trait Implementations§
Source§impl Clone for ClientRequester
impl Clone for ClientRequester
Source§fn clone(&self) -> ClientRequester
fn clone(&self) -> ClientRequester
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more