UNPKG

codesort-server

Version:

šŸš€ CodeSort Server v2.0.0 - Simplified, robust MCP server for code analysis. Works with Claude Desktop, Claude CLI, and other AI tools. Zero configuration required.

355 lines (289 loc) • 11.1 kB
# CodeSort Server v2.5.0 - Production Ready šŸš€ **Simplified, robust MCP server for code analysis** - Works with Claude Desktop, Claude CLI, and other AI tools. ## ⚔ Quick Start (30 seconds) ### 1. Install ```bash npm install -g codesort-server ``` āš ļø **Performance Note**: Direct command (`codesort`) is **5x faster** than npx. Always use direct command when possible. ### 2. Add to Claude CLI **Method A: Direct command (Recommended - Fastest)** Edit `C:\Users\Martin\.claude.json` (Windows) or `~/.claude.json` (macOS/Linux) and add: ```json { "mcpServers": { "codesort": { "type": "stdio", "command": "codesort", "args": ["start", "--transport", "stdio"], "env": {} } } } ``` **Method B: One-command setup** ```bash claude mcp add --transport stdio codesort codesort start --transport stdio ``` **Method C: npx fallback (if direct command doesn't work)** ```json { "mcpServers": { "codesort": { "type": "stdio", "command": "npx", "args": ["-y", "codesort-server", "start", "--transport", "stdio"], "env": {} } } } ``` ### 3. Verify installation ```bash claude mcp list ``` You should see: `codesort: codesort start --transport stdio - āœ“ Connected` ### 4. Use immediately ```bash claude --print "What functions exist in this project?" ``` ## āœ… That's it! Minimal configuration required. CodeSort automatically: - āœ… Analyzes your entire codebase with intelligent issue detection - āœ… Detects existing functions before creating duplicates - āœ… Flags potential code quality issues and duplications: - šŸ”“ **HIGH**: Duplicate function names across files - 🟔 **MEDIUM**: Files with excessive functions (>20) - 🟢 **LOW**: Naming convention inconsistencies - āœ… Provides context-aware suggestions - āœ… Works with any MCP-compatible AI tool ## šŸ› ļø Supported AI Tools ### Claude CLI (Recommended) ```bash # Add to Claude CLI (direct command - fastest) claude mcp add --transport stdio codesort codesort start --transport stdio # Use immediately claude --print "Create a user authentication function" ``` ### Claude Desktop ```json { "mcpServers": { "codesort": { "command": "codesort", "args": ["start", "--transport", "stdio"] } } } ``` ### Other MCP Tools Use universal configuration: ```json { "mcpServers": { "codesort": { "command": "codesort", "args": ["start", "--transport", "stdio"] } } } ``` ## šŸ”§ Troubleshooting ### "codesort command not found" or MCP server not connecting: **Option 1: Use npx fallback (Slower but works)** āš ļø **Note**: npx is 5x slower than direct command but works regardless of PATH configuration: ```json { "mcpServers": { "codesort": { "command": "npx", "args": ["-y", "codesort-server", "start", "--transport", "stdio"] } } } ``` **Option 2: Use full path (Windows)** ```json { "mcpServers": { "codesort": { "command": "C:\\Users\\YOUR_USERNAME\\AppData\\Roaming\\npm\\codesort.cmd", "args": ["start", "--transport", "stdio"] } } } ``` **Option 3: Use full path (macOS/Linux)** ```json { "mcpServers": { "codesort": { "command": "/usr/local/bin/codesort", "args": ["start", "--transport", "stdio"] } } } ``` **Option 4: Add to PATH (Recommended fix)** 1. Find your npm global bin directory: `npm config get prefix` 2. Add it to your system PATH environment variable 3. Restart your terminal/AI tool ## šŸš€ What CodeSort Does When you ask an AI to create code, CodeSort automatically: 1. **šŸ” Scans your codebase** for existing functions 2. **āš ļø Prevents duplicates** by suggesting existing code 3. **šŸ“‹ Follows your patterns** and coding conventions 4. **šŸŽÆ Provides context** based on your actual codebase ### Example ``` You: "Create a user authentication function" AI: "I found existing authentication in `src/auth/login.ts:15`. Would you like me to extend the existing functionality or create something different?" ``` ## šŸ“‹ Available Commands ```bash # Direct CLI usage codesort analyze # Analyze current project codesort search "user auth" # Search functions codesort docs all # Generate docs codesort info # Show server info # Start MCP server (for AI tools) codesort start --transport stdio ``` ## šŸ”§ MCP Tools Available - **`analyze_codebase`** - Complete project analysis with flexible output formats and token management - **NEW:** `output_format` - Choose between `minimal`, `summary`, or `comprehensive` - **NEW:** `max_files` - Limit number of files analyzed (1-200) - **NEW:** `max_issues` - Limit issues reported (1-100) - **NEW:** `severity_filter` - Filter issues by severity (`high`, `medium`, `low`) - **NEW:** `max_tokens` - Set token limit with automatic truncation (1000-25000) - **`search_functions`** - Find existing functions and patterns - **`find_dependencies`** - šŸ”— Analyze import/require dependencies and detect circular dependencies - **`security_scan`** - šŸ›”ļø Scan code for common security vulnerabilities and anti-patterns - **`documentation_sitemap`** - Generate comprehensive documentation with AI guidance - **`validate_structure`** - Validate TypeScript type consistency - **`ripple_effects`** - Analyze impact of changes before implementing - **`full_audit`** - Run comprehensive audit of all tools ## šŸ“Š MCP Resources Available - **`project://overview`** - Project summary and info ## šŸŽÆ Production Features - āœ… **Simplified Architecture** - Removed complex dependencies - āœ… **Robust Error Handling** - Graceful failure handling - āœ… **Performance Optimized** - Smart caching and limits - āœ… **Type Safe** - Full TypeScript strict mode - āœ… **Zero Configuration** - Works out of the box - āœ… **Multi-language Support** - TypeScript, JavaScript, Python ## šŸ—ļø Development ### Prerequisites - Node.js 18+ - TypeScript 5.0+ ### Setup ```bash git clone https://github.com/codesort/codesort-server.git cd codesort-server npm install npm run build ``` ### Scripts ```bash npm run dev # Development mode npm run build # Build for production npm run test # Run tests npm run lint # Lint code ``` ## šŸ“ˆ What's New in v2.5.0 ### šŸŽ‰ Major Token Management Improvements - **šŸ“Š Flexible Output Formats** - `analyze_codebase` now supports `minimal`, `summary`, and `comprehensive` formats - **šŸ”§ Advanced Filtering** - Filter issues by severity (`high`, `medium`, `low`) and limit issue count - **⚔ Performance Controls** - Limit files analyzed (1-200) and manage response size - **šŸ›”ļø Token Limits** - Built-in token management with automatic truncation (1000-25000 tokens) - **šŸŽÆ Smart Caching** - Parameter-aware caching for consistent and fast responses ### šŸš€ Enhanced MCP Tool Suite - **šŸ“‹ Documentation Sitemap** - Generate AI-aware documentation with cross-references - **āœ… Structure Validation** - Validate TypeScript type consistency and prevent drift - **🌊 Ripple Effects Analysis** - Analyze impact of changes before implementing - **šŸ” Full Audit Mode** - Comprehensive audit of all tools for complete health assessment ### šŸ”§ Usage Examples for Large Codebases ```typescript // For large codebases - use minimal format analyze_codebase({ output_format: "minimal", max_files: 20, max_issues: 5, severity_filter: "high", max_tokens: 5000 }) // For medium codebases - use summary format analyze_codebase({ output_format: "summary", max_files: 50, max_issues: 15, severity_filter: "medium" }) ``` ### Previous v2.1.1 Features - **šŸ”— Dependency Analysis Tool** - `find_dependencies` tool for comprehensive dependency analysis - **šŸ›”ļø Security Scanning** - `security_scan` tool for detecting common security vulnerabilities - **⚔ Performance Enhancements** - Parallel processing and improved caching ### šŸ”— Dependency Analysis Features (`find_dependencies`) - **Import/Require Detection** - Analyzes ES6 imports, CommonJS requires, and Python imports - **Circular Dependency Detection** - Identifies circular dependencies in your codebase - **Dependency Classification** - Categorizes dependencies as internal, external, or built-in - **Most Connected Files** - Identifies files with the highest number of dependencies - **External Dependencies Report** - Shows most frequently used external packages ### šŸ›”ļø Security Analysis Features (`security_scan`) - **Hardcoded Secrets Detection** - Scans for passwords, API keys, tokens in code - **Insecure Pattern Detection** - Identifies eval(), innerHTML, document.write() usage - **Input Validation Issues** - Detects unsanitized user input handling - **Severity Classification** - Issues classified as High, Medium, or Low severity - **Actionable Recommendations** - Provides specific remediation advice ### ⚔ Performance Enhancements - **Parallel Processing** - Multiple files analyzed simultaneously for faster results - **Enhanced Caching** - Improved cache strategies with longer TTL for different analysis types - **Memory Optimization** - Better memory management for large codebases - **Incremental Analysis** - Foundation for future incremental analysis features ### Previous v2.0.2-beta Features - **šŸ› Fixed Duplicate Detection Bug** - Resolved critical function parsing issues - **šŸ”“ Intelligent Issue Detection** - Added comprehensive code analysis issue detection - **⚔ Enhanced Search Accuracy** - Improved function detection and reduced false positives - **šŸ“Š Rich Analysis Reports** - Detailed codebase analysis with actionable insights ### Previous v2.0.0 Features - **Simplified Codebase** - Removed complex AST parsing and embeddings - **Better Performance** - Faster parsing with regex-based approach - **Robust Error Handling** - Graceful degradation on errors - **Production Ready** - Extensive testing and validation - **Zero Dependencies** - Minimal external dependencies - **Type Safe** - Full TypeScript strict mode compliance ## šŸ” Technical Details ### Supported Languages - **TypeScript** (.ts, .tsx) - **JavaScript** (.js, .jsx) - **Python** (.py) - **Java** (.java) - **C/C++** (.c, .cpp, .cc, .cxx) - **Go** (.go) - **Rust** (.rs) - **PHP** (.php) - **Ruby** (.rb) ### Function Detection Uses optimized regex patterns for reliable function detection: - Function declarations - Arrow functions - Class definitions - Interface declarations - Method definitions - Import/Export statements ## šŸ›”ļø Error Handling - Graceful file reading errors - Invalid syntax handling - Network timeout protection - Memory usage limits - Comprehensive logging ## šŸ“ License MIT License - see the [LICENSE](LICENSE) file for details. ## šŸ†˜ Support - **Issues**: [GitHub Issues](https://github.com/codesort/codesort-server/issues) - **Documentation**: [Full Documentation](https://github.com/codesort/codesort-server#readme) --- **CodeSort Server v2.5.0** - *Simplified, Robust, Production-Ready* *Install once, use everywhere. Simple. Powerful. Ready to go.* šŸš€