1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// SATD (Self-Admitted Technical Debt) Analysis Tool
/// MCP args for analyze.satd: paths to scan for self-admitted technical debt, optional include_resolved flag.
#[derive(Debug, Deserialize)]
struct SatdArgs {
paths: Vec<String>,
#[serde(default)]
include_resolved: bool,
}
/// Tool handler for detecting self-admitted technical debt in code comments.
///
/// This tool scans source files for TODO, FIXME, HACK, and other markers
/// that indicate technical debt acknowledged by developers.
///
/// # Arguments
///
/// ```json
/// {
/// "paths": ["src/"], // Required: paths to analyze
/// "include_resolved": false // Optional: include resolved items
/// }
/// ```ignore
///
/// # Examples
///
/// ```rust,no_run
/// # #[cfg(feature = "pmcp-mcp")]
/// # {
/// use pmat::mcp_pmcp::analyze_handlers::AnalyzeSatdTool;
/// use serde_json::json;
///
/// let tool = AnalyzeSatdTool::new();
/// let args = json!({
/// "paths": ["src/", "tests/"],
/// "include_resolved": false
/// });
/// # }
/// ```
pub struct SatdTool;
impl SatdTool {
/// Creates a new SATD analysis tool handler.
#[must_use]
pub fn new() -> Self {
Self
}
}
impl Default for SatdTool {
fn default() -> Self {
Self::new()
}
}
#[async_trait]
impl ToolHandler for SatdTool {
async fn handle(&self, args: Value, _extra: RequestHandlerExtra) -> Result<Value> {
debug!("Handling analyze.satd with args: {}", args);
let params: SatdArgs = serde_json::from_value(args)
.map_err(|e| Error::validation(format!("Invalid arguments: {e}")))?;
let paths: Vec<PathBuf> = params.paths.into_iter().map(PathBuf::from).collect();
let results = tool_functions::analyze_satd(&paths, params.include_resolved)
.await
.map_err(|e| Error::internal(format!("SATD analysis failed: {e}")))?;
Ok(results)
}
}
// Dead Code Analysis Tool
/// MCP args for analyze.dead-code: paths to scan for unreachable code, optional include_tests flag.
#[derive(Debug, Deserialize)]
struct DeadCodeArgs {
paths: Vec<String>,
#[serde(default)]
include_tests: bool,
}
pub struct DeadCodeTool;
impl DeadCodeTool {
#[must_use]
pub fn new() -> Self {
Self
}
}
impl Default for DeadCodeTool {
fn default() -> Self {
Self::new()
}
}
#[async_trait]
impl ToolHandler for DeadCodeTool {
async fn handle(&self, args: Value, _extra: RequestHandlerExtra) -> Result<Value> {
debug!("Handling analyze.dead-code with args: {}", args);
let params: DeadCodeArgs = serde_json::from_value(args)
.map_err(|e| Error::validation(format!("Invalid arguments: {e}")))?;
let paths: Vec<PathBuf> = params.paths.into_iter().map(PathBuf::from).collect();
let results = tool_functions::analyze_dead_code(&paths, params.include_tests)
.await
.map_err(|e| Error::internal(format!("Dead code analysis failed: {e}")))?;
Ok(results)
}
}