Development · MODEL CONTEXT PROTOCOL
nicobailon code summarizer
A command-line tool and MCP server that summarizes code files using Gemini Flash 2.0
WHAT IT CONNECTS
nicobailon code summarizer 为 AI Agent 提供什么
- Recursively processes code files in a directory
- Respects `.gitignore` rules
- Skips irrelevant directories like `node_modules`, `dist`, etc.
- Summarizes code files using Gemini Flash 2.0
- Outputs summaries to a text file
- Configurable detail level and summary length
- MCP server for integration with Claude Desktop and other LLM tools
- Modular design for easy integration into other applications
- Secure API key management
- Authentication for MCP server endpoints
- Retry mechanism with exponential backoff for LLM calls
- Rate limiting to prevent abuse
- Node.js 18+
- Clone the repository
- Install dependencies:
- Create a `.env` file with your Google API key:
- Build the project:
- Start the code-summarizer MCP server
- Open Claude Desktop and click on the Claude menu, then "Settings..."
- Navigate to the "Developer" section
- Create a file at `~/.claude/claude_desktop_config.json` (macOS/Linux) or `%USERPROFILE%\.claude\claude_desktop_config.json` (Windows) with this content:
- Restart Claude Desktop
- After restarting, you can ask Claude to access your codebase, e.g., "Summarize the files in my project"
- "Can you summarize all the JavaScript files in my project?"
- "Please give me a high-level overview of my codebase."
- "Explain what the file 'src/config/config.ts' does."
- "Find all functions related to authentication in my code."
- Start the code-summarizer MCP server
- Create a `.cursor/mcp.json` file in your project directory:
- Restart Cursor or reload your project
- Ask Cursor about your code, e.g., "Can you summarize my codebase?"
- "Summarize the structure of this codebase for me."
- "What are the key components in this project?"
- "Give me a detailed explanation of the MCP server implementation."
- "Help me understand how the retry mechanism works."
- Start the code-summarizer MCP server
- In Cline, you can add the MCP server with a command:
- Then authenticate with your API key:
- You can then ask Cline to use the code-summarizer, e.g., "Please summarize my code files"
- "What does each file in my project do?"
- "Create a summary of all TypeScript files."
- "Explain the authentication flow in this codebase."
- "What are the main functions in the 'summarizer' directory?"
- **Get file summaries**: Request concise explanations of what specific files do
- **Explore directories**: Browse through your codebase structure
- **Batch processing**: Summarize multiple files at once
- **Targeted queries**: Find specific patterns or functionality in your code
- **Customize summaries**: Control detail level and summary length
- **Update settings**: Change configuration options through the MCP interface
- `code://file/*` - Access individual code files
- `code://directory/*` - List code files in a directory
- `summary://file/*` - Get summary for a specific file
- `summary://batch/*` - Get summaries for multiple files
- `summarize_file` - Summarize a single file with options
- `summarize_directory` - Summarize a directory with options
- `set_config` - Update configuration options
- `code_summary` - Prompt template for summarizing code
- `directory_summary` - Prompt template for summarizing entire directories
- **Connection Refused**
- Make sure the MCP server is running (`npm start -- server`)
- Verify the port is correct in your configuration
- Check for firewall issues blocking the connection
- **Authentication Errors**
- Verify you've added the correct API key in the headers (`x-api-key`)
- Check that your API key is valid and properly formatted
- Make sure environment variables are set correctly
- **Transport Errors**
- Ensure the correct transport type is specified (SSE)
- Check that the URL includes the correct endpoint (`/sse`)
- Verify network connectivity between the client and server
- **Permission Issues**
- Ensure the MCP server has read access to your codebase
- Check file permissions if summarizing fails for specific files
- **Claude Desktop Not Finding the MCP Server**
- Verify the path in `claude_desktop_config.json` is correct
- Make sure the command and args point to the right location
- Check Claude Desktop logs for any configuration errors
- **Rate Limiting**
- If you see "Too many requests" errors, wait and try again later
- Consider adjusting the rate limiting settings in the server code
- `--detail`, `-d`: Set the level of detail for summaries. Options are 'low', 'medium', or 'high'. Default is 'medium'.
- `--max-length`, `-l`: Maximum length of each summary in characters. Default is 500.
- API keys are stored securely and prioritize environment variables over configuration files
- Keys are validated for proper format before use
- API keys are never exposed in logs or error messages
- Configuration file doesn't store API keys when they're provided via environment variables
- All MCP server endpoints (except health check) require authentication via API key
- Authentication uses the `x-api-key` header for secure transmission
- Failed authentication attempts are logged for security monitoring
- Built-in rate limiting prevents abuse of the service
- Default: 60 requests per minute per IP address
- Configurable through server settings
- Structured error system with categorization
- Sensitive information is never exposed in error messages
- Proper error codes are returned for different failure scenarios
- Automatic retry with exponential backoff for transient failures
- Configurable retry settings including max retries, delays, and backoff factor
- Jitter added to retry timing to prevent thundering herd problems
- Request ID tracking for tracing issues across the system
- TypeScript (.ts, .tsx)
- JavaScript (.js, .jsx)
- Python (.py)
- Java (.java)
- C++ (.cpp)
- C (.c)
- Go (.go)
- Ruby (.rb)
- PHP (.php)
- C# (.cs)
- Swift (.swift)
- Rust (.rs)
- Kotlin (.kt)
- Scala (.scala)
- Vue (.vue)
- HTML (.html)
- CSS (.css, .scss, .less)
- The tool scans the specified directory recursively, respecting `.gitignore` rules.
- It filters files based on supported extensions.
- For each supported file, it reads the content and determines the programming language.
- It sends the code to Gemini Flash 2.0 with a prompt to summarize, including detail level and length constraints.
- The summaries are collected and written to the specified output file.
- `index.ts`: Main CLI implementation
- `src/`: Source code directory
- `summarizer/`: Core summarization functionality
- `mcp/`: MCP server implementation
- `config/`: Configuration management
- `bin/`: CLI entrypoint
- `config.json`: Default configuration file
- `tsconfig.json`: TypeScript configuration
- `package.json`: Project dependencies and scripts
- `.env.example`: Template for setting up environment variables
- `.gitignore`: Files and directories to ignore in Git
- `__tests__`: Unit and integration tests
- `__mocks__/mock-codebase`: Mock codebase for testing
- Support for more file types
- Support for alternative LLM providers
- Integration with an Electron app for a GUI interface
- Enhanced MCP server capabilities
- Advanced token usage tracking
- OpenTelemetry-based observability
- Enhanced audit logging capabilities
- Secret scanning integration
SECURITY
MCP 收录不等于安全审核
MCP 服务器可能获得模型上下文、凭据、本地文件或调用外部系统的权限。连接 Agent 前,请检查代码、环境变量、网络行为、软件包来源与维护状态。