httpmcp_rust/
handler_types.rs

1use crate::context::RequestContext;
2use crate::error::Result;
3use crate::protocol::*;
4use futures::future::BoxFuture;
5use serde_json::Value;
6use std::collections::HashMap;
7
8/// Tool handler function signature
9pub type ToolHandler = Box<
10    dyn Fn(HashMap<String, Value>, RequestContext) -> BoxFuture<'static, Result<Value>>
11        + Send
12        + Sync,
13>;
14
15/// Resource list handler function signature
16pub type ResourceListHandler = Box<
17    dyn Fn(
18            Option<String>,
19            RequestContext,
20        ) -> BoxFuture<'static, Result<(Vec<Resource>, Option<String>)>>
21        + Send
22        + Sync,
23>;
24
25/// Resource read handler function signature
26pub type ResourceReadHandler = Box<
27    dyn Fn(String, RequestContext) -> BoxFuture<'static, Result<Vec<ResourceContents>>>
28        + Send
29        + Sync,
30>;
31
32/// Prompt handler function signature
33pub type PromptHandler = Box<
34    dyn Fn(
35            String,
36            Option<HashMap<String, String>>,
37            RequestContext,
38        ) -> BoxFuture<'static, Result<(Option<String>, Vec<PromptMessage>)>>
39        + Send
40        + Sync,
41>;
42
43/// Registered tool
44pub struct RegisteredTool {
45    pub meta: Tool,
46    pub handler: ToolHandler,
47}
48
49/// Registered resource
50pub struct RegisteredResource {
51    pub meta: Resource,
52    pub list_handler: ResourceListHandler,
53    pub read_handler: ResourceReadHandler,
54}
55
56/// Registered prompt
57pub struct RegisteredPrompt {
58    pub meta: Prompt,
59    pub handler: PromptHandler,
60}