comment-stripper-mcp
by yhzion
A flexible MCP server that batch processes code files to remove comments across multiple programming languages. It supports various file types and offers efficient comment removal using regex-based pattern matching.
Last updated: N/A
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:
- Write a failing test first (Red phase)
- Implement the minimum code to pass the test (Green phase)
- 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.