Skip to content

Conversation

agn-7
Copy link

@agn-7 agn-7 commented Oct 3, 2025

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:

  1. append_file: Safe appending to existing files (fails if file doesn't exist)
  2. 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)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Protocol Documentation
  • My changes follows MCP security best practices
  • I have updated the server's README accordingly
  • I have tested this with an LLM client
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • 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

agn-7 added 7 commits October 3, 2025 18:43
…functions

Add two new file content operations:
- appendFileContent: appends content to existing files
- writeOrUpdateFileContent: creates or appends to files

Both functions use atomic write operations with temporary files
for safe file modifications.
Add two new MCP tools for enhanced file operations:

- append_file: Appends content to existing files without overwriting
- write_or_update_file: Creates new files or appends to existing ones

These tools provide more flexible file modification options compared
to the existing write_file tool which always overwrites content.
Add comprehensive unit tests for:
- appendFileContent: file existence checks, content appending, error handling
- writeOrUpdateFileContent: file creation, appending, error scenarios

All tests follow existing patterns and include proper mocking.
…file tools

Add documentation for the two new tools in the API section:
- append_file: append content to existing files
- write_or_update_file: create or append to files

Also updated the Features section to highlight the new capabilities.
@agn-7
Copy link
Author

agn-7 commented Oct 8, 2025

Hi

I really need this feature. could you please take a look?

@olaservo @sebastien-rosset @Finndersen @domdomegg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

filesystem: write_or_update_file

1 participant