Simple file update mechanism that uses unified diff patches
Configuration
View docs{
"mcpServers": {
"shenning00-patch_mcp": {
"command": "python",
"args": [
"-m",
"patch_mcp"
]
}
}
}Patch MCP Server enables an AI assistant to safely apply unified diff patches to files with built-in validation, backups, and rollback. It provides atomic multi-hunk patches, dry-run testing, and strong security checks to prevent unsafe modifications, giving you reliable patch management for local projects.
You interact with Patch MCP Server through an MCP client to apply, validate, inspect, or revert patches. Start by running the server locally and then issue patch operations from your client whenever you need to modify files in a controlled, auditable way. All actions support automatic backups and safety checks so you can test changes before they are committed.
Prerequisites: Python 3.8+ and a working environment for running Python modules.
1) Clone the project repository to your machine.
2) Create and activate a Python virtual environment.
3) Install the package in editable mode with development dependencies.
4) Run the server in standalone mode so it communicates via the Model Context Protocol.
Configure your MCP client to connect to the local Patch MCP Server using stdio mode. The server runs as a local process and can be started from the command line.
# Start the server locally
python -m patch_mcpAll operations include security checks to prevent unsafe changes. The server rejects symlinks, binary files, and path traversals, enforces maximum file sizes, validates available disk space, and ensures atomic file replacements so partial patches cannot leave files in an inconsistent state.
If a patch cannot be applied, revert to the most recent backup before trying again. Ensure the patch accurately matches the target file and that the patch is valid for the current file state.
Apply a unified diff patch to a file with support for multi-hunk patches, dry-run testing, and automatic validation.
Check if a patch can be applied without modifying files, including context mismatch detection and preview of changes.
Reverse a previously applied patch, supporting multi-hunk patches and requiring the original patch.
Create a patch from two file versions in standard unified diff format with configurable context.
Analyze patch content without applying changes to files, listing affected files and patch structure.
Create timestamped backups of files before applying patches, preserving metadata.
Restore from backups with safety checks to prevent unintended overwrites.