This project is a high-performance static analysis toolkit for the Ruby language. The goal is to be a solid foundation to power a variety of tools, such as type checkers, linters, language servers and more.
Both Ruby and Rust APIs are made available through a gem and a crate, respectively. Here's a simple example of using the Ruby API:
# Create a new graph representing the current workspace
graph = Rubydex::Graph.new
# Configuring graph LSP encoding
graph.encoding = "utf16"
# Index the entire workspace with all dependencies
graph.index_workspace
# Or index specific file paths
graph.index_all(["path/to/file.rb"])
# Transform the initially collected information into its semantic understanding by running resolution
graph.resolve
# Get all diagnostics acquired during the analysis
graph.diagnostics
# Iterating over graph nodes
graph.declarations
graph.documents
graph.constant_references
graph.method_references
# Analyzing require paths
graph.resolve_require_path("rails/engine", load_paths) # => document pointed by `rails/engine`
graph.require_paths(load_paths) # => array of all indexed require paths
# Querying
graph["Foo"] # Get declaration by fully qualified name
graph.search("Foo#b") # Name search
graph.resolve_constant("Bar", ["Foo", "Baz::Qux"]) # Resolve constant reference based on nesting
# Declarations
declaration = graph["Foo"]
# All declarations include
declaration.name
declaration.unqualified_name
declaration.definitions
declaration.owner
# Namespace declarations include
declaration.member("bar()")
declaration.member("@ivar")
declaration.singleton_class
declaration.ancestors
declaration.descendants
# Documents
document = graph.documents.first
document.uri
document.definitions # => list of definitions discovered in this document
# Definitions
definition = declaration.definitions.first
definition.location
definition.comments
definition.name
definition.deprecated?
definition.name_location
# Locations
location = definition.location
location.path
# Diagnostics
diagnostic = graph.diagnostics.first
diagnostic.rule
diagnostic.message
diagnostic.location
Rubydex can run as an MCP (Model Context Protocol) server, enabling AI assistants like Claude to semantically query your Ruby codebase.
Add Rubydex to the Ruby project you want to index:
ruby
gem "rubydex"
Install the bundle:
bash
bundle install
Configure your MCP client to run bundle exec rubydex_mcp.
Using Claude Code as an example:
bash
claude mcp add --scope project rubydex -- bundle exec rubydex_mcp
Using Codex as an example:
bash
codex mcp add rubydex -- bundle exec rubydex_mcp
Start your MCP client from that project directory. The MCP server indexes the project at startup and provides semantic code intelligence tools through the tools below.
| Tool | Description |
|---|---|
search_declarations |
Fuzzy search for classes, modules, methods, constants |
get_declaration |
Full details by fully qualified name with docs, ancestors, members |
get_descendants |
What classes/modules inherit from or include this one |
find_constant_references |
All precise, resolved constant references across the codebase |
get_file_declarations |
List declarations defined in a specific file |
codebase_stats |
High-level statistics about the indexed codebase |
$ claude mcp add rubydex \
-- python -m otcore.mcp_server <graph>