turul_mcp_builders/traits/
tool_traits.rs1use serde_json::Value;
7use std::collections::HashMap;
8
9use turul_mcp_protocol::tools::ToolAnnotations;
11use turul_mcp_protocol::{Tool, ToolSchema};
12
13pub trait HasBaseMetadata {
15 fn name(&self) -> &str;
17
18 fn title(&self) -> Option<&str> {
20 None
21 }
22}
23
24pub trait HasDescription {
26 fn description(&self) -> Option<&str> {
27 None
28 }
29}
30
31pub trait HasInputSchema {
33 fn input_schema(&self) -> &ToolSchema;
34}
35
36pub trait HasOutputSchema {
38 fn output_schema(&self) -> Option<&ToolSchema> {
39 None
40 }
41}
42
43pub trait HasAnnotations {
45 fn annotations(&self) -> Option<&ToolAnnotations> {
46 None
47 }
48}
49
50pub trait HasToolMeta {
52 fn tool_meta(&self) -> Option<&HashMap<String, Value>> {
53 None
54 }
55}
56
57pub trait ToolDefinition:
63 HasBaseMetadata + HasDescription + HasInputSchema + HasOutputSchema + HasAnnotations + HasToolMeta + super::icon_traits::HasIcons + super::execution_traits::HasExecution + Send +
72 Sync
73{
74 fn display_name(&self) -> &str {
76 if let Some(title) = self.title() {
77 title
78 } else {
79 self.name()
80 }
81 }
82
83 fn to_tool(&self) -> Tool {
85 Tool {
86 name: self.name().to_string(),
87 title: self.title().map(String::from),
88 description: self.description().map(String::from),
89 input_schema: self.input_schema().clone(),
90 output_schema: self.output_schema().cloned(),
91 annotations: self.annotations().cloned(),
92 execution: self.execution(),
93 icons: self.icons().cloned(),
94 meta: self.tool_meta().cloned(),
95 }
96 }
97}
98
99impl<T> ToolDefinition for T
101where
102 T: HasBaseMetadata
103 + HasDescription
104 + HasInputSchema
105 + HasOutputSchema
106 + HasAnnotations
107 + HasToolMeta
108 + super::icon_traits::HasIcons
109 + super::execution_traits::HasExecution
110 + Send
111 + Sync,
112{
113 }