codegraph.mdc 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. ---
  2. description: CodeGraph MCP usage guide — when to use which tool
  3. alwaysApply: true
  4. ---
  5. <!-- CODEGRAPH_START -->
  6. ## CodeGraph
  7. This project has a CodeGraph MCP server (`codegraph_*` tools) configured. CodeGraph is a tree-sitter-parsed knowledge graph of every symbol, edge, and file. Reads are sub-millisecond and return structural information grep cannot.
  8. ### When to prefer codegraph over native search
  9. Use codegraph for **structural** questions — what calls what, what would break, where is X defined, what is X's signature. Use native grep/read only for **literal text** queries (string contents, comments, log messages) or after you already have a specific file open.
  10. | Question | Tool |
  11. |---|---|
  12. | "Where is X defined?" / "Find symbol named X" | `codegraph_search` |
  13. | "What calls function Y?" | `codegraph_callers` |
  14. | "What does Y call?" | `codegraph_callees` |
  15. | "What would break if I changed Z?" | `codegraph_impact` |
  16. | "Show me Y's signature / source / docstring" | `codegraph_node` |
  17. | "Give me focused context for a task/area" | `codegraph_context` |
  18. | "Survey an unfamiliar module/topic" | `codegraph_explore` |
  19. | "What files exist under path/" | `codegraph_files` |
  20. | "Is the index healthy?" | `codegraph_status` |
  21. ### Rules of thumb
  22. - **Trust codegraph results.** They come from a full AST parse. Do NOT re-verify them with grep — that's slower, less accurate, and wastes context.
  23. - **Don't grep first** when looking up a symbol by name. `codegraph_search` is faster and returns kind + location + signature in one call.
  24. - **Don't chain `codegraph_search` + `codegraph_node`** when you just want context — `codegraph_context` is one call.
  25. - **`codegraph_explore` is the heavy hitter** for unfamiliar areas — it returns full source from all relevant files in one call, but is token-heavy. If your harness supports parallel subagents (e.g., Claude Code's Task tool), spawn one for explore-class questions to keep main session context clean.
  26. - **Index lag**: the file watcher debounces ~500ms behind writes; don't re-query immediately after editing a file in the same turn.
  27. ### If `.codegraph/` doesn't exist
  28. The MCP server returns "not initialized." Ask the user: *"I notice this project doesn't have CodeGraph initialized. Want me to run `codegraph init -i` to build the index?"*
  29. <!-- CODEGRAPH_END -->