# 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)](https://modelcontextprotocol.io/) 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 ```bash # 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 ```bash # 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 ν™˜κ²½ μ„€μ • ```bash # 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`)μ—μ„œ μƒλŒ€ 경둜 λŒ€μ‹  μ ˆλŒ€ 경둜λ₯Ό μ‚¬μš©ν•˜μ„Έμš”: ```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: ```bash # 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 ```bash # 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**: ```json { "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**: ```json { "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**: ```json { "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.