Skip to content

Commit f62a0d5

Browse files
committed
Update README to reflect changes from unified diff format to block format, enhance installation instructions, and clarify usage examples for patch_file tool.
1 parent 1bdac30 commit f62a0d5

File tree

1 file changed

+81
-75
lines changed

1 file changed

+81
-75
lines changed

README.md

Lines changed: 81 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,29 @@
11
# Patch File MCP
22

3-
An MCP Server to patch existing files using unified diff format. This allows AI agents (like Claude) to make precise changes to files in your projects.
3+
An MCP Server to patch existing files using block format. This allows AI agents (like Claude) to make precise changes to files in your projects.
44

55
## Overview
66

7-
Patch File MCP provides a simple way to modify files by applying patches in unified diff format. The key benefits include:
7+
Patch File MCP provides a simple way to modify files by applying patches in block format. The key benefits include:
88

99
- Makes targeted changes to specific parts of files without rewriting the entire content
10-
- Supports multiple patches to the same file
11-
- Safer than complete file rewrites since it only affects the specified sections
10+
- Supports multiple patches to the same file in a single request
11+
- Ensures safety through exact text matching and uniqueness verification
1212
- Better alternative to the `edit_block` tool from `desktop-commander` for most file editing tasks
1313

1414
## Installation
1515

16-
### Local installation
16+
### Using uvx
1717

18-
#### Prerequisites
19-
20-
- Python 3.11 or higher
21-
- Pip package manager
22-
23-
#### Install from PyPI
24-
25-
```bash
26-
pip install patch-file-mcp
27-
```
28-
29-
#### Install from Source
30-
31-
```bash
32-
git clone https://github.com/your-username/patch-file-mcp.git
33-
cd patch-file-mcp
34-
pip install -e .
35-
```
36-
37-
## Usage
38-
39-
The MCP server is started by the client (e.g., Claude Desktop) based on the configuration you provide. You don't need to start the server manually.
18+
This method uses `uvx` (from the `uv` Python package manager) to run the server without permanent installation:
4019

41-
### Integration with Claude Desktop
20+
#### Prerequisites
4221

43-
To use this MCP server with Claude Desktop, you need to add it to your `claude_desktop_config.json` file:
22+
Install `uvx` from [uv](https://docs.astral.sh/uv/installation/) if you don't have it already.
4423

45-
#### Using uvx (Recommended)
24+
#### Set up MCP Client (Claude Desktop, Cursor, etc.)
4625

47-
This method uses `uvx` (from the `uv` Python package manager) to run the server without permanent installation:
26+
Merge the following config with your existing config file (e.g. `claude_desktop_config.json`):
4827

4928
```json
5029
{
@@ -61,15 +40,34 @@ This method uses `uvx` (from the `uv` Python package manager) to run the server
6140
}
6241
```
6342

64-
#### Using pip installed version
43+
> **Note:** Replace `/Users/your-username` with the actual path to your own projects and code directories.
44+
45+
### Install from Source
46+
47+
#### Prerequisites
48+
49+
- Python 3.11 or higher
50+
- Pip package manager
51+
52+
#### Clone the repository
53+
54+
```bash
55+
git clone https://github.com/your-username/patch-file-mcp.git
56+
cd patch-file-mcp
57+
python -m venv venv
58+
source venv/bin/activate
59+
pip install -e .
60+
```
61+
62+
#### Set up MCP Client (Claude Desktop, Cursor, etc.)
6563

66-
If you've installed the package with pip:
64+
Merge the following config with your existing config file (e.g. `claude_desktop_config.json`):
6765

6866
```json
6967
{
7068
"mcpServers": {
7169
"patch-file": {
72-
"command": "patch-file-mcp",
70+
"command": "path/to/your/venv/bin/patch-file-mcp",
7371
"args": [
7472
"--allowed-dir", "/Users/your-username/projects",
7573
"--allowed-dir", "/Users/your-username/Documents/code"
@@ -79,74 +77,82 @@ If you've installed the package with pip:
7977
}
8078
```
8179

82-
### Configuring Claude Desktop
80+
> **Note:** Replace `/Users/your-username` with the actual path to your own projects and code directories.
8381
84-
1. Install Claude Desktop from the [official website](https://claude.ai/desktop)
85-
2. Open Claude Desktop
86-
3. From the menu, select Settings → Developer → Edit Config
87-
4. Add the MCP configuration above to your existing config (modify paths as needed)
88-
5. Save and restart Claude Desktop
82+
## Arguments
8983

90-
## Tools
84+
The `--allowed-dir` argument is used to specify the directories that the server has access to. You can use it multiple times to allow access to multiple directories. All directories inside the allowed directories are also allowed.
85+
It is optional. If not provided, the server will only have access to the home directory of the user running the server.
9186

92-
Patch File MCP provides one main tool:
87+
## Usage
9388

94-
### patch_file
89+
The MCP server is started by the client (e.g., Claude Desktop) based on the configuration you provide. You don't need to start the server manually.
9590

96-
Updates a file by applying a unified diff/patch to it.
91+
### Tools
9792

98-
```
99-
patch_file(file_path: str, patch_content: str)
100-
```
93+
Patch File MCP provides one main tool:
10194

102-
**Parameters:**
103-
- `file_path`: Path to the file to be patched
104-
- `patch_content`: Unified diff/patch content to apply to the file
95+
#### patch_file
10596

106-
**Notes:**
107-
- The file must exist and be within an allowed directory
108-
- The patch must be in valid unified diff format
109-
- If the patch fails to apply, an error is raised
97+
Update the file by applying a patch/edit to it using block format.
11098

111-
## Example Workflow
99+
```python
100+
patch_file(file_path: str, patch_content: str)
101+
```
102+
- **file_path**: Path to the file to be patched.
103+
- **patch_content**: Content to search and replace in the file using block format with SEARCH/REPLACE markers. Multiple blocks are supported.
112104

113-
1. Begin a conversation with Claude about modifying a file in your project
114-
2. Claude generates a unified diff/patch that makes the desired changes
115-
3. Claude uses `patch_file` to apply these changes to your file
116-
4. If the patch fails, Claude might suggest using `write_file` from another MCP as an alternative
105+
The patch content must have the following format:
117106

118-
## Creating Unified Diffs
107+
```
108+
<<<<<<< SEARCH
109+
Text to find in the file
110+
=======
111+
Text to replace it with
112+
>>>>>>> REPLACE
113+
```
119114

120-
A unified diff typically looks like:
115+
You can include multiple search-replace blocks in a single request:
121116

122117
```
123-
--- oldfile
124-
+++ newfile
125-
@@ -start,count +start,count @@
126-
context line
127-
-removed line
128-
+added line
129-
context line
118+
<<<<<<< SEARCH
119+
First text to find
120+
=======
121+
First replacement
122+
>>>>>>> REPLACE
123+
<<<<<<< SEARCH
124+
Second text to find
125+
=======
126+
Second replacement
127+
>>>>>>> REPLACE
130128
```
131129

132-
Claude can generate these diffs automatically when suggesting file changes.
130+
This tool verifies that each search text appears exactly once in the file to ensure the correct section is modified. If a search text appears multiple times or isn't found, it will report an error.
133131

134-
## Recent Changes
132+
## Example Workflow
133+
134+
1. Begin a conversation with Claude about modifying a file in your project
135+
2. Claude generates a block format patch that makes the desired changes
136+
3. Claude uses `patch_file` to apply these changes to your file
137+
4. If the patch fails, Claude provides detailed error information to help you fix the issue
135138

136-
### 2025-04-23 Bugfixes
137-
- Fixed an issue where the patch operation would fail with "Not a directory" error when trying to apply patches.
138-
- Updated the patching logic to use the parent directory as the root for patch application, rather than the file itself.
139139

140140
## Security Considerations
141141

142142
- All file operations are restricted to allowed directories
143-
- The tool only modifies specified sections of files
143+
- Search texts must appear exactly once in the file to ensure correct targeting
144+
- Detailed error reporting helps identify and fix issues
144145
- Each patch operation is validated before being applied
145146

147+
## Advantages over similar tools
148+
149+
- **Multiple blocks in one operation**: Can apply several changes in a single call
150+
- **Safety checks**: Ensures the correct sections are modified through exact matching
151+
- **Detailed errors**: Provides clear feedback when patches can't be applied
152+
146153
## Dependencies
147154

148155
- fastmcp (>=2.2.0, <3.0.0)
149-
- patch-ng (>=1.18.0, <2.0.0)
150156

151157
## License
152158

0 commit comments

Comments
 (0)