aprender_mcp/tools/
validate.rs1#![allow(clippy::disallowed_methods)] use crate::tools::subprocess::run_apr;
14use crate::types::{InputSchema, ToolCallResult, ToolDefinition};
15
16pub const NAME: &str = "apr.validate";
18
19#[must_use]
28pub fn validate_tool_definition() -> ToolDefinition {
29 let input_schema: InputSchema = serde_json::from_str(crate::schemas::APR_VALIDATE_SCHEMA)
30 .expect(
31 "FALSIFY-MCP-008: apr.validate codegen constant must parse as InputSchema; \
32 regenerate by editing contracts/apr-mcp-tool-schemas-v1.yaml and rebuilding",
33 );
34 ToolDefinition {
35 name: NAME.to_string(),
36 description: crate::schemas::APR_VALIDATE_DESCRIPTION.to_string(),
37 input_schema,
38 }
39}
40
41#[must_use]
43pub fn call(args: &serde_json::Value) -> ToolCallResult {
44 let Some(model_path) = args.get("model_path").and_then(|v| v.as_str()) else {
45 return ToolCallResult::error("Missing required argument: model_path");
46 };
47 run_apr(&["validate", model_path, "--json"])
48}
49
50#[cfg(test)]
51#[allow(clippy::disallowed_methods)] mod tests {
53 use super::*;
54
55 #[test]
56 fn definition_has_correct_name_and_required_field() {
57 let def = validate_tool_definition();
58 assert_eq!(def.name, "apr.validate");
59 assert_eq!(def.input_schema.schema_type, "object");
60 assert_eq!(def.input_schema.required, vec!["model_path".to_string()]);
61 assert!(def.input_schema.properties.contains_key("model_path"));
62 }
63
64 #[test]
65 fn missing_model_path_returns_error() {
66 let result = call(&serde_json::json!({}));
67 assert_eq!(result.is_error, Some(true));
68 assert!(result.content[0].text.contains("model_path"));
69 }
70
71 #[test]
72 fn nonstring_model_path_returns_error() {
73 let result = call(&serde_json::json!({ "model_path": 42 }));
74 assert_eq!(result.is_error, Some(true));
75 }
76}