mcprotocol_rs/client_features/
sampling.rs

1use async_trait::async_trait;
2use serde::{Deserialize, Serialize};
3use serde_json::Value;
4
5use crate::Result;
6
7/// Represents a sampling request from the server
8#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct SamplingRequest {
10    /// The prompt to be processed
11    pub prompt: Value,
12    /// Optional sampling parameters
13    pub parameters: Option<Value>,
14    /// Optional stop sequences
15    pub stop: Option<Vec<String>>,
16}
17
18/// Represents a sampling response to the server
19#[derive(Debug, Clone, Serialize, Deserialize)]
20pub struct SamplingResponse {
21    /// The generated text
22    pub text: String,
23    /// Optional metadata about the sampling
24    pub metadata: Option<Value>,
25}
26
27/// Sampling handler trait
28#[async_trait]
29pub trait SamplingHandler: Send + Sync {
30    /// Handles a sampling request
31    async fn handle_request(&self, request: SamplingRequest) -> Result<SamplingResponse>;
32
33    /// Cancels an ongoing sampling operation
34    async fn cancel(&self) -> Result<()>;
35}