Skip to main content

do_memory_mcp/server/
tool_definitions.rs

1//! Basic tool definitions for the MCP server
2//!
3//! This module contains the `create_default_tools()` function that defines
4//! the core MCP tools for the memory system (querying, patterns, monitoring, embeddings).
5
6use crate::types::Tool;
7use serde_json::json;
8
9/// Create the default set of basic tool definitions for the MCP server.
10///
11/// This function defines core tools including memory queries, pattern analysis,
12/// health checks, metrics, embeddings, and pattern search/recommendation.
13pub fn create_default_tools() -> Vec<Tool> {
14    let mut tools = vec![Tool::new(
15        "query_memory".to_string(),
16        "Query episodic memory for relevant past experiences and learned patterns".to_string(),
17        json!({
18            "type": "object",
19            "properties": {
20                "query": {
21                    "type": "string",
22                    "description": "Search query describing the task or context"
23                },
24                "domain": {
25                    "type": "string",
26                    "description": "Task domain (e.g., 'web-api', 'data-processing')"
27                },
28                "task_type": {
29                    "type": "string",
30                    "enum": [
31                        "code_generation",
32                        "debugging",
33                        "refactoring",
34                        "testing",
35                        "analysis",
36                        "documentation"
37                    ],
38                    "description": "Type of task being performed"
39                },
40                "limit": {
41                    "type": "integer",
42                    "default": 10,
43                    "description": "Maximum number of episodes to retrieve"
44                },
45                "sort": {
46                    "type": "string",
47                    "enum": ["relevance", "newest", "oldest", "duration", "success"],
48                    "default": "relevance",
49                    "description": "Sort order for results"
50                }
51            },
52            "required": ["query", "domain"]
53        }),
54    )];
55
56    tools.push(Tool::new(
57        "analyze_patterns".to_string(),
58        "Analyze patterns from past episodes to identify successful strategies".to_string(),
59        json!({
60            "type": "object",
61            "properties": {
62                "task_type": {
63                    "type": "string",
64                    "description": "Type of task to analyze patterns for"
65                },
66                "min_success_rate": {
67                    "type": "number",
68                    "default": 0.7,
69                    "description": "Minimum success rate for patterns (0.0-1.0)"
70                },
71                "limit": {
72                    "type": "integer",
73                    "default": 20,
74                    "description": "Maximum number of patterns to return"
75                }
76            },
77            "required": ["task_type"]
78        }),
79    ));
80
81    tools.push(Tool::new(
82        "health_check".to_string(),
83        "Check the health status of the MCP server and its components".to_string(),
84        json!({"type": "object", "properties": {}}),
85    ));
86
87    tools.push(Tool::new(
88        "get_metrics".to_string(),
89        "Get comprehensive monitoring metrics and statistics".to_string(),
90        json!({
91            "type": "object",
92            "properties": {
93                "metric_type": {
94                    "type": "string",
95                    "enum": ["all", "performance", "episodes", "system"],
96                    "default": "all",
97                    "description": "Type of metrics to retrieve"
98                }
99            }
100        }),
101    ));
102
103    // Advanced pattern analysis tool
104    tools.push(
105        crate::mcp::tools::advanced_pattern_analysis::AdvancedPatternAnalysisTool::tool_definition(
106        ),
107    );
108
109    // Quality metrics tool
110    tools.push(crate::mcp::tools::quality_metrics::QualityMetricsTool::tool_definition());
111
112    // Embedding configuration and query tools
113    tools.push(crate::mcp::tools::embeddings::configure_embeddings_tool());
114    tools.push(crate::mcp::tools::embeddings::query_semantic_memory_tool());
115    tools.push(crate::mcp::tools::embeddings::test_embeddings_tool());
116
117    // Pattern search tool
118    tools.push(Tool::new(
119        "search_patterns".to_string(),
120        "Search for patterns semantically similar to a query using multi-signal ranking"
121            .to_string(),
122        json!({
123            "type": "object",
124            "properties": {
125                "query": {
126                    "type": "string",
127                    "description": "Natural language query describing what pattern to search for"
128                },
129                "domain": {
130                    "type": "string",
131                    "description": "Domain to search in (e.g., 'web-api', 'cli', 'data-processing')"
132                },
133                "tags": {
134                    "type": "array",
135                    "items": {"type": "string"},
136                    "description": "Optional tags for filtering",
137                    "default": []
138                },
139                "limit": {
140                    "type": "integer",
141                    "description": "Maximum number of results (default: 5)",
142                    "default": 5
143                },
144                "min_relevance": {
145                    "type": "number",
146                    "description": "Minimum relevance score 0.0-1.0 (default: 0.3)",
147                    "default": 0.3
148                },
149                "filter_by_domain": {
150                    "type": "boolean",
151                    "description": "Whether to filter by domain (default: false)",
152                    "default": false
153                }
154            },
155            "required": ["query", "domain"]
156        }),
157    ));
158
159    // Pattern recommendation tool
160    tools.push(Tool::new(
161        "recommend_patterns".to_string(),
162        "Get pattern recommendations for a specific task with high-quality filtering".to_string(),
163        json!({
164            "type": "object",
165            "properties": {
166                "task_description": {
167                    "type": "string",
168                    "description": "Description of the task you're working on"
169                },
170                "domain": {
171                    "type": "string",
172                    "description": "Domain of the task (e.g., 'web-api', 'cli')"
173                },
174                "tags": {
175                    "type": "array",
176                    "items": {"type": "string"},
177                    "description": "Optional context tags",
178                    "default": []
179                },
180                "limit": {
181                    "type": "integer",
182                    "description": "Maximum number of recommendations (default: 3)",
183                    "default": 3
184                }
185            },
186            "required": ["task_description", "domain"]
187        }),
188    ));
189
190    // Recommendation feedback tools (ADR-044 Feature 2)
191    tools.push(Tool::new(
192        "record_recommendation_session".to_string(),
193        "Record a recommendation session when patterns/playbooks are suggested to an agent"
194            .to_string(),
195        json!({
196            "type": "object",
197            "properties": {
198                "episode_id": {
199                    "type": "string",
200                    "description": "Episode ID for which recommendations are made"
201                },
202                "recommended_pattern_ids": {
203                    "type": "array",
204                    "items": {"type": "string"},
205                    "description": "Pattern IDs that were recommended",
206                    "default": []
207                },
208                "recommended_playbook_ids": {
209                    "type": "array",
210                    "items": {"type": "string"},
211                    "description": "Playbook IDs that were recommended",
212                    "default": []
213                }
214            },
215            "required": ["episode_id"]
216        }),
217    ));
218
219    tools.push(Tool::new(
220        "record_recommendation_feedback".to_string(),
221        "Record feedback about which recommendations were used and the outcome".to_string(),
222        json!({
223            "type": "object",
224            "properties": {
225                "session_id": {
226                    "type": "string",
227                    "description": "Session ID from the recommendation session"
228                },
229                "applied_pattern_ids": {
230                    "type": "array",
231                    "items": {"type": "string"},
232                    "description": "Pattern IDs that were actually applied",
233                    "default": []
234                },
235                "consulted_episode_ids": {
236                    "type": "array",
237                    "items": {"type": "string"},
238                    "description": "Episode IDs that were consulted",
239                    "default": []
240                },
241                "outcome": {
242                    "type": "object",
243                    "description": "Final outcome of the task",
244                    "properties": {
245                        "type": {
246                            "type": "string",
247                            "enum": ["success", "partial_success", "failure"]
248                        },
249                        "verdict": {"type": "string"},
250                        "reason": {"type": "string"},
251                        "artifacts": {
252                            "type": "array",
253                            "items": {"type": "string"},
254                            "default": []
255                        }
256                    },
257                    "required": ["type"]
258                },
259                "agent_rating": {
260                    "type": "number",
261                    "description": "Optional rating of recommendation quality (0.0-1.0)",
262                    "minimum": 0.0,
263                    "maximum": 1.0
264                }
265            },
266            "required": ["session_id", "outcome"]
267        }),
268    ));
269
270    tools.push(Tool::new(
271        "get_recommendation_stats".to_string(),
272        "Get statistics about recommendation effectiveness and adoption rates".to_string(),
273        json!({
274            "type": "object",
275            "properties": {}
276        }),
277    ));
278
279    tools
280}