diff --git a/crates/goose-mcp/src/developer/mod.rs b/crates/goose-mcp/src/developer/mod.rs index 0c09e20c..7d9c0a86 100644 --- a/crates/goose-mcp/src/developer/mod.rs +++ b/crates/goose-mcp/src/developer/mod.rs @@ -251,6 +251,19 @@ impl DeveloperRouter { .map_err(|e| ToolError::ExecutionError(e.to_string()))?; let output_str = String::from_utf8_lossy(&output.stdout); + + // Check the character count of the output + const MAX_CHAR_COUNT: usize = 400_000; // 409600 chars = 400KB + let char_count = output_str.chars().count(); + if char_count > MAX_CHAR_COUNT { + return Err(ToolError::ExecutionError(format!( + "Shell output from command '{}' has too many characters ({}). Maximum character count is {}.", + command, + char_count, + MAX_CHAR_COUNT + ))); + } + Ok(vec![ Content::text(output_str.clone()).with_audience(vec![Role::Assistant]), Content::text(output_str) @@ -312,9 +325,9 @@ impl DeveloperRouter { async fn text_editor_view(&self, path: &PathBuf) -> Result, ToolError> { if path.is_file() { - // Check file size first (2MB limit) - const MAX_FILE_SIZE: u64 = 2 * 1024 * 1024; // 2MB in bytes - const MAX_CHAR_COUNT: usize = 1 << 20; // 2^20 characters (1,048,576) + // Check file size first (400KB limit) + const MAX_FILE_SIZE: u64 = 400 * 1024; // 400KB in bytes + const MAX_CHAR_COUNT: usize = 400_000; // 409600 chars = 400KB let file_size = std::fs::metadata(path) .map_err(|e| { @@ -324,9 +337,9 @@ impl DeveloperRouter { if file_size > MAX_FILE_SIZE { return Err(ToolError::ExecutionError(format!( - "File '{}' is too large ({:.2}MB). Maximum size is 2MB to prevent memory issues.", + "File '{}' is too large ({:.2}KB). Maximum size is 400KB to prevent memory issues.", path.display(), - file_size as f64 / 1024.0 / 1024.0 + file_size as f64 / 1024.0 ))); } @@ -778,8 +791,8 @@ mod tests { let many_chars_path = temp_dir.path().join("many_chars.txt"); let many_chars_str = many_chars_path.to_str().unwrap(); - // Create a file with more than 2^20 characters but less than 2MB - let content = "x".repeat((1 << 20) + 1); // 2^20 + 1 characters + // Create a file with more than 400K characters but less than 400KB + let content = "x".repeat(405_000); std::fs::write(&many_chars_path, content).unwrap(); let result = router