Metadata-Version: 2.4
Name: code-graph-mcp
Version: 1.1.1
Summary: MCP server for multi-language code graph intelligence and analysis across 25+ programming languages
Project-URL: Homepage, https://github.com/entrepeneur4lyf/code-graph-mcp
Project-URL: Repository, https://github.com/entrepeneur4lyf/code-graph-mcp
Project-URL: Documentation, https://github.com/entrepeneur4lyf/code-graph-mcp#readme
Project-URL: Changelog, https://github.com/entrepeneur4lyf/code-graph-mcp/releases
Project-URL: Issues, https://github.com/entrepeneur4lyf/code-graph-mcp/issues
Author-email: entrepeneur4lyf <shawn.payments@gmail.com>
License: MIT License
        
        Copyright (c) 2025 Shawn McAllister @entrepeneur4lyf
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: ast,claude-code,code-analysis,code-quality,complexity-analysis,graph,intelligence,mcp,python,static-analysis
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Code Generators
Classifier: Topic :: Software Development :: Compilers
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Software Development :: Quality Assurance
Classifier: Topic :: Text Processing :: Linguistic
Requires-Python: >=3.12
Requires-Dist: anyio>=4.0.0
Requires-Dist: ast-grep-py>=0.39.0
Requires-Dist: click>=8.0.0
Requires-Dist: mcp>=1.12.2
Requires-Dist: rustworkx>=0.15.0
Requires-Dist: watchdog>=6.0.0
Provides-Extra: dev
Requires-Dist: black>=23.0.0; extra == 'dev'
Requires-Dist: pytest-asyncio>=0.23.0; extra == 'dev'
Requires-Dist: pytest>=7.0.0; extra == 'dev'
Requires-Dist: ruff>=0.1.0; extra == 'dev'
Provides-Extra: test
Requires-Dist: pytest-asyncio>=0.23.0; extra == 'test'
Requires-Dist: pytest>=7.0.0; extra == 'test'
Description-Content-Type: text/markdown

# Code Graph MCP Server

Model Context Protocol server providing comprehensive code analysis, navigation, and quality assessment capabilities **across 25+ programming languages**.

## Features

🌍 **Multi-Language Support**
- **25+ Programming Languages**: JavaScript, TypeScript, Python, Java, C#, C++, C, Rust, Go, Kotlin, Scala, Swift, Dart, Ruby, PHP, Elixir, Elm, Lua, HTML, CSS, SQL, YAML, JSON, XML, Markdown, Haskell, OCaml, F#
- **Intelligent Language Detection**: Extension-based, MIME type, shebang, and content signature analysis
- **Framework Recognition**: React, Angular, Vue, Django, Flask, Spring, and 15+ more
- **Universal AST Abstraction**: Language-agnostic code analysis and graph structures

🔍 **Advanced Code Analysis**
- Complete codebase structure analysis with metrics across all languages
- Universal AST parsing with ast-grep backend and intelligent caching
- Cyclomatic complexity calculation with language-specific patterns
- Project health scoring and maintainability indexing
- Code smell detection: long functions, complex logic, duplicate patterns
- Cross-language similarity analysis and pattern matching

🧭 **Navigation & Search**
- Symbol definition lookup across mixed-language codebases
- Reference tracking across files and languages
- Function caller/callee analysis with cross-language calls
- Dependency mapping and circular dependency detection
- Call graph generation across entire project

⚡ **Performance Optimized**
- **Debounced File Watcher** - Automatic re-analysis when files change with 2-second intelligent debouncing
- **Real-time Updates** - Code graph automatically updates during active development
- Aggressive LRU caching with 50-90% speed improvements on repeated operations
- Cache sizes optimized for 500+ file codebases (up to 300K entries)
- Sub-microsecond response times on cache hits
- Memory-efficient universal graph building

🏢 **Enterprise Ready**
- Production-quality error handling across all languages
- Comprehensive logging and monitoring with language context
- UV package management with ast-grep integration

## Installation

### Quick Start (PyPI)

```bash
pip install code-graph-mcp ast-grep-py rustworkx
```

## MCP Host Integration

### Claude Desktop

#### Method 1: Using Claude CLI (Recommended)
```bash
# Project-specific installation
claude mcp add --scope project code-graph-mcp code-graph-mcp

# User-wide installation  
claude mcp add --scope user code-graph-mcp code-graph-mcp

# Verify installation
claude mcp list
```

#### Method 2: Manual Configuration
Add to your Claude Desktop configuration file:

**macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
**Windows**: `%APPDATA%\Claude\claude_desktop_config.json`

```json
{
  "mcpServers": {
    "code-graph-mcp": {
      "command": "code-graph-mcp",
      "args": ["--project-root", "."]
    }
  }
}
```

### Cline (VS Code Extension)

Add to your Cline MCP settings in VS Code:

1. Open VS Code Settings (Ctrl/Cmd + ,)
2. Search for "Cline MCP"
3. Add server configuration:

```json
{
  "cline.mcp.servers": {
    "code-graph-mcp": {
      "command": "code-graph-mcp",
      "args": ["--project-root", "${workspaceFolder}"]
    }
  }
}
```

### Continue (VS Code Extension)

Add to your `~/.continue/config.json`:

```json
{
  "mcpServers": [
    {
      "name": "code-graph-mcp",
      "command": "code-graph-mcp",
      "args": ["--project-root", "."],
      "env": {}
    }
  ]
}
```

### Cursor

Add to Cursor's MCP configuration:

1. Open Cursor Settings
2. Navigate to Extensions → MCP
3. Add server:

```json
{
  "name": "code-graph-mcp",
  "command": "code-graph-mcp", 
  "args": ["--project-root", "."]
}
```

### Zed Editor

Add to your Zed `settings.json`:

```json
{
  "assistant": {
    "mcp_servers": {
      "code-graph-mcp": {
        "command": "code-graph-mcp",
        "args": ["--project-root", "."]
      }
    }
  }
}
```

### Zencoder ⭐

**The best AI coding tool!** Add to your Zencoder MCP configuration:

```json
{
  "mcpServers": {
    "code-graph-mcp": {
      "command": "code-graph-mcp",
      "args": ["--project-root", "${workspaceFolder}"],
      "env": {},
      "description": "Multi-language code analysis with 25+ language support"
    }
  }
}
```

**Pro Tip**: Zencoder's advanced AI capabilities work exceptionally well with Code Graph MCP's comprehensive multi-language analysis. Perfect combination for professional development! 🚀

### Windsurf

Add to Windsurf's MCP configuration:

```json
{
  "mcpServers": {
    "code-graph-mcp": {
      "command": "code-graph-mcp",
      "args": ["--project-root", "${workspaceRoot}"]
    }
  }
}
```

### Aider

Use with Aider AI coding assistant:

```bash
aider --mcp-server code-graph-mcp --mcp-args "--project-root ."
```

### Open WebUI

For Open WebUI integration, add to your MCP configuration:

```json
{
  "mcp_servers": {
    "code-graph-mcp": {
      "command": "code-graph-mcp",
      "args": ["--project-root", "/workspace"],
      "env": {}
    }
  }
}
```

### Generic MCP Client

For any MCP-compatible client, use these connection details:

```json
{
  "name": "code-graph-mcp",
  "command": "code-graph-mcp",
  "args": ["--project-root", "/path/to/your/project"],
  "env": {
    "PYTHONPATH": "/path/to/code-graph-mcp/src"
  }
}
```

### Docker Integration

Run as a containerized MCP server:

```dockerfile
FROM python:3.12-slim
RUN pip install code-graph-mcp ast-grep-py rustworkx
EXPOSE 3000
CMD ["code-graph-mcp", "--project-root", "/workspace"]
```

```bash
docker run -v $(pwd):/workspace -p 3000:3000 code-graph-mcp
```

### Development Installation

For contributing or custom builds:

```bash
git clone <repository-url>
cd code-graph-mcp
uv sync --dev
uv build
```

Then use the development version in your MCP client:

```json
{
  "command": "uv",
  "args": ["run", "code-graph-mcp", "--project-root", "."]
}
```

## Configuration Options

### Command Line Arguments

```bash
code-graph-mcp --help
```

Available options:
- `--project-root PATH`: Root directory of your project (required)
- `--verbose`: Enable detailed logging
- `--port PORT`: Custom port for server (default: auto)
- `--no-file-watcher`: Disable automatic file change detection

### Environment Variables

```bash
export CODE_GRAPH_MCP_LOG_LEVEL=DEBUG
export CODE_GRAPH_MCP_CACHE_SIZE=500000
export CODE_GRAPH_MCP_MAX_FILES=10000
export CODE_GRAPH_MCP_FILE_WATCHER=true
export CODE_GRAPH_MCP_DEBOUNCE_DELAY=2.0
```

### File Watcher (v1.1.0+)

The server includes an intelligent file watcher that automatically updates the code graph when files change:

- **Automatic Detection**: Monitors all supported file types in your project
- **Smart Debouncing**: 2-second delay prevents excessive re-analysis during rapid changes
- **Efficient Filtering**: Respects `.gitignore` patterns and only watches relevant files
- **Thread-Safe**: Runs in background without blocking analysis operations
- **Zero Configuration**: Starts automatically after first analysis

**File Watcher Features:**
- Real-time graph updates during development
- Batch processing of multiple rapid changes
- Duplicate change prevention
- Graceful error recovery
- Resource cleanup on shutdown

### Troubleshooting

#### Common Issues

1. **"Command not found"**: Ensure `code-graph-mcp` is in your PATH
   ```bash
   pip install --upgrade code-graph-mcp
   which code-graph-mcp
   ```

2. **"ast-grep not found"**: Install the required dependency
   ```bash
   pip install ast-grep-py
   ```

3. **Permission errors**: Use virtual environment
   ```bash
   python -m venv venv
   source venv/bin/activate  # Linux/Mac
   # or
   venv\Scripts\activate     # Windows
   pip install code-graph-mcp ast-grep-py rustworkx
   ```

4. **Large project timeouts**: Increase timeout or exclude directories
   ```bash
   code-graph-mcp --project-root . --timeout 300
   ```

#### Debug Mode

Enable verbose logging for troubleshooting:

```bash
code-graph-mcp --project-root . --verbose
```

#### Supported File Types

The server automatically detects and analyzes these file extensions:
- **Web**: `.js`, `.ts`, `.jsx`, `.tsx`, `.html`, `.css`
- **Backend**: `.py`, `.java`, `.cs`, `.cpp`, `.c`, `.rs`, `.go`
- **Mobile**: `.swift`, `.dart`, `.kt`
- **Scripting**: `.rb`, `.php`, `.lua`, `.pl`
- **Config**: `.json`, `.yaml`, `.yml`, `.toml`, `.xml`
- **Docs**: `.md`, `.rst`, `.txt`

## Available Tools

The MCP server provides 8 comprehensive analysis tools that work across all 25+ supported languages:

| Tool | Description | Multi-Language Features |
|------|-------------|------------------------|
| `analyze_codebase` | Complete project analysis with structure metrics and complexity assessment | Language detection, framework identification, cross-language dependency mapping |
| `find_definition` | Locate symbol definitions with detailed metadata and documentation | Universal AST traversal, language-agnostic symbol resolution |  
| `find_references` | Find all references to symbols throughout the codebase | Cross-file and cross-language reference tracking |
| `find_callers` | Identify all functions that call a specified function | Multi-language call graph analysis |
| `find_callees` | List all functions called by a specified function | Universal function call detection across languages |
| `complexity_analysis` | Analyze code complexity with refactoring recommendations | Language-specific complexity patterns, universal metrics |
| `dependency_analysis` | Generate module dependency graphs and import relationships | Cross-language dependency detection, circular dependency analysis |
| `project_statistics` | Comprehensive project health metrics and statistics | Multi-language project profiling, maintainability indexing |

## Usage Examples

Once installed, you can use the tools directly in Claude Code for multi-language projects:

```
Analyze this React/TypeScript frontend with Python backend - show me the overall structure and complexity metrics
```

```
Find all references to the function "authenticate" across both the Java services and JavaScript frontend
```

```
Show me functions with complexity higher than 15 across all languages that need refactoring
```

```
Generate a dependency graph showing how the Python API connects to the React components
```

```
Detect code smells and duplicate patterns across the entire multi-language codebase
```

## Development

### Requirements
- Python 3.12+
- UV package manager
- MCP SDK
- ast-grep-py (for multi-language support)
- rustworkx (for high-performance graph operations)

### Running locally
```bash
# Install dependencies
uv sync

# Run the server directly
uv run code-graph-mcp --project-root /path/to/your/project --verbose

# Test with help
uv run code-graph-mcp --help
```

### Performance Features

- **LRU Caching**: 50-90% speed improvements with cache sizes up to 300K entries for large codebases
- **High-Performance Analytics**: PageRank at 4.9M nodes/second, Betweenness Centrality at 104K nodes/second
- **Sub-microsecond Response**: Cache hits deliver sub-microsecond response times for repeated operations
- **Memory Optimized**: Cache configurations optimized for 500+ file codebases with 500MB memory allocation
- **Comprehensive Benchmarks**: Performance monitoring with detailed cache effectiveness metrics

## Supported Languages

| Category | Languages | Count |
|----------|-----------|-------|
| **Web & Frontend** | JavaScript, TypeScript, HTML, CSS | 4 |
| **Backend & Systems** | Python, Java, C#, C++, C, Rust, Go | 7 |
| **JVM Languages** | Java, Kotlin, Scala | 3 |  
| **Functional** | Elixir, Elm | 2 |
| **Mobile** | Swift, Dart | 2 |
| **Scripting** | Ruby, PHP, Lua | 3 |
| **Data & Config** | SQL, YAML, JSON, TOML | 4 |
| **Markup & Docs** | XML, Markdown | 2 |
| **Additional** | Haskell, OCaml, F# | 3 |
| **Total** | | **25+** |

## Status

✅ **Multi-Language Support** - 25+ programming languages with ast-grep backend  
✅ **MCP SDK integrated** - Full protocol compliance across all languages  
✅ **Universal Architecture** - Language-agnostic graph structures and analysis  
✅ **Server architecture complete** - Enterprise-grade multi-language structure  
✅ **Core tools implemented** - 8 comprehensive analysis tools working across all languages  
✅ **Performance optimized** - Multi-language AST caching with intelligent routing  
✅ **Production ready** - comprehensive error handling, defensive security