Skill: clangd-graph-rag
This skill enables deep semantic and structural analysis of C/C++ codebases using a pre-built Neo4j GraphRAG. It provides insights into call chains, class hierarchies, macro causality, and type aliases.
Activation
Activate this skill when the user asks questions about:
- Project architecture, module responsibilities, or high-level workflows.
- Call chains (caller/callee relationships) or method overriding.
- C++ inheritance structures and template specializations.
- "Magic symbols" generated by macros or complex
typedef/usingalias chains. - Semantic code search (e.g., "Find the logic for packet validation").
Setup Requirements
- A Neo4j database populated by the
clangd-graph-ragpipeline. - The
graph_mcp_server.pymust be configured as an MCP server. - Environment variables:
NEO4J_URI,NEO4J_USER,NEO4J_PASSWORD.
Core Instructions
1. Orientation & Discovery
- Always start by calling
get_project_infoandget_graph_schema. get_project_infoprovides thepath(absolute project root) and a high-levelsummary.get_graph_schemaexplains the node labels (e.g.,FUNCTION,CLASS_STRUCTURE,MACRO,TYPE_ALIAS) and relationships.- Paths: All
pathproperties in the graph are relative to the project root.
2. Structural Querying (Cypher)
- Use
execute_cypher_queryfor precise structural analysis. - Semantic Labels: Prefer specific labels (
FUNCTION,METHOD,CLASS_STRUCTURE,MACRO,TYPE_ALIAS) over the genericENTITYlabel for efficiency. - Macros: Follow
(s)-[:EXPANDED_FROM]->(m:MACRO)to explain symbols generated by the preprocessor. Check theoriginal_nameproperty on the symbol for the raw invocation text. - Types: Follow
(ta:TYPE_ALIAS)-[:ALIAS_OF]->(t)to resolve alias chains (e.g.,MyInt2->MyInt->int). - Calls: Use
SHORTESTpath selectors (e.g.,MATCH p = SHORTEST 5 (a:FUNCTION)-[:CALLS*]->(b:FUNCTION)) to prevent result set explosion. - Result Management: Always use
LIMIT(e.g.,LIMIT 10) on custom queries.
3. Implementation Retrieval
- Precise Reading: Use
get_source_code_by_id. It retrieves the exact implementation span (including template headers and bodies) as seen by the compiler. - File Context: Use
get_source_code_by_pathonly when you need to see the entire surrounding file (e.g., checking includes or global variables). - Labels: Use
get_semantic_labelif you are unsure which specific label a node has (besidesENTITY).
4. Semantic Search
- Use
search_nodes_for_semantic_similarityfor concept-based discovery (e.g., "Where is the error handling for disk I/O?"). - Use the returned
summaryproperty to understand a node's purpose without reading its code.
Example Workflow: Resolving a "Magic" Symbol
- Find:
MATCH (n:ENTITY {name: 'SomeMagicName'}) RETURN n.id, n.original_name. - Trace:
MATCH (n)-[:EXPANDED_FROM]->(m:MACRO) RETURN m.name, m.macro_definition. - Analyze: Read
m.macro_definitionor useget_source_code_by_idon theMACROnode to see the ground-truth definition. - Context: Look at
n.original_nameto see the exact arguments passed to the macro at the expansion site.
Source: 2015xli/clangd-graph-rag — distributed by TomeVault.