asimov_server/http/mcp/
prompt.rs1use std::sync::Arc;
4
5use super::server::Error;
6use rmcp::model::{PromptArgument, PromptMessage};
7use serde_json::{Map, Value};
8
9pub type PromptCallback =
10 Arc<dyn Fn(Option<Map<String, Value>>) -> Result<Vec<PromptMessage>, Error> + Send + Sync>;
11
12#[derive(Clone)]
13pub struct Prompt {
14 pub name: String,
15 pub description: Option<String>,
16 pub arguments: Option<Vec<PromptArgument>>,
17 pub callback: PromptCallback,
18}
19
20impl Prompt {
21 pub fn new<S, D, F>(name: S, description: Option<D>, callback: F) -> Self
22 where
23 S: Into<String>,
24 D: Into<String>,
25 F: Fn() -> Result<Vec<PromptMessage>, Error> + Send + Sync + 'static,
26 {
27 Self {
28 name: name.into(),
29 description: description.map(Into::into),
30 arguments: None,
31 callback: Arc::new(move |_args| callback()),
32 }
33 }
34
35 pub fn new_with_args<S, D, F>(
36 name: S,
37 description: Option<D>,
38 arguments: Vec<PromptArgument>,
39 callback: F,
40 ) -> Self
41 where
42 S: Into<String>,
43 D: Into<String>,
44 F: Fn(Option<Map<String, Value>>) -> Result<Vec<PromptMessage>, Error>
45 + Send
46 + Sync
47 + 'static,
48 {
49 Self {
50 name: name.into(),
51 description: description.map(Into::into),
52 arguments: Some(arguments),
53 callback: Arc::new(callback),
54 }
55 }
56}