Sponsored by Deepsite.site

Patch File MCP

Created By
PyneSys9 months ago
An MCP Server to patch existing files using block format
Content

Patch File MCP

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.

Overview

Patch File MCP provides a simple way to modify files by applying patches in block format. The key benefits include:

  • Makes targeted changes to specific parts of files without rewriting the entire content
  • Supports multiple patches to the same file in a single request
  • Ensures safety through exact text matching and uniqueness verification
  • Better alternative to the edit_block tool from desktop-commander for most file editing tasks

Installation

Using uvx

This method uses uvx (from the uv Python package manager) to run the server without permanent installation:

Prerequisites

Install uvx from uv if you don't have it already.

Set up MCP Client (Claude Desktop, Cursor, etc.)

Merge the following config with your existing config file (e.g. claude_desktop_config.json):

{
  "mcpServers": {
    "patch-file": {
      "command": "uvx",
      "args": [
        "patch-file-mcp",
        "--allowed-dir", "/Users/your-username/projects",
        "--allowed-dir", "/Users/your-username/Documents/code"
      ]
    }
  }
}

Note: Replace /Users/your-username with the actual path to your own projects and code directories.

Install from Source

Prerequisites

  • Python 3.11 or higher
  • Pip package manager

Clone the repository

git clone https://github.com/your-username/patch-file-mcp.git
cd patch-file-mcp
python -m venv venv
source venv/bin/activate
pip install -e .

Set up MCP Client (Claude Desktop, Cursor, etc.)

Merge the following config with your existing config file (e.g. claude_desktop_config.json):

{
  "mcpServers": {
    "patch-file": {
      "command": "path/to/your/venv/bin/patch-file-mcp",
      "args": [
        "--allowed-dir", "/Users/your-username/projects",
        "--allowed-dir", "/Users/your-username/Documents/code"
      ]
    }
  }
}

Note: Replace /Users/your-username with the actual path to your own projects and code directories.

Arguments

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. It is optional. If not provided, the server will only have access to the home directory of the user running the server.

Usage

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.

Tools

Patch File MCP provides one main tool:

patch_file

Update the file by applying a patch/edit to it using block format.

patch_file(file_path: str, patch_content: str)
  • file_path: Path to the file to be patched.
  • patch_content: Content to search and replace in the file using block format with SEARCH/REPLACE markers. Multiple blocks are supported.

The patch content must have the following format:

<<<<<<< SEARCH
Text to find in the file
=======
Text to replace it with
>>>>>>> REPLACE

You can include multiple search-replace blocks in a single request:

<<<<<<< SEARCH
First text to find
=======
First replacement
>>>>>>> REPLACE
<<<<<<< SEARCH
Second text to find
=======
Second replacement
>>>>>>> REPLACE

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.

Example Workflow

  1. Begin a conversation with Claude about modifying a file in your project
  2. Claude generates a block format patch that makes the desired changes
  3. Claude uses patch_file to apply these changes to your file
  4. If the patch fails, Claude provides detailed error information to help you fix the issue

Security Considerations

  • All file operations are restricted to allowed directories
  • Search texts must appear exactly once in the file to ensure correct targeting
  • Detailed error reporting helps identify and fix issues
  • Each patch operation is validated before being applied

Advantages over similar tools

  • Multiple blocks in one operation: Can apply several changes in a single call
  • Safety checks: Ensures the correct sections are modified through exact matching
  • Detailed errors: Provides clear feedback when patches can't be applied

Dependencies

  • fastmcp (>=2.2.0, <3.0.0)

License

MIT

Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
WindsurfThe new purpose-built IDE to harness magic
DeepChatYour AI Partner on Desktop
Tavily Mcp
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
Serper MCP ServerA Serper MCP Server
ChatWiseThe second fastest AI chatbot™
Y GuiA web-based graphical interface for AI chat interactions with support for multiple AI models and MCP (Model Context Protocol) servers.
Amap Maps高德地图官方 MCP Server
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题; Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
CursorThe AI Code Editor
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
Playwright McpPlaywright MCP server