Skip to content

Add diff_files capability for file comparison #62

@abderraouf-belalia

Description

@abderraouf-belalia

Feature Request

Add a new diff_files tool to enable file comparison capabilities in the MCP filesystem server.

Motivation

This feature would complement existing file operations by allowing:

  • Comparison of file versions before/after edits
  • Content verification in merge/review workflows
  • Debugging file synchronization issues
  • Integration with version control workflows

Proposed Implementation

Tool: diff_files

Parameters:

  • path1 (string): First file path to compare
  • path2 (string): Second file path to compare
  • max_file_size_bytes (optional number): Maximum file size to compare (default: 10MB)

Behavior:

  • Text files: Generate unified diff format (using existing similar crate)
  • Binary files: Compare SHA-256 hashes and report match/mismatch
  • Read-only operation: read_only_hint=true, destructive_hint=false, idempotent_hint=true

Output format:

  • Unified diff in markdown code block for text files
  • Hash comparison result for binary files
  • Clear error messages for access denied, file not found, or size exceeded

Technical Details

  • Leverages existing dependencies: similar=2.7, sha2=0.10.9, infer=0.19.0
  • Follows established patterns from read_text_file and edit_file tools
  • Implements proper path validation via validate_path()
  • Respects allowed directory restrictions
  • File size limits to prevent memory issues

Scope

Starting with simple file-to-file comparison. Future enhancements could include:

  • Directory comparison
  • Content-vs-string diff
  • Additional output formats (JSON, stats-only)

Checklist

  • Implement tool definition in src/tools/diff_files.rs
  • Add service method in src/fs_service.rs
  • Register in src/tools.rs and src/handler.rs
  • Write comprehensive tests
  • Update docs/capabilities.md
  • Run cargo make check

[agent issue]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions