httpmcp_rust/
handler_types.rs1use crate::context::RequestContext;
2use crate::error::Result;
3use crate::protocol::*;
4use actix_multipart::Multipart;
5use actix_web::HttpResponse;
6use futures::future::BoxFuture;
7use serde_json::Value;
8use std::collections::HashMap;
9use std::sync::Arc;
10
11pub type ToolHandler = Box<
13 dyn Fn(HashMap<String, Value>, RequestContext) -> BoxFuture<'static, Result<Value>>
14 + Send
15 + Sync,
16>;
17
18pub type ResourceListHandler = Box<
20 dyn Fn(
21 Option<String>,
22 RequestContext,
23 ) -> BoxFuture<'static, Result<(Vec<Resource>, Option<String>)>>
24 + Send
25 + Sync,
26>;
27
28pub type ResourceReadHandler = Box<
30 dyn Fn(String, RequestContext) -> BoxFuture<'static, Result<Vec<ResourceContents>>>
31 + Send
32 + Sync,
33>;
34
35pub type PromptHandler = Box<
37 dyn Fn(
38 String,
39 Option<HashMap<String, String>>,
40 RequestContext,
41 ) -> BoxFuture<'static, Result<(Option<String>, Vec<PromptMessage>)>>
42 + Send
43 + Sync,
44>;
45
46pub type EndpointHandler = Arc<
48 dyn Fn(RequestContext, Option<Value>) -> BoxFuture<'static, Result<HttpResponse>> + Send + Sync,
49>;
50
51pub type MultipartEndpointHandler = Arc<
55 dyn Fn(
56 RequestContext,
57 Multipart,
58 ) -> std::pin::Pin<Box<dyn std::future::Future<Output = Result<HttpResponse>>>>
59 + Send
60 + Sync,
61>;
62
63pub struct RegisteredTool {
65 pub meta: Tool,
66 pub handler: ToolHandler,
67}
68
69pub struct RegisteredResource {
71 pub meta: Resource,
72 pub list_handler: ResourceListHandler,
73 pub read_handler: ResourceReadHandler,
74}
75
76pub struct RegisteredPrompt {
78 pub meta: Prompt,
79 pub handler: PromptHandler,
80}
81
82pub struct RegisteredEndpoint {
84 pub route: String,
85 pub method: String,
86 pub description: Option<String>,
87 pub handler: EndpointHandler,
88}
89
90pub struct RegisteredMultipartEndpoint {
92 pub route: String,
93 pub method: String,
94 pub description: Option<String>,
95 pub handler: MultipartEndpointHandler,
96}