asimov_server/http/mcp/
resource.rs1use std::sync::Arc;
4
5use rmcp::model::ResourceContents;
6
7use super::server::Error;
8
9pub type ResourceCallback = Arc<dyn Fn() -> Result<Vec<ResourceContents>, Error> + Send + Sync>;
10
11#[derive(Clone)]
12pub struct Resource {
13 pub uri: String,
14 pub name: String,
15 pub description: Option<String>,
16 pub mime_type: Option<String>,
17 pub size: Option<u32>,
18 pub callback: ResourceCallback,
19}
20
21impl Resource {
22 pub fn new<U, N, D, M, F>(
23 uri: U,
24 name: N,
25 description: Option<D>,
26 mime_type: Option<M>,
27 size: Option<u32>,
28 callback: F,
29 ) -> Self
30 where
31 U: Into<String>,
32 N: Into<String>,
33 D: Into<String>,
34 M: Into<String>,
35 F: Fn() -> Result<Vec<ResourceContents>, Error> + Send + Sync + 'static,
36 {
37 Self {
38 uri: uri.into(),
39 name: name.into(),
40 description: description.map(Into::into),
41 mime_type: mime_type.map(Into::into),
42 size,
43 callback: Arc::new(callback),
44 }
45 }
46}
47
48#[derive(Clone)]
49pub struct ResourceTemplate {
50 pub name: String,
51 pub uri_template: String,
52 pub description: Option<String>,
53 pub mime_type: Option<String>,
54}