Skip to content

feat(filesystem): add compare_files tool for file diff comparison#4024

Open
factspark23-hash wants to merge 1 commit intomodelcontextprotocol:mainfrom
factspark23-hash:feat/compare-files
Open

feat(filesystem): add compare_files tool for file diff comparison#4024
factspark23-hash wants to merge 1 commit intomodelcontextprotocol:mainfrom
factspark23-hash:feat/compare-files

Conversation

@factspark23-hash
Copy link
Copy Markdown

What

Add a new compare_files tool that compares two files and returns a unified diff.

Why

Currently there is no way to compare two files through MCP. Users often need to:

  • Verify an edit was applied correctly
  • Understand differences between file versions
  • Review changes before committing

Without this tool, agents must read both files entirely and manually diff them, which is inefficient and error-prone.

How

compare_files({
  file1: "path/to/original.ts",
  file2: "path/to/modified.ts",
  contextLines: 3  // optional, default 3
})

Returns unified diff output, or reports files as identical.

Changes

  • src/filesystem/index.ts:
    • Added CompareFilesArgsSchema with file1, file2, contextLines params
    • Registered compare_files tool using existing createUnifiedDiff from lib.ts
    • Both files must be within allowed directories

New tool that compares two files and returns a unified diff output.
- Shows exactly what changed between two files
- Configurable context lines (default: 3)
- Reports when files are identical
- Uses existing createUnifiedDiff utility
- Both files must be within allowed directories

Useful for code review, change verification, and understanding
differences between file versions.
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.

1 participant