mcp_server_rs/router/
capabilities.rs

1use mcp_core_rs::protocol::capabilities::{
2    PromptsCapability, ResourcesCapability, ServerCapabilities, ToolsCapability,
3};
4
5/// Builder for configuring and constructing capabilities
6pub struct CapabilitiesBuilder {
7    tools: Option<ToolsCapability>,
8    prompts: Option<PromptsCapability>,
9    resources: Option<ResourcesCapability>,
10}
11
12impl Default for CapabilitiesBuilder {
13    fn default() -> Self {
14        Self::new()
15    }
16}
17
18impl CapabilitiesBuilder {
19    pub fn new() -> Self {
20        Self {
21            tools: None,
22            prompts: None,
23            resources: None,
24        }
25    }
26
27    /// Add multiple tools to the router
28    pub fn with_tools(mut self, list_changed: bool) -> Self {
29        self.tools = Some(ToolsCapability {
30            list_changed: Some(list_changed),
31        });
32        self
33    }
34
35    /// Enable prompts capability
36    pub fn with_prompts(mut self, list_changed: bool) -> Self {
37        self.prompts = Some(PromptsCapability {
38            list_changed: Some(list_changed),
39        });
40        self
41    }
42
43    /// Enable resources capability
44    pub fn with_resources(mut self, subscribe: bool, list_changed: bool) -> Self {
45        self.resources = Some(ResourcesCapability {
46            subscribe: Some(subscribe),
47            list_changed: Some(list_changed),
48        });
49        self
50    }
51
52    /// Build the router with automatic capability inference
53    pub fn build(self) -> ServerCapabilities {
54        // Create capabilities based on what's configured
55        ServerCapabilities {
56            tools: self.tools,
57            prompts: self.prompts,
58            resources: self.resources,
59        }
60    }
61}