Powerful features for codebase intelligence
Every tool you need to understand, query, edit, and optimize your codebase.
Architecture
Tree-sitter AST Parsing
Robust, language-agnostic parsing using Tree-sitter grammars. Extracts functions, classes, modules, imports, and call relationships with full source location tracking.
| Language | Status | Extensions |
|---|---|---|
| Python | Fully Supported | .py |
| TypeScript | Fully Supported | .ts, .tsx, .mts, .cts |
| JavaScript | Fully Supported | .js, .jsx, .mjs, .cjs |
| Rust | Fully Supported | .rs |
| Java | Fully Supported | .java |
| C | Fully Supported | .c |
| C++ | Fully Supported | .cpp, .h, .hpp, .cc, .cxx, .hxx, .hh, .ixx, .cppm, .ccm |
| Lua | Fully Supported | .lua |
| C# | Fully Supported | .cs |
| Go | Fully Supported | .go |
| PHP | Fully Supported | .php |
| Dart | Fully Supported | .dart |
| Ruby | Structural Support | .rb |
| Scala | In Development | .scala, .sc |
Knowledge Graph Architecture
Your codebase stored as an interconnected graph in Memgraph. Nodes represent code entities, edges represent relationships like calls, imports, contains, and inherits.
Every language lands in the same schema, so one Cypher query spans a polyglot monorepo. I/O, data-flow, and ast-grep finding nodes are opt-in capture groups.
Natural Language Querying
Ask questions in plain English. The AI translates your intent into Cypher queries, executes them against the graph, and returns human-readable answers.
# Natural Language Queries> "What functions call the authenticate method?"> "Show me all classes that implement the Logger interface"> "Find functions with more than 50 lines in the auth module"> "What are the dependencies between the payment and user modules?"
AI-Powered Code Editing
Surgical code replacement that targets specific functions using AST analysis. Preview diffs before applying changes with exact code block modifications.
# Surgical Code Replacement> surgical_replace_code(file_path="auth/login.py",target_code="...existing block...",new_code="...updated code...")✓ Replaced code block in auth/login.py (lines 42-51)
Interactive Code Optimization
AI analyzes your codebase with language-specific best practices. Review each suggestion interactively and apply with confidence.
# AI-Powered Optimization$ cgr optimize python --repo-path ./authSuggestions:1. [auth/login.py:42] Add rate limiting to authenticate_userImpact: HIGH | Type: Security[Accept] [Reject] [Modify]2. [auth/token.py:15] Use constant-time comparison for token validationImpact: HIGH | Type: Security[Accept] [Reject] [Modify]
Dead Code Detection
Find functions and methods unreachable from any entry point by walking CALLS and REFERENCES edges from roots. CI-friendly with --fail-on-found.
# Find code unreachable from any entry point$ cgr dead-code --fail-on-foundDead code candidates (3):auth/legacy.py:12 validate_md5_token (function)api/v1/users.py:88 UserSerializer.to_xml (method)utils/compat.py:5 py2_urlencode (function)Exit code 1 (CI gate triggered)
Structural Search & Replace
Find and rewrite code by AST pattern with ast-grep — structure-aware matching instead of text or regex. Exposed as agent tools, with a dry-run diff before anything is written.
# Match and rewrite by AST pattern, not text> structural_search(pattern="requests.get($URL)",language="python")3 matches:api/client.py:31:12 requests.get(BASE_URL)jobs/sync.py:88:8 requests.get(feed_url)tools/probe.py:14:4 requests.get("https://health")> structural_replace(pattern="requests.get($URL)",rewrite="http_client.get($URL)",dry_run=true)--- api/client.py- resp = requests.get(BASE_URL)+ resp = http_client.get(BASE_URL)
I/O & Data-Flow Tracing
Opt into the io capture group and the graph gains Resource nodes for files, environment variables, networks, sockets, and databases, plus READS_FROM, WRITES_TO, and FLOWS_TO taint edges. Provenance questions become graph reachability.
// Does anything from the environment reach stdout?MATCH path = (src:Resource {kind: 'ENV'})-[:FLOWS_TO*1..5]->(sink:Resource {kind: 'STDOUT'})RETURN path// Which callables read secrets from disk?MATCH (f)-[:READS_FROM]->(r:Resource {kind: 'FILE'})WHERE r.qualified_name CONTAINS 'credentials'RETURN f.qualified_name, r.qualified_name
Security & Code Smell Findings
The findings capture group runs bundled ast-grep rule packs and stores each hit as a SecurityIssue, CodeSmell, or Pattern node linked to its module — so audit results live in the same graph you already query.
// Security issues and code smells as graph nodesMATCH (m:Module)-[:HAS_VULNERABILITY]->(s:SecurityIssue)RETURN m.path, s.name, s.message, s.start_line// Smells inside a single packageMATCH (m:Module)-[:HAS_SMELL]->(c:CodeSmell)WHERE m.qualified_name STARTS WITH 'payments.'RETURN m.qualified_name, c.name, c.snippet
Semantic Code Search
Find functions by describing what they do. Search by intent rather than exact names.
# Semantic Search — find by intent, not by name> semantic_search("error handling functions")Found 5 results for "error handling functions":1. auth.exceptions:handle_auth_error (score: 0.923)2. api.middleware:error_handler (score: 0.891)3. db.retry:handle_connection_failure (score: 0.847)4. payments.stripe:handle_webhook_error (score: 0.812)5. utils.logging:log_and_reraise (score: 0.798)> semantic_search("user authentication and login")Found 3 results:1. auth.login:authenticate_user (score: 0.951)2. auth.token:verify_jwt_token (score: 0.887)
MCP Server / Claude Code
Full MCP server integration with 15 tools available directly in Claude Code. Index, query, edit, and search without leaving your terminal.
list_projectsdelete_projectwipe_databaseindex_repositoryupdate_repositoryquery_code_graphget_code_snippetsurgical_replace_coderead_filewrite_filelist_directorysemantic_searchstructural_searchstructural_replaceask_agentGraph Export & Real-Time Updates
Export your knowledge graph data for external analysis. A debounced file watcher keeps the graph synchronised as your codebase changes, and cgr index writes a protobuf index for offline use.
{"nodes": [{"node_id": 0,"labels": ["Module"],"properties": {"qualified_name": "auth.login","name": "login","path": "auth/login.py"}},{"node_id": 1,"labels": ["Function"],"properties": {"qualified_name": "auth.login:authenticate_user","name": "authenticate_user","decorators": []}},{"node_id": 2,"labels": ["Class"],"properties": {"qualified_name": "auth.login:AuthService","name": "AuthService","decorators": []}}],"relationships": [{"from_id": 0, "to_id": 1,"type": "DEFINES","properties": {}},{"from_id": 1, "to_id": 5,"type": "CALLS","properties": {}}],"metadata": {"total_nodes": 1247,"total_relationships": 3891,"exported_at": "2025-01-15T10:30:00+00:00"}}
Python SDK & Packaged Stack
Install cgr from PyPI, bring up the packaged Memgraph + Qdrant stack with cgr daemon up, and drive the graph programmatically through the cgr package — graph loader, Cypher generator, semantic search, and settings.
from cgr import load_graphgraph = load_graph("my_graph.json")print(graph.summary())for fn in graph.find_nodes_by_label("Function")[:5]:rels = graph.get_relationships_for_node(fn.node_id)print(fn.properties["name"], len(rels))
Extensible Language Support
Adding a new language is straightforward thanks to the unified Tree-sitter architecture, and the pluggable ast-grep tier adds structural support — modules, functions, classes, and imports — from a single YAML pattern file, no hand-written parser required. Every language produces the same graph schema, so all query and editing tools work automatically with new languages.
# One YAML file adds a language to the graphlanguage: rubyast_grep_id: rubyextensions:- ".rb"functions:- "def self.$NAME"- "def $NAME"classes:- "class $NAME"- "module $NAME"imports:- "require $PATH"- "require_relative $PATH"