httpmcp_rust/
handler_types.rs1use crate::context::RequestContext;
2use crate::error::Result;
3use crate::protocol::*;
4use actix_web::HttpResponse;
5use futures::future::BoxFuture;
6use serde_json::Value;
7use std::collections::HashMap;
8use std::sync::Arc;
9
10pub type ToolHandler = Box<
12    dyn Fn(HashMap<String, Value>, RequestContext) -> BoxFuture<'static, Result<Value>>
13        + Send
14        + Sync,
15>;
16
17pub type ResourceListHandler = Box<
19    dyn Fn(
20            Option<String>,
21            RequestContext,
22        ) -> BoxFuture<'static, Result<(Vec<Resource>, Option<String>)>>
23        + Send
24        + Sync,
25>;
26
27pub type ResourceReadHandler = Box<
29    dyn Fn(String, RequestContext) -> BoxFuture<'static, Result<Vec<ResourceContents>>>
30        + Send
31        + Sync,
32>;
33
34pub type PromptHandler = Box<
36    dyn Fn(
37            String,
38            Option<HashMap<String, String>>,
39            RequestContext,
40        ) -> BoxFuture<'static, Result<(Option<String>, Vec<PromptMessage>)>>
41        + Send
42        + Sync,
43>;
44
45pub type EndpointHandler = Arc<
47    dyn Fn(RequestContext, Option<Value>) -> BoxFuture<'static, Result<HttpResponse>> + Send + Sync,
48>;
49
50pub struct RegisteredTool {
52    pub meta: Tool,
53    pub handler: ToolHandler,
54}
55
56pub struct RegisteredResource {
58    pub meta: Resource,
59    pub list_handler: ResourceListHandler,
60    pub read_handler: ResourceReadHandler,
61}
62
63pub struct RegisteredPrompt {
65    pub meta: Prompt,
66    pub handler: PromptHandler,
67}
68
69pub struct RegisteredEndpoint {
71    pub route: String,
72    pub method: String,
73    pub description: Option<String>,
74    pub handler: EndpointHandler,
75}