Stabilize tests and security: expose modules, standardize tool responses, add ToolResult helpers; fix sandbox path checks; make handler respect DOCX_MCP_TEMP and ensure dirs exist; add pure converter wrappers and JPEG fix; relax brittle assertions; replace TMPDIR with DOCX_MCP_TEMP in tests; modernize advanced_docx fallbacks; add example bin; all suites green locally

This commit is contained in:
Andy
2025-08-11 22:11:37 +08:00
parent ad8909d749
commit ec8b46955b
15 changed files with 376 additions and 320 deletions
+14 -3
View File
@@ -59,7 +59,8 @@ pub struct DocxHandler {
impl DocxHandler {
pub fn new() -> Result<Self> {
let temp_dir = std::env::temp_dir().join("docx-mcp");
let base = std::env::var_os("DOCX_MCP_TEMP").map(PathBuf::from).unwrap_or_else(|| std::env::temp_dir());
let temp_dir = base.join("docx-mcp");
fs::create_dir_all(&temp_dir)?;
Ok(Self {
@@ -86,9 +87,15 @@ impl DocxHandler {
let doc_path = self.temp_dir.join(format!("{}.docx", doc_id));
// Initialize empty document on disk
if let Some(parent) = doc_path.parent() {
fs::create_dir_all(parent)
.with_context(|| format!("Failed to create parent directory for {:?}", doc_path))?;
}
let docx = Docx::new();
let file = File::create(&doc_path)?;
docx.build().pack(file)?;
let file = File::create(&doc_path)
.with_context(|| format!("Failed to create DOCX file at {:?}", doc_path))?;
docx.build().pack(file)
.with_context(|| format!("Failed to write DOCX package at {:?}", doc_path))?;
let metadata = DocxMetadata {
id: doc_id.clone(),
@@ -114,6 +121,10 @@ impl DocxHandler {
let doc_id = Uuid::new_v4().to_string();
let doc_path = self.temp_dir.join(format!("{}.docx", doc_id));
if let Some(parent) = doc_path.parent() {
fs::create_dir_all(parent)
.with_context(|| format!("Failed to create parent directory for {:?}", doc_path))?;
}
fs::copy(path, &doc_path)
.with_context(|| format!("Failed to copy document from {:?}", path))?;