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.
# Clone the repository
git clone https://github.com/yourusername/code-merge-mcp.git
cd code-merge-mcp
# Install dependencies
npm install
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
.
The get_file_tree
tool generates a tree view of your project's file structure with various filtering options.
Parameters:
path
: Target directory pathuse_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
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 pathcompress
: 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
The analyze_code
tool analyzes code files and provides statistical information such as line count and function count.
Parameters:
path
: Target file or directory pathlanguage
: Optional language filtercountLines
: Whether to count lines of codecountFunctions
: Whether to count functionsOutput: Statistical information containing code analysis results
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);
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);
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);
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.
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.
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"
]
}
}
}
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.
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.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.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