servers
servers copied to clipboard
feat(filesystem): add append_file and write_or_update_file tools
Description
Fixes #2807
Added two new tools to the filesystem MCP server for enhanced file modification capabilities:
-
append_file: Appends content to existing files without overwriting -
write_or_update_file: Creates new files or appends to existing ones (smart create-or-append)
These tools complement the existing write_file tool by providing non-destructive file operations, addressing the common use case where users want to add content to files while preserving existing data.
Server Details
- Server: filesystem
- Changes to: tools (added 2 new tools), core library functions, tests
Motivation and Context
The existing write_file tool always overwrites file content, which is problematic when users want to:
- Add content to existing log files or documents
- Incrementally build up file content
- Preserve existing data while adding new information
These new tools solve this by providing:
- append_file: Safe appending to existing files (fails if file doesn't exist)
- write_or_update_file: Flexible create-or-append operation (creates if needed, appends if exists)
How Has This Been Tested?
- ✅ Tested with MCP client using local build
- ✅ All unit tests pass (51/51)
- ✅ Tested scenarios:
- Appending to existing files
- Creating new files with write_or_update_file
- Appending to existing files with write_or_update_file
- Error handling (file not found, permission errors)
- Atomic write operations with concurrent access
Breaking Changes
No breaking changes. These are new tools that don't affect existing functionality.
Types of changes
- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
- [ ] Documentation update
Checklist
- [x] I have read the MCP Protocol Documentation
- [x] My changes follows MCP security best practices
- [x] I have updated the server's README accordingly
- [x] I have tested this with an LLM client
- [x] My code follows the repository's style guidelines
- [x] New and existing tests pass locally
- [x] I have added appropriate error handling
- [x] I have documented all environment variables and configuration options
Additional context
Implementation details:
- Both functions use atomic write operations (temp file + rename) for safety
- Follow existing patterns from the codebase for consistency
- Proper error handling and cleanup of temporary files
- Comprehensive test coverage added (6 new test cases)
- Tool descriptions clearly explain use cases and differences
Hi
I really need this feature. could you please take a look?
@olaservo @sebastien-rosset @Finndersen @domdomegg