|
| 1 | +# Code Index MCP |
| 2 | + |
| 3 | +Code Index MCP is a Model Context Protocol server that enables large language models (LLMs) to index, search, and analyze code in project directories. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- Index and navigate project file structures |
| 8 | +- Search for specific patterns in code |
| 9 | +- Get detailed file summaries |
| 10 | +- Analyze code structure and complexity |
| 11 | +- Support for multiple programming languages |
| 12 | +- Persistent storage of project settings |
| 13 | + |
| 14 | +## Installation |
| 15 | + |
| 16 | +This project uses uv for environment management and dependency installation. |
| 17 | + |
| 18 | +1. Ensure you have Python 3.10 or later installed |
| 19 | +2. Install uv (recommended): |
| 20 | + ```bash |
| 21 | + # Windows |
| 22 | + powershell -c "irm https://astral.sh/uv/install.ps1 | iex" |
| 23 | + # macOS/Linux |
| 24 | + curl -LsSf https://astral.sh/uv/install.sh | sh |
| 25 | + ``` |
| 26 | + |
| 27 | +3. Set up the environment and install dependencies: |
| 28 | + ```bash |
| 29 | + # Create virtual environment and install dependencies |
| 30 | + uv venv |
| 31 | + uv pip install -r requirements.txt |
| 32 | + ``` |
| 33 | + |
| 34 | +## Usage |
| 35 | + |
| 36 | +### Running the Server |
| 37 | + |
| 38 | +```bash |
| 39 | +# Using Python from the virtual environment |
| 40 | +.venv/Scripts/python server.py # Windows |
| 41 | +.venv/bin/python server.py # macOS/Linux |
| 42 | + |
| 43 | +# Or more conveniently with uv |
| 44 | +uv run server.py |
| 45 | +``` |
| 46 | + |
| 47 | +### Integrating with Claude Desktop |
| 48 | + |
| 49 | +You can manually configure Claude Desktop to integrate with Code Index MCP: |
| 50 | + |
| 51 | +1. Ensure you have completed the environment setup as described above |
| 52 | + |
| 53 | +2. Find or create the Claude Desktop configuration file: |
| 54 | + - Windows: `%APPDATA%\Claude\claude_desktop_config.json` |
| 55 | + - macOS: `~/Library/Application Support/Claude/claude_desktop_config.json` |
| 56 | + |
| 57 | +3. Add the following configuration (replace with your actual path): |
| 58 | + ```json |
| 59 | + { |
| 60 | + "mcpServers": { |
| 61 | + "code-indexer": { |
| 62 | + "command": "uv", |
| 63 | + "args": ["run", "C:/path/to/your/code-index-mcp/server.py"] |
| 64 | + } |
| 65 | + } |
| 66 | + } |
| 67 | + ``` |
| 68 | + |
| 69 | +4. Restart Claude Desktop to use Code Indexer for analyzing code projects |
| 70 | + |
| 71 | +### Basic Workflow |
| 72 | + |
| 73 | +1. **Set Project Path** (required first step): |
| 74 | + - When using for the first time, you must set the project path to analyze |
| 75 | + - Through Claude command: "I need to analyze a project, help me set up the project path" |
| 76 | + - Provide the complete project directory path |
| 77 | + |
| 78 | +2. **Code Search**: |
| 79 | + - Search for specific keywords or patterns: "Search for 'function name' in the project" |
| 80 | + - Filter by file type: "Search for 'import' in all .py files" |
| 81 | + |
| 82 | +3. **File Analysis**: |
| 83 | + - Analyze specific files: "Analyze the file src/main.py" |
| 84 | + - Get file summaries: "Give me a list of functions in utils/helpers.js" |
| 85 | + |
| 86 | +4. **Project Navigation**: |
| 87 | + - View project structure: "Show me the structure of this project" |
| 88 | + - Find files matching specific patterns: "Find all test_*.py files" |
| 89 | + |
| 90 | +## Technical Details |
| 91 | + |
| 92 | +### Persistent Storage |
| 93 | + |
| 94 | +All index and settings data are stored in the `.code_indexer` folder within the project directory: |
| 95 | +- `config.json`: Project configuration information |
| 96 | +- `file_index.pickle`: File index data |
| 97 | +- `content_cache.pickle`: File content cache |
| 98 | + |
| 99 | +This ensures that the entire project doesn't need to be re-indexed each time it's used. |
| 100 | + |
| 101 | +### Supported File Types |
| 102 | + |
| 103 | +The following file types are currently supported for indexing and analysis: |
| 104 | +- Python (.py) |
| 105 | +- JavaScript/TypeScript (.js, .ts, .jsx, .tsx) |
| 106 | +- Java (.java) |
| 107 | +- C/C++ (.c, .cpp, .h, .hpp) |
| 108 | +- C# (.cs) |
| 109 | +- Go (.go) |
| 110 | +- Ruby (.rb) |
| 111 | +- PHP (.php) |
| 112 | +- Swift (.swift) |
| 113 | +- Kotlin (.kt) |
| 114 | +- Rust (.rs) |
| 115 | +- Scala (.scala) |
| 116 | +- Shell (.sh, .bash) |
| 117 | +- HTML/CSS (.html, .css, .scss) |
| 118 | +- Markdown (.md) |
| 119 | +- JSON (.json) |
| 120 | +- XML (.xml) |
| 121 | +- YAML (.yml, .yaml) |
| 122 | + |
| 123 | +## Security Considerations |
| 124 | + |
| 125 | +- File path validation prevents directory traversal attacks |
| 126 | +- Absolute path access is not allowed |
| 127 | +- Project path must be explicitly set, with no default value |
| 128 | + |
| 129 | +## Contributing |
| 130 | + |
| 131 | +Contributions via issues or pull requests to add new features or fix bugs are welcome. |
| 132 | + |
| 133 | +--- |
| 134 | + |
| 135 | +*For documentation in Chinese, please see [README_zh.md](README_zh.md).* |
0 commit comments