pub struct PromptBuilderWithHandler<F> { /* private fields */ }Expand description
Builder state after handler is specified
This allows either calling .build() to create the prompt directly,
or .layer() to apply middleware before building.
Implementations§
Source§impl<F, Fut> PromptBuilderWithHandler<F>
impl<F, Fut> PromptBuilderWithHandler<F>
Sourcepub fn layer<L>(self, layer: L) -> Promptwhere
L: Layer<PromptHandlerService<F>> + Send + Sync + 'static,
L::Service: Service<PromptRequest, Response = GetPromptResult> + Clone + Send + 'static,
<L::Service as Service<PromptRequest>>::Error: Display + Send,
<L::Service as Service<PromptRequest>>::Future: Send,
pub fn layer<L>(self, layer: L) -> Promptwhere
L: Layer<PromptHandlerService<F>> + Send + Sync + 'static,
L::Service: Service<PromptRequest, Response = GetPromptResult> + Clone + Send + 'static,
<L::Service as Service<PromptRequest>>::Error: Display + Send,
<L::Service as Service<PromptRequest>>::Future: Send,
Apply a tower middleware layer to this prompt
The layer wraps the prompt handler, allowing middleware like timeouts, rate limiting, or retries to be applied to this specific prompt.
§Example
use std::collections::HashMap;
use std::time::Duration;
use tower::timeout::TimeoutLayer;
use tower_mcp::prompt::PromptBuilder;
use tower_mcp::protocol::{GetPromptResult, PromptMessage, PromptRole, Content};
let prompt = PromptBuilder::new("slow_prompt")
.description("A prompt that might take a while")
.handler(|_args: HashMap<String, String>| async move {
Ok(GetPromptResult {
description: Some("Generated prompt".to_string()),
messages: vec![PromptMessage {
role: PromptRole::User,
content: Content::Text {
text: "Hello!".to_string(),
annotations: None,
},
}],
})
})
.layer(TimeoutLayer::new(Duration::from_secs(5)));Auto Trait Implementations§
impl<F> Freeze for PromptBuilderWithHandler<F>where
F: Freeze,
impl<F> RefUnwindSafe for PromptBuilderWithHandler<F>where
F: RefUnwindSafe,
impl<F> Send for PromptBuilderWithHandler<F>where
F: Send,
impl<F> Sync for PromptBuilderWithHandler<F>where
F: Sync,
impl<F> Unpin for PromptBuilderWithHandler<F>where
F: Unpin,
impl<F> UnwindSafe for PromptBuilderWithHandler<F>where
F: UnwindSafe,
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
Mutably borrows from an owned value. Read more