Code Merge MCP server

Enables code analysis and merging from multiple files in a project with efficient handling of file trees, content compression, and filtering through .gitignore rules for comprehensive codebase context.
Back to servers
Setup instructions
Provider
yy1588133
Release date
Apr 09, 2025
Language
TypeScript
Stats
20 stars

The Code Merge MCP server is a tool designed for code file extraction, merging, and analysis based on the Model Context Protocol (MCP). It helps large language models like GPT and Claude more effectively process and analyze codebases through a set of specialized tools.

Installation Requirements

Prerequisites

  • Node.js (v16.x or higher recommended)
  • npm (typically installed with Node.js)

Installation Steps

# Clone the repository
git clone https://github.com/yourusername/code-merge-mcp.git
cd code-merge-mcp

# Install dependencies
npm install

VS Code Configuration

Add the following to your mcp_settings.json file in VS Code:

{
  "mcpServers": {
    "code-merge": {
      "command": "node",
      "args": [
        "<full-project-path>/src/main.js"
      ],
    }
  }
}

Replace <full-project-path> with the actual path to your project, for example: C:\Users\username\code-merge-mcp.

Available Tools

File Tree Generation

The get_file_tree tool generates a tree view of your project's file structure with various filtering options.

Parameters:

  • path: Target directory path
  • use_gitignore: Whether to use .gitignore rules (optional)
  • ignore_git: Whether to ignore the .git directory (optional)
  • custom_blacklist: Custom blacklist items (optional)

Example output:

project/
├── src/
│   ├── main.js
│   └── utils/
│       └── helper.js
├── tests/
│   └── test.js
└── README.md

Content Merging

The merge_content tool combines content from multiple files into a single output, ideal for preparing code for analysis by large language models.

Parameters:

  • path: Target file or directory path
  • compress: Whether to compress output (optional)
  • use_gitignore: Whether to use .gitignore rules (optional)
  • ignore_git: Whether to ignore the .git directory (optional)
  • custom_blacklist: Custom blacklist items (optional)

Output: Combined file content with statistics

Code Analysis

The analyze_code tool analyzes code files and provides statistical information such as line count and function count.

Parameters:

  • path: Target file or directory path
  • language: Optional language filter
  • countLines: Whether to count lines of code
  • countFunctions: Whether to count functions

Output: Statistical information containing code analysis results

Usage Examples

Generating a File Tree

To generate a file tree for your project while ignoring files specified in .gitignore:

// Example MCP API call
const response = await mcp.call("get_file_tree", {
  path: "/path/to/your/project",
  use_gitignore: true,
  ignore_git: true
});
console.log(response);

Merging Code Content

To merge all code files in a directory for analysis:

// Example MCP API call
const mergedContent = await mcp.call("merge_content", {
  path: "/path/to/your/project/src",
  compress: false,
  use_gitignore: true,
  custom_blacklist: ["node_modules", "dist"]
});
console.log(mergedContent);

Analyzing Code

To analyze code statistics in your project:

// Example MCP API call
const analysis = await mcp.call("analyze_code", {
  path: "/path/to/your/project/src",
  language: "javascript",
  countLines: true,
  countFunctions: true
});
console.log(analysis);

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "code-merge" '{"command":"node","args":["<\u9879\u76ee\u5b8c\u6574\u8def\u5f84>/src/main.js"]}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "code-merge": {
            "command": "node",
            "args": [
                "<\u9879\u76ee\u5b8c\u6574\u8def\u5f84>/src/main.js"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "code-merge": {
            "command": "node",
            "args": [
                "<\u9879\u76ee\u5b8c\u6574\u8def\u5f84>/src/main.js"
            ]
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later