Skip to main content
Glama

Code Merge MCP 服务器

Code Merge MCP 是一个基于 Model Context Protocol (MCP) 的服务器实现,专为代码文件内容提取、合并和分析而设计。它提供了一套强大的工具,帮助大语言模型(如GPT、Claude)更有效地处理和分析代码库。

核心功能

  • 文件树生成:生成项目文件结构的树状视图

  • 代码合并:将多个文件的内容合并为单一输出

  • 代码分析:提供代码统计信息,如行数和函数数量

  • 智能过滤:支持 .gitignore 规则和自定义黑名单

Related MCP server: MCP File Context Server

技术架构

本项目基于 Model Context Protocol (MCP) SDK 构建,使用 Node.js 实现。主要组件包括:

  • MCP 服务器:处理客户端请求并提供工具功能

  • 工具模块:实现各种代码处理功能

  • 核心库:提供文件系统操作和过滤功能

工具说明

1. get_file_tree

生成项目文件结构的树状视图,支持多种过滤选项。

参数

  • path:目标目录路径

  • use_gitignore:是否使用 .gitignore 规则(可选)

  • ignore_git:是否忽略 .git 目录(可选)

  • custom_blacklist:自定义黑名单项目(可选)

示例输出

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

2. merge_content

将多个文件的内容合并为单一输出,适合准备用于大语言模型的代码分析。

参数

  • path:目标文件或目录路径

  • compress:是否压缩输出(可选)

  • use_gitignore:是否使用 .gitignore 规则(可选)

  • ignore_git:是否忽略 .git 目录(可选)

  • custom_blacklist:自定义黑名单项目(可选)

输出:包含合并后的文件内容和统计信息

3. analyze_code

分析代码文件并提供统计信息,如行数和函数数量。

参数

  • path:目标文件或目录路径

  • language:可选的语言过滤器

  • countLines:是否统计代码行数

  • countFunctions:是否统计函数数量

输出:包含代码分析结果的统计信息

安装与使用

环境要求

  • Node.js (v16.x 或更高版本推荐)

  • npm (通常随 Node.js 一起安装)

从 Git 仓库获取项目

# 克隆仓库
git clone https://github.com/yourusername/code-merge-mcp.git
cd code-merge-mcp

# 安装依赖
npm install

VS Code 配置

在 VS Code 的 mcp_settings.json 中添加:

{
  "mcpServers": {
    "code-merge": {
      "command": "node",
      "args": [
        "<项目完整路径>/src/main.js"
      ],
    }
  }
}

<项目完整路径> 替换为实际路径,例如 C:\Users\username\code-merge-mcp

项目结构

code-merge-mcp/
├── bin/                # 可执行文件目录
│   ├── cli.js           # 命令行入口点
│   └── mcp-server.js    # MCP服务器入口点
├── src/
│   ├── core/           # 核心功能模块
│   │   ├── compressor.js   # 内容压缩
│   │   ├── file-lister.js  # 文件列表生成
│   │   ├── file-reader.js  # 文件读取
│   │   └── filter.js       # 文件过滤
│   ├── tools/          # 工具实现
│   │   ├── analyze_code.js  # 代码分析工具
│   │   ├── get_file_tree.js # 文件树生成工具
│   │   └── merge_content.js # 内容合并工具
│   ├── main.js         # 主入口点
│   └── mcp-server.js   # MCP 服务器实现
├── package.json        # 项目配置
└── README.md           # 项目文档

贡献指南

欢迎提交 Issue 和 Pull Request 来改进这个工具。在提交代码前,请确保:

  1. 代码符合项目的编码规范

  2. 添加适当的测试用例

  3. 更新相关文档

许可证

MIT License

致谢

本项目基于 TownBoats/codeMerge 开发,感谢原作者的贡献。

Available Tools

3 tools
analyze_codeC

Analyzes code files and provides statistics.

ParametersJSON Schema
NameRequiredDescriptionDefault
pathYesThe target file or directory path.
languageNoOptional language filter.
countLinesNoWhether to count lines of code.
countFunctionsNoWhether to count functions.

TDQS

C2.9/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool 'analyzes code files and provides statistics,' implying a read-only operation, but doesn't specify what types of statistics, whether it's resource-intensive, if it handles errors gracefully, or what the output format looks like. This leaves significant gaps in understanding the tool's behavior beyond the basic purpose.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence: 'Analyzes code files and provides statistics.' It is front-loaded with the core purpose and contains no unnecessary words or redundancy, making it highly concise and well-structured.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of a code analysis tool with 4 parameters and no annotations or output schema, the description is incomplete. It lacks details on behavioral traits, output format, error handling, and usage guidelines. While the schema covers parameters, the overall context for effective tool invocation is insufficient, especially for a tool that likely produces varied statistical results.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all four parameters (path, language, countLines, countFunctions) with clear descriptions. The description adds no additional meaning or context about the parameters beyond what's in the schema, such as examples or usage notes. This meets the baseline for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Analyzes code files and provides statistics.' This specifies the verb ('analyzes') and resource ('code files') with the outcome ('provides statistics'). It distinguishes from sibling tools like 'get_file_tree' (which lists files) and 'merge_content' (which combines content), but doesn't explicitly differentiate beyond the general domain of code analysis.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention sibling tools, prerequisites, or specific contexts for usage. The agent must infer usage from the purpose alone, which is insufficient for optimal tool selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

get_file_treeC

Retrieves the file tree structure of the project.

ParametersJSON Schema
NameRequiredDescriptionDefault
pathNoThe target directory path.
use_gitignoreNoWhether to use .gitignore rules.
ignore_gitNoWhether to ignore the .git directory.
custom_blacklistNoCustom blacklist items.

TDQS

C2.9/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states 'Retrieves' which implies a read-only operation, but doesn't cover critical aspects like whether it requires specific permissions, how it handles large directories, or what the output format looks like (e.g., tree structure details). This leaves significant gaps for a tool with 4 parameters.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that directly states the tool's purpose without unnecessary words. It's front-loaded and wastes no space, making it highly concise and well-structured for quick understanding.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of a file tree retrieval tool with 4 parameters and no output schema, the description is incomplete. It doesn't explain the return format (e.g., hierarchical structure), potential limitations (e.g., depth or size constraints), or how parameters interact (e.g., combining gitignore and custom blacklist). Without annotations, this leaves the agent under-informed for effective use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, so parameters like 'path', 'use_gitignore', 'ignore_git', and 'custom_blacklist' are well-documented in the schema. The description adds no additional parameter semantics beyond implying a 'project' context, which is minimal value. Baseline 3 is appropriate as the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'Retrieves' and the resource 'file tree structure of the project', making the purpose understandable. However, it doesn't explicitly differentiate from sibling tools like 'analyze_code' or 'merge_content', which might also involve file operations, so it falls short of a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'analyze_code' or 'merge_content'. It lacks context about scenarios where retrieving a file tree is appropriate, such as for navigation or analysis, leaving the agent to infer usage without explicit direction.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

merge_contentC

Merges content from multiple files into a single output file.

ParametersJSON Schema
NameRequiredDescriptionDefault
pathYesThe target file or directory path.
compressNoWhether to compress the output.
use_gitignoreNoWhether to use .gitignore rules.
ignore_gitNoWhether to ignore the .git directory.
custom_blacklistNoCustom blacklist items.
use_cacheNoWhether to use file content cache.
use_streamsNoWhether to use stream processing for large files.
max_filesNoMaximum number of files to process.

TDQS

C2.9/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the basic operation but lacks critical details: it doesn't specify file formats supported, output location or naming, whether merging is destructive to source files, error handling, or performance characteristics. For a tool with 8 parameters and file system operations, this leaves significant behavioral uncertainty.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that states the core purpose without unnecessary words. It's front-loaded with the essential information ('Merges content from multiple files into a single output file') and contains no redundant or verbose phrasing. Every word serves a clear purpose in conveying the tool's function.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a tool with 8 parameters, no annotations, and no output schema, the description is insufficiently complete. It doesn't address key contextual aspects: what happens to source files after merging, supported file types, output format/location, error conditions, or performance implications. The agent would need to infer or test these behavioral aspects, creating uncertainty in tool selection and invocation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all 8 parameters thoroughly. The description adds no parameter-specific information beyond the general concept of merging files. It doesn't explain how parameters like 'compress', 'use_gitignore', or 'custom_blacklist' affect the merge operation, leaving the schema to carry the full parameter documentation burden.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('merges') and resource ('content from multiple files'), specifying the action and target. It distinguishes from sibling tools like 'analyze_code' and 'get_file_tree' by focusing on file combination rather than analysis or structure retrieval. However, it doesn't explicitly differentiate from hypothetical similar merge tools that might exist elsewhere.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention sibling tools ('analyze_code', 'get_file_tree') or suggest scenarios where merging files is appropriate versus other operations. There's no indication of prerequisites, constraints, or typical use cases.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections. Dates show when Glama detected each change.

  1. 3 tool updates
    • First observedanalyze_code
    • First observedget_file_tree
    • First observedmerge_content

TDQS

B3.2/5.0
Disambiguation5/5

Each tool has a clearly distinct purpose with no overlap: analyze_code focuses on code statistics, get_file_tree on project structure, and merge_content on file merging. An agent can easily tell them apart without confusion.

Naming Consistency5/5

All tools follow a consistent verb_noun pattern (analyze_code, get_file_tree, merge_content), using snake_case throughout. The naming is predictable and readable across the set.

Tool Count3/5

With only 3 tools, the set feels thin for a code merge server, as it lacks operations like conflict resolution, version control integration, or undo capabilities. However, it covers basic analysis and merging functions reasonably.

Completeness3/5

The tools provide analysis, structure retrieval, and merging, but there are notable gaps for a code merge domain, such as handling merge conflicts, comparing files, or reverting changes. Agents might struggle with advanced merge scenarios.

Maintenance

ActivityInactive
ResponsivenessNo issues

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Connectors

Related MCP Servers

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/yy1588133/code-merge-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server