comment-stripper-mcp

A flexible MCP server that batch processes code files to remove comments across multiple programming languages.

Visit Server
Added on 3/28/2025

comment-stripper-mcp

A flexible MCP server that batch processes code files to remove comments across multiple programming languages. Currently supports JavaScript, TypeScript, Vue, CSS/SCSS/LESS, HTML, Python, Java, C#, C++, Ruby, and PHP files with regex-based pattern matching.

Overview

This server implements the Model Context Protocol (MCP) to provide a service that removes comments from code files. It accepts individual files, directories (including subdirectories), or direct text input, and returns the cleaned code with comments stripped out.

This project is developed using Test-Driven Development (TDD) methodology, ensuring high code quality, better design, and comprehensive test coverage from the start. Each feature is first defined by tests before implementation, following the red-green-refactor cycle.

Features

  • ๐Ÿ”„ Process files, directories, or raw text input
  • ๐ŸŒ Cross-language support (JS, TS, Vue, CSS/SCSS/LESS, HTML, Python, Java, C#, C++, Ruby, and PHP)
  • ๐Ÿ“‚ Recursively handle nested directories
  • โšก Regex-based pattern matching for efficient comment removal
  • ๐Ÿ”Œ MCP-compliant API for easy integration
  • ๐Ÿ› ๏ธ Built with Node.js and TypeScript
  • ๐Ÿ“Š Comprehensive logging system with multiple log levels
  • โš ๏ธ Robust error handling with standardized error responses
  • โš™๏ธ Flexible configuration through environment variables
  • ๐Ÿš€ Performance optimization for processing large files
  • ๐Ÿ” API authentication for secure access
  • ๐Ÿ“ˆ Progress tracking for large directory processing

Getting Started

Prerequisites

  • Node.js 18+
  • npm or yarn

Installation

# Clone this repository
git clone https://github.com/yhzion/comment-stripper-mcp.git
cd comment-stripper-mcp

# Install dependencies
npm install
# or
yarn install

Running the Server

# Development mode
npm run dev
# or
yarn dev

# Production mode
npm run build
npm start
# or
yarn build
yarn start

By default, the server runs on port 3000. You can configure this through environment variables.

MCP ์„œ๋ฒ„ ์—ฐ๊ฒฐ ๋ฌธ์ œ ํ•ด๊ฒฐ ๊ฐ€์ด๋“œ

MCP ์„œ๋ฒ„๊ฐ€ Claude Desktop๊ณผ ์—ฐ๊ฒฐ ์‹œ ์˜ˆ๊ธฐ์น˜ ์•Š๊ฒŒ ์ข…๋ฃŒ๋˜๋Š” ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•œ ๊ฐ€์ด๋“œ์ž…๋‹ˆ๋‹ค.

๋ฌธ์ œ ์ฆ์ƒ

  • ์„œ๋ฒ„๊ฐ€ ์ดˆ๊ธฐํ™”๋œ ํ›„ ๊ณง๋ฐ”๋กœ ์ข…๋ฃŒ๋จ
  • ๋กœ๊ทธ์— "Server transport closed unexpectedly" ๋ฉ”์‹œ์ง€๊ฐ€ ํ‘œ์‹œ๋จ
  • Claude Desktop์—์„œ MCP ์„œ๋ฒ„์— ์—ฐ๊ฒฐํ•  ์ˆ˜ ์—†๋‹ค๋Š” ์˜ค๋ฅ˜ ๋ฉ”์‹œ์ง€๊ฐ€ ํ‘œ์‹œ๋จ

ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•

1. NVM์„ ์‚ฌ์šฉํ•œ ๊นจ๋—ํ•œ Node.js ํ™˜๊ฒฝ ์„ค์ •

# NVM ์„ค์น˜ (์ด๋ฏธ ์„ค์น˜๋˜์–ด ์žˆ๋‹ค๋ฉด ์ƒ๋žต)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

# ์ตœ์‹  Node.js ์„ค์น˜
nvm install node

# ์„ค์น˜ํ•œ ๋ฒ„์ „ ํ™œ์„ฑํ™”
nvm use node

2. Claude Desktop ์„ค์ • ํŒŒ์ผ์— ์ ˆ๋Œ€ ๊ฒฝ๋กœ ์‚ฌ์šฉ

Claude Desktop ์„ค์ • ํŒŒ์ผ(claude_desktop_config.json)์—์„œ ์ƒ๋Œ€ ๊ฒฝ๋กœ ๋Œ€์‹  ์ ˆ๋Œ€ ๊ฒฝ๋กœ๋ฅผ ์‚ฌ์šฉํ•˜์„ธ์š”:

{
  "mcpServers": {
    "comment-stripper": {
      "command": "/์ ˆ๋Œ€/๊ฒฝ๋กœ/node",
      "args": [
        "/์ ˆ๋Œ€/๊ฒฝ๋กœ/comment-stripper-mcp/build/index.js"
      ]
    }
  }
}

which node ๋ช…๋ น์–ด๋กœ Node.js ๊ฒฝ๋กœ๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

3. ์„œ๋ฒ„ ์•ˆ์ •์„ฑ ๊ฐœ์„ 

์„œ๋ฒ„ ์ฝ”๋“œ์— ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์•ˆ์ •์„ฑ ๊ฐœ์„  ์‚ฌํ•ญ์ด ์ ์šฉ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค:

  • ํ”„๋กœ์„ธ์Šค๊ฐ€ ์˜ˆ๊ธฐ์น˜ ์•Š๊ฒŒ ์ข…๋ฃŒ๋˜์ง€ ์•Š๋„๋ก process.stdin.resume() ์‚ฌ์šฉ
  • ๋‹ค์ค‘ keep-alive ๋ฉ”์ปค๋‹ˆ์ฆ˜ ๊ตฌํ˜„
  • ์˜ค๋ฅ˜ ์ฒ˜๋ฆฌ ๊ฐœ์„ 
  • ์ƒ์„ธํ•œ ๋กœ๊น… ์ถ”๊ฐ€

์ถ”๊ฐ€ ๋ฌธ์ œ ํ•ด๊ฒฐ ํŒ

  • Claude Desktop์˜ ๊ฐœ๋ฐœ์ž ๋ชจ๋“œ๋ฅผ ํ™œ์„ฑํ™”ํ•˜์—ฌ MCP ๋กœ๊ทธ ํŒŒ์ผ์— ์ ‘๊ทผํ•˜์„ธ์š”.
  • ์„œ๋ฒ„ ์‹คํ–‰ ์‹œ ๋ฐœ์ƒํ•˜๋Š” ์˜ค๋ฅ˜ ๋ฉ”์‹œ์ง€๋ฅผ ํ™•์ธํ•˜์„ธ์š”.
  • ํ™˜๊ฒฝ ๋ณ€์ˆ˜๊ฐ€ ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ์„ค์ •๋˜์–ด ์žˆ๋Š”์ง€ ํ™•์ธํ•˜์„ธ์š”.
  • ๋ฐฉํ™”๋ฒฝ์ด๋‚˜ ๋ณด์•ˆ ์†Œํ”„ํŠธ์›จ์–ด๊ฐ€ ์—ฐ๊ฒฐ์„ ์ฐจ๋‹จํ•˜๊ณ  ์žˆ์ง€ ์•Š์€์ง€ ํ™•์ธํ•˜์„ธ์š”.

Configuration

The server can be configured using environment variables. You can create a .env file in the root directory based on the provided .env.example file:

# Server configuration
PORT=3000                # Port for the server to listen on
HOST=127.0.0.1           # Host for the server to bind to
NODE_ENV=development     # Environment (development, production, test)

# Logging configuration
LOG_LEVEL=2              # 0=ERROR, 1=WARN, 2=INFO, 3=DEBUG, 4=TRACE
LOG_TO_FILE=false        # Whether to log to a file
LOG_DIR=logs             # Directory for log files

# Performance configuration
CHUNK_SIZE=1048576       # 1MB chunk size for processing large files
MAX_WORKERS=4            # Number of concurrent workers for batch processing
MEMORY_LIMIT=536870912   # 512MB memory limit before using streaming

# Authentication
API_KEY=your-secret-key  # API key for authentication

Testing

This project strictly follows Test-Driven Development (TDD) principles:

  1. Write a failing test first (Red phase)
  2. Implement the minimum code to pass the test (Green phase)
  3. Refactor the code while keeping tests passing

The project uses Jest as the testing framework with TypeScript support via ts-jest. Tests are organized into:

  • Unit tests: Testing individual functions and components
  • Integration tests: Testing API endpoints and interactions between components
# Run all tests
npm test
# or
yarn test

# Run tests in watch mode
npm run test:watch
# or
yarn test:watch

# Run tests with coverage
npm run test:coverage
# or
yarn test:coverage

API Documentation

Strip Comments Endpoint

Endpoint: /api/strip-comments

Method: POST

Description: Strips comments from code files or text.

Request Parameters:

  • text (optional): The text to strip comments from.
  • filePath (optional): The path to a file to strip comments from.
  • directoryPath (optional): The path to a directory to process.
  • recursive (optional, default: true): Whether to recursively process subdirectories.
  • fileTypes (optional, default: all supported): Array of file extensions to process.
  • trackProgress (optional, default: false): Whether to track progress for directory processing.

Response:

{
  "success": true,
  "data": {
    "original": "// Original code with comments",
    "stripped": "// Code with comments removed"
  }
}

Get Progress Endpoint

Endpoint: /api/get-progress

Method: POST

Description: Gets the progress of a directory processing operation.

Request Parameters:

  • trackerId: The ID of the progress tracker.

Response:

{
  "success": true,
  "data": {
    "processed": 10,
    "total": 20,
    "percentage": 50,
    "completed": false
  }
}

Authentication Status Endpoint

Endpoint: /api/auth-status

Method: POST

Description: Gets the current authentication status and configuration.

Response:

{
  "success": true,
  "data": {
    "authEnabled": true,
    "authenticated": true,
    "message": "Authenticated successfully"
  }
}

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the ISC License - see the LICENSE file for details.