trackmcp
Back to directory
fashionzzz

code-line-counter-mcp

View on GitHub

这是一个MCP(Model Context Protocol)工具,用于统计AI生成的代码行数。该工具可以帮助您跟踪和分析每次AI生成的代码的规模。

1 stars JavaScriptAI & Machine Learning Updated Sep 12, 2025
code-line-countercode-linesmcpmcp-server

Documentation

Code Line Counter MCP Tool

这是一个MCP(Model Context Protocol)工具,用于统计AI生成的代码行数。该工具可以帮助您跟踪和分析每次AI生成的代码的规模。

功能

1. count_code_lines: 统计给定代码的行数信息,包括总行数、代码行数、注释行数和空行数

2. get_statistics: 获取代码行数的统计信息,支持按时间范围筛选

安装

bash
npm install

使用

bash
npm start

集成到MCP客户端

要将此工具集成到MCP客户端中,您需要执行以下步骤:

1. 启动MCP服务器

首先,确保MCP服务器正在运行:

bash
npm start

服务器将监听标准输入/输出,等待MCP客户端的连接。

2. 在MCP客户端中配置工具

在您的MCP客户端配置中,添加对此工具服务器的引用。具体的配置方式取决于您使用的MCP客户端实现。

对于基于JSON的配置,通常需要添加类似以下的配置:

json
{
  "tools": [
    {
      "name": "code-line-counter",
      "type": "process",
      "command": "node",
      "args": ["src/index.js"],
      "cwd": "/path/to/code-line-counter-mcp"
    }
  ]
}

3. 使用工具

一旦集成完成,您可以在AI助手会话中使用以下工具:

1. count_code_lines - 当AI生成代码时,自动调用此工具统计代码行数

2. get_statistics - 查询历史统计信息

客户端会自动处理工具的调用和结果返回。

工具说明

count_code_lines

统计代码行数的工具。

参数:

  • `fileType` (string, 必需): 代码文件类型,例如:javascript, python, java等
  • `code` (string, 必需): 需要统计的代码内容

返回:

  • 代码行数统计结果,包括总行数、代码行数、注释行数和空行数

get_statistics

获取代码行数统计信息。

参数:

  • `startTime` (string, 可选): 开始时间,ISO格式 (例如: "2023-01-01T00:00:00Z")
  • `endTime` (string, 可选): 结束时间,ISO格式 (例如: "2023-12-31T23:59:59Z")

返回:

  • 代码行数统计信息,包括总文件数、总行数、总代码行数、总注释行数、总空行数,以及按文件类型的分组统计

数据持久化

工具会自动将统计结果保存到 `data/code_line_data.json` 文件中,确保重启后数据不会丢失。

支持的文件类型

目前支持以下文件类型的注释识别:

  • JavaScript
  • Python
  • Java
  • C++
  • C
  • Go
  • Rust
  • Swift
  • Kotlin
  • TypeScript

对于不支持的文件类型,仍将统计总行数、空行数,但注释行数将为0。

示例

调用 `count_code_lines` 工具:

json
{
  "fileType": "javascript",
  "code": "function hello() {\n  // 这是一个注释\n  console.log('Hello World');\n\n  return true;\n}"
}

调用 `get_statistics` 工具:

json
{
  "startTime": "2023-01-01T00:00:00Z",
  "endTime": "2023-12-31T23:59:59Z"
}

Frequently asked questions

What is code-line-counter-mcp?

code-line-counter-mcp is 这是一个MCP(Model Context Protocol)工具,用于统计AI生成的代码行数。该工具可以帮助您跟踪和分析每次AI生成的代码的规模。

How do I install code-line-counter-mcp?

Open the GitHub repository and follow its README. Most MCP servers are added to your client's MCP config, then called by your agent.

Is code-line-counter-mcp open source?

Yes — it is hosted on GitHub at https://github.com/fashionzzz/code-line-counter-mcp and has 1 stars.

Related MCP tools

Run your own MCP server? See who uses it and what to fix.

Measure it with TrackMCP