XRAY MCP - Progressive Code Intelligence for AI Assistants
❌ Without XRAY
AI assistants struggle with codebase understanding. You get:
- ❌ "I can't see your code structure"
- ❌ "I don't know what depends on this function"
- ❌ Generic refactoring advice without impact analysis
- ❌ No understanding of symbol relationships
✅ With XRAY
XRAY gives AI assistants code navigation capabilities. Add use XRAY tools
to your prompt:
XRAY provides three focused tools:
- 🗺️ Map (
explore_repo
) - See project structure with symbol skeletons - 🔍 Find (
find_symbol
) - Locate functions and classes with fuzzy search - 💥 Impact (
what_breaks
) - Find where a symbol is referenced
🚀 Quick Install
Modern Install with uv (Recommended)
Automated Install with uv
For the quickest setup, this script automates the uv
installation process.
Generate Config
Language Support
XRAY uses ast-grep, a tree-sitter powered structural search tool, providing accurate parsing for:
- Python - Functions, classes, methods, async functions
- JavaScript - Functions, classes, arrow functions, imports
- TypeScript - All JavaScript features plus interfaces, type aliases
- Go - Functions, structs, interfaces, methods
ast-grep ensures structural accuracy - it understands code syntax, not just text patterns.
The XRAY Workflow - Progressive Discovery
1. Map - Start Simple, Then Zoom In
2. Find - Locate Specific Symbols
3. Impact - See What Would Break
Architecture
Stateless design - No database, no persistent index. Each operation runs fresh ast-grep queries for real-time accuracy.
Why ast-grep?
Traditional grep searches text. ast-grep searches code structure:
- grep: Finds "authenticate" in function names, variables, comments, strings
- ast-grep: Finds only
def authenticate()
orfunction authenticate()
definitions
This structural approach provides clean, accurate results essential for reliable code intelligence.
Performance Characteristics
- Startup: Fast - launches ast-grep subprocess
- File tree: Python directory traversal
- Symbol search: Runs multiple ast-grep patterns, speed depends on codebase size
- Impact analysis: Name-based search across all files
- Memory: Minimal - no persistent state
What Makes This Practical
- Progressive Discovery - Start with directories, add symbols only where needed
- Smart Caching - Symbol extraction cached per git commit for instant re-runs
- Flexible Focus - Use
focus_dirs
to zoom into specific parts of large codebases - Enhanced Symbols - See function signatures and docstrings, not just names
- Based on tree-sitter - ast-grep provides accurate structural analysis
XRAY helps AI assistants avoid information overload while providing deep code intelligence where needed.
Stateless Design
XRAY performs on-demand structural analysis using ast-grep. There's no database to manage, no index to build, and no state to maintain. Each query runs fresh against your current code.
Getting Started
- Install: See
getting_started.md
for modern installation - Map the terrain:
explore_repo("/path/to/project")
- Find your target:
find_symbol("/path/to/project", "UserService")
- Assess impact:
what_breaks(symbol)
The XRAY Philosophy
XRAY bridges the gap between simple text search and complex LSP servers:
- More than grep - Matches code syntax patterns, not just text
- Less than LSP - No language servers or complex setup
- Practical for AI - Provides structured data about code relationships
A simple tool that helps AI assistants navigate codebases more effectively than text search alone.
Architectural Journey & Design Rationale
The current implementation of XRAY is the result of a rigorous evaluation of multiple code analysis methodologies. My journey involved prototyping and assessing several distinct approaches, each with its own set of trade-offs. Below is a summary of the considered architectures and the rationale for my final decision.
- Naive Grep-Based Analysis: I initially explored a baseline approach using standard
grep
for symbol identification. While expedient, this method proved fundamentally inadequate due to its inability to differentiate between syntactical constructs and simple text occurrences (e.g., comments, strings, variable names). The high signal-to-noise ratio rendered it impractical for reliable code intelligence. - Tree-Sitter Native Integration: A direct integration with
tree-sitter
was evaluated to leverage its powerful parsing capabilities. However, this path was fraught with significant implementation complexities, including intractable errors within the parser generation and binding layers. The maintenance overhead and steep learning curve for custom grammar development were deemed prohibitive for a lean, multi-language tool. - Language Server Protocol (LSP): I considered leveraging the Language Server Protocol for its comprehensive, standardized approach to code analysis. This was ultimately rejected due to the excessive operational burden it would impose on the end-user, requiring them to install, configure, and manage separate LSPs for each language in their environment. This friction conflicted with my goal of a lightweight, zero-configuration user experience.
- Comby-Based Structural Search:
Comby
was explored for its structural search and replacement capabilities. Despite its promising feature set, I encountered significant runtime instability and idiosyncratic behavior that undermined its reliability for mission-critical code analysis. The tool's performance and consistency did not meet my stringent requirements for a production-ready system. - ast-grep as the Core Engine: My final and current architecture is centered on
ast-grep
. This tool provides the optimal balance of structural awareness, performance, and ease of integration. By leveragingtree-sitter
internally, it offers robust, syntactically-aware code analysis without the complexities of directtree-sitter
integration or the overhead of LSPs. Its reliability and rich feature set for structural querying made it the unequivocal choice for XRAY's core engine.
Getting Started with XRAY - Modern Installation with uv
XRAY is a minimal-dependency code intelligence system that enhances AI assistants' understanding of codebases. This guide shows how to install and use XRAY with the modern uv
package manager.
Prerequisites
- Python 3.10 or later
- uv - Fast Python package manager
Installing uv
Installation Options
Option 1: Automated Install (Easiest)
For the quickest setup, use the one-line installer from the README.md
. This will handle everything for you.
Option 2: Quick Try with uvx (Recommended for Testing)
Run XRAY directly without installation using uvx
:
Option 3: Install as a Tool (Recommended for Regular Use)
Install XRAY as a persistent tool:
Option 4: Development Installation
For contributing or modifying XRAY:
Configure Your AI Assistant
After installation, configure your AI assistant to use XRAY:
Using the MCP Config Generator (Recommended)
For easier configuration, use the mcp-config-generator.py
script located in the XRAY repository. This script can generate the correct JSON configuration for various AI assistants and installation methods.
To use it:
- Navigate to the XRAY repository root:
- Run the script with your desired tool and installation method. For example, to get the configuration for Claude Desktop with an installed
xray-mcp
script:Or for VS Code with a local Python installation:The script will print the JSON configuration and instructions on where to add it.Available tools:cursor
,claude
,vscode
Available methods:local_python
,docker
,source
,installed_script
(method availability varies by tool)
Manual Configuration (Advanced)
If you prefer to configure manually, here are examples for common AI assistants:
Claude CLI (Claude Code)
For Claude CLI users, simply run:
Then verify it's connected:
Claude Desktop
Add to ~/Library/Application Support/Claude/claude_desktop_config.json
(macOS):
Or if installed as a tool:
Cursor
Settings → Cursor Settings → MCP → Add new global MCP server:
Minimal Dependencies
One of XRAY's best features is its minimal dependency profile. You don't need to install a suite of language servers. XRAY uses:
- ast-grep: A single, fast binary for structural code analysis.
- Python: For the server and core logic.
This means you can start using XRAY immediately after installation with no complex setup!
Verify Installation
1. Check XRAY is accessible
2. Test basic functionality
Create a test file test_xray.py
:
3. In your AI assistant, test these commands:
Expected: Success message with files indexed
Expected: Should find hello_world
function
Expected: Impact analysis showing any dependencies
Usage Examples
Once configured, use XRAY by adding "use XRAY tools" to your prompts:
Troubleshooting
uv not found
Make sure uv is in your PATH:
Permission denied
On macOS/Linux, you might need to make the script executable:
Python version issues
XRAY requires Python 3.10+. Check your version:
MCP connection issues
- Check XRAY is running:
xray-mcp --test
- Verify your MCP config JSON is valid
- Restart your AI assistant after config changes
Advanced Configuration
Custom Database Location
Set the XRAY_DB_PATH
environment variable:
Debug Mode
Enable debug logging:
What's Next?
- Index your first repository: In your AI assistant, ask it to "Build the index for my project. use XRAY tools"
- Explore the tools:
build_index
- Visual file tree of your repositoryfind_symbol
- Fuzzy search for functions, classes, and methodswhat_breaks
- Find what code depends on a symbol (reverse dependencies)what_depends
- Find what a symbol depends on (calls and imports)
Note: Results may include matches from comments or strings. The AI assistant will intelligently filter based on context.
- Read the documentation: Check out the README for detailed examples and API reference
Why XRAY Uses a Minimal Dependency Approach
XRAY is designed for simplicity and ease of use. It relies on:
- ast-grep: A powerful and fast single-binary tool for code analysis.
- Python: For its robust standard library and ease of scripting.
This approach avoids the complexity of setting up and managing multiple language servers, while still providing accurate, structural code intelligence.
Benefits of Using uv
- 10-100x faster than pip for installations
- No virtual environment hassles - uv manages everything
- Reproducible installs - uv.lock ensures consistency
- Built-in Python management - install any Python version
- Global tool management - like pipx but faster
Happy coding with XRAY! 🚀
remote-capable server
The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.
Enables AI assistants to understand and navigate codebases through structural analysis. Provides code mapping, symbol search, and impact analysis using ast-grep for accurate parsing of Python, JavaScript, TypeScript, and Go projects.
- ❌ Without XRAY
- ✅ With XRAY
- 🚀 Quick Install
- Language Support
- The XRAY Workflow - Progressive Discovery
- Architecture
- Why ast-grep?
- Performance Characteristics
- What Makes This Practical
- Stateless Design
- Getting Started
- The XRAY Philosophy
- Architectural Journey & Design Rationale
- Getting Started with XRAY - Modern Installation with uv
Related Resources
Related MCP Servers
- -securityFlicense-qualityAnalyzes codebases to generate dependency graphs and architectural insights across multiple programming languages, helping developers understand code structure and validate against architectural rules.Last updated -11JavaScript
- AsecurityAlicenseAqualityProvides code context and analysis for AI assistants by extracting directory structures and code symbols using WebAssembly Tree-sitter parsers with zero native dependencies.Last updated -17087JavaScriptMIT License
- AsecurityAlicenseAqualityProvides tools for analyzing project structures, searching through codebases, managing dependencies, and performing file operations with advanced filtering capabilities.Last updated -66871TypeScriptMIT License
- AsecurityAlicenseAqualityAI-powered code assistant that provides advanced search and discovery capabilities across GitHub and NPM ecosystems, helping users understand code patterns, implementations, and connections between repositories.Last updated -10526366TypeScriptMIT License