Skip to content

Conversation

@abderraouf-belalia
Copy link

Summary

Implements a new diff_files tool that enables file comparison within the MCP filesystem server.

Closes #62

Changes

New Tool: diff_files

  • Parameters:

    • path1 (string): First file path to compare
    • path2 (string): Second file path to compare
    • maxFileSizeBytes (optional, default: 10MB): Maximum file size limit
  • Behavior:

    • Text files: Generates unified diff format showing additions/deletions
    • Binary files: Compares SHA-256 hashes and reports match/mismatch
    • Read-only operation: No filesystem modifications

Implementation Details

Files Modified/Created:

  • src/tools/diff_files.rs - Tool definition with schema
  • src/fs_service.rs - Service layer implementation with binary detection
  • src/tools.rs - Tool registration in macros
  • src/handler.rs - Handler dispatch registration
  • Cargo.toml - Added hex dependency for hash encoding
  • docs/capabilities.md - Updated documentation (24→25 tools)
  • tests/test_tools.rs - 8 comprehensive test cases

Key Features:

  • Automatic binary detection via null byte scanning
  • Configurable file size limits to prevent memory issues
  • Path validation respecting allowed directories
  • Consistent error handling with existing patterns
  • Line ending normalization for cross-platform diffs

Test Coverage

Added 8 test cases covering:

  • ✅ Identical text files
  • ✅ Different text files with unified diff
  • ✅ Identical binary files (hash comparison)
  • ✅ Different binary files (hash comparison)
  • ✅ Access control (files outside allowed directories)
  • ✅ Non-existent files
  • ✅ File size limit enforcement
  • ✅ Multi-line changes with context

All 131 tests passing (cargo make check ✓)

Test Plan

cargo make check  # All tests pass
cargo build       # Compiles successfully
cargo install --path . --force  # Local installation successful

Manual testing completed:

  • Compare two identical text files
  • Compare two different text files
  • Compare binary files
  • Test file size limits
  • Test access control boundaries
  • Installed locally and verified MCP integration

[agent pull request]

Abderraouf Belalia added 4 commits October 29, 2025 02:34
Implements rust-mcp-stack#60 - Add line numbering flag for read_text_file

Changes:
- Added `with_line_numbers` optional parameter to ReadTextFile struct
- Updated read_text_file service method to format output with line numbers
- Line numbers are right-aligned (6 digits) with pipe separator format
- Uses 1-based indexing for line numbers
- Maintains backward compatibility (defaults to false)
- Added comprehensive unit tests for various scenarios
- Updated CHANGELOG.md with feature description

This feature enables AI agents to obtain file content with line numbers
in a single tool invocation, improving efficiency for code modification
tasks that require precise line-based targeting.

[agent commit]
Implements a new diff_files tool that compares two files and returns:
- Unified diff format for text files
- SHA-256 hash comparison for binary files

Features:
- Configurable file size limit (default: 10MB)
- Automatic binary detection via null bytes check
- Read-only operation (no filesystem modification)
- Comprehensive test coverage (8 test cases)

Closes rust-mcp-stack#62

[agent commit]
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.

Add diff_files capability for file comparison

1 participant