diff --git a/src/docx_tools.rs b/src/docx_tools.rs index b5f3551..cef0b8c 100644 --- a/src/docx_tools.rs +++ b/src/docx_tools.rs @@ -1856,16 +1856,25 @@ impl DocxToolsProvider { hint: Some("Check list_templates for available names".to_string()), } } else { - // Open template let mut handler = self.handler.write().unwrap(); + + // Open template let doc_id = match handler.open_document(&template_path) { Ok(id) => id, Err(e) => { drop(handler); - return ToolOutcome::Error { - code: ErrorCode::InternalError, - error: e.to_string(), - hint: None, + return CallToolResponse { + content: vec![ToolResponseContent::Text(TextContent { + content_type: "application/json".into(), + text: serde_json::json!({ + "success": false, + "error": e.to_string(), + "code": ErrorCode::InternalError + }).to_string(), + annotations: None, + })], + is_error: Some(true), + meta: None, }; } }; @@ -1882,9 +1891,9 @@ impl DocxToolsProvider { &doc_id, &placeholder, &val_str, - false, // case_sensitive: false for placeholders - true, // whole_word: true (treat placeholder as whole token) - false, // use_regex: false + false, + true, + false, ) { replace_count += count; } @@ -1892,9 +1901,8 @@ impl DocxToolsProvider { // Save generated document let out_path = PathBuf::from(output_path); - let result = if out_path.parent().is_some() { - if let Err(e) = std::fs::create_dir_all(out_path.parent().unwrap()) { - drop(handler); + let result = if let Some(parent) = out_path.parent() { + if let Err(e) = std::fs::create_dir_all(parent) { ToolOutcome::Error { code: ErrorCode::InternalError, error: format!("Failed to create output directory: {}", e),