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
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

This commit adds two new tools to the filesystem server:

1. **append_file**: Appends content to the end of an existing file.
   - File must already exist
   - Preserves existing content, adds new content at the end

2. **write_or_update_file**: Creates a new file or appends to an existing file.
   - If file doesn't exist: creates it with the provided content
   - If file exists: appends new content to the end
   - Useful when you want to add content while preserving existing data

Changes include:
- Added `appendFileContent` and `writeOrUpdateFileContent` functions to lib.ts
- Added tool registrations and schemas to index.ts
- Updated README.md with new tool documentation
- Added comprehensive tests for the new functions

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@agn-7 agn-7 force-pushed the feat/filesystem-append-tools branch from d4d0d52 to d15eb75 Compare December 24, 2025 06:15
@agn-7
Copy link
Author

agn-7 commented Dec 24, 2025

I just resolved the merge conflicts in my previously submitted PR. Could you please review it to help prevent future conflicts?

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