turbomcp_server/handlers/traits/
prompt.rs

1//! Prompt handler trait for processing prompt requests
2
3use async_trait::async_trait;
4use serde_json::Value;
5use std::collections::HashMap;
6use turbomcp_protocol::RequestContext;
7use turbomcp_protocol::types::{GetPromptRequest, GetPromptResult, Prompt};
8
9use crate::ServerResult;
10
11/// Prompt handler trait for processing prompt requests
12#[async_trait]
13pub trait PromptHandler: Send + Sync {
14    /// Handle a prompt request
15    async fn handle(
16        &self,
17        request: GetPromptRequest,
18        ctx: RequestContext,
19    ) -> ServerResult<GetPromptResult>;
20
21    /// Get the prompt definition
22    fn prompt_definition(&self) -> Prompt;
23
24    /// Validate prompt arguments (optional, default implementation allows all)
25    fn validate_arguments(&self, _args: &HashMap<String, Value>) -> ServerResult<()> {
26        Ok(())
27    }
28}