Set up a knowledge graph for Cursor
Setup guide · .cursor/rules · optional MCP
Cursor is quick at finding code that looks relevant to your prompt. What its agent lacks is typed structure: which function calls which, what imports what, how far a change propagates. Graphify builds that structure as a local knowledge graph in graphify-out/ and wires Cursor to it with a single always-on rule, so the agent queries the graph before it greps. (Comparing the two approaches head-on? See Graphify vs Cursor.)
The rule Graphify writes into Cursor
graphify cursor install creates exactly one file: .cursor/rules/graphify.mdc, with alwaysApply: truein its frontmatter, so Cursor includes it in every conversation. No hooks and no background process; Cursor does not expose PreToolUse-style hooks, so an always-on rule is the native mechanism (this is also why Cursor's setup differs from Claude Code's).
---description: graphify knowledge graph contextalwaysApply: true--- This project has a graphify knowledge graph at graphify-out/. **MANDATORY: Before using Read, Grep, Glob, or Bash to explore thecodebase, you MUST run graphify first:**Below that, the rule names the three commands the agent should reach for: graphify query "<question>" for a scoped subgraph, graphify path "<A>" "<B>" for the dependency path between two symbols, and graphify explain "<concept>" for everything connected to a node. It also tells the agent to pass the same guidance to every subagent it spawns, to prefer the generated wiki when one exists, and to run graphify update . after modifying files. The file is wholly owned by Graphify (upgrades overwrite it, so stale wording never lingers) and it is committable, so one install covers the whole team.
Set it up
- Install the CLI. If
graphifyis not found in Cursor's terminal afterwards, runuv tool update-shelland restart Cursor. - From the project root:
graphify cursor install. - Build the graph with
/graphify .if you have not already; the install reminds you to. It producesgraphify-out/graph.jsonplus the interactivegraph.htmlandGRAPH_REPORT.md. - Ask Cursor a structural question and watch the agent query the graph first.
$ uv tool install graphifyy$ graphify cursor installWhat a query looks like inside Cursor
Say you ask how the request handler reaches ModelField in a FastAPI-sized codebase. Instead of opening files, the agent runs a path query in the terminal and gets the route hop by hop:
$ graphify path "FastAPI" "ModelField"Shortest path (3 hops): FastAPI --uses--> DefaultPlaceholder <--references-- get_request_handler() --references--> ModelFieldFor broad questions, graphify queryreturns a scoped subgraph under a token budget; for one symbol's full neighborhood, graphify explain lists every edge. Results carry file:line citations, and each edge is tagged EXTRACTED (parsed from the AST), INFERRED (a model connected it), or AMBIGUOUS (evidence, not fully resolved), so the agent knows what was found versus guessed. The full command set is in the CLI reference.
Optional: the MCP server in .cursor/mcp.json
The rule plus the CLI is the whole default setup. If you would rather expose the graph to Cursor as native MCP tools, register the server in your project's .cursor/mcp.json (or ~/.cursor/mcp.json globally):
{ "mcpServers": { "graphify": { "command": "python", "args": ["-m", "graphify.serve", "graphify-out/graph.json"] } }}That serves ten tools over the graph (query_graph, shortest_path, god_nodes, graph_stats, the PR-triage set, and more), documented in the MCP tools reference. The stdio server ships as an extra: uv tool install "graphifyy[mcp]".
Keeping the graph current
After edits, graphify update .re-extracts only the files that changed (AST-only, no API cost); the rule tells Cursor's agent to run it itself after modifying code. For hands-off freshness, graphify hook install adds post-commit and post-checkout git hooks that refresh the graph as you work.
Troubleshooting
- The agent ignores the graph: confirm
.cursor/rules/graphify.mdcexists and its frontmatter saysalwaysApply: true, then start a new conversation so the rule is loaded. - The agent runs graphify but gets
command not found: Cursor's terminal does not have the uv or pipx bin dir on PATH. Runuv tool update-shell(orpipx ensurepath) and restart Cursor. ModuleNotFoundError: No module named 'graphify': usually a plainpip installon Mac or Windows pointing at a different Python than the one recorded ingraphify-out/.graphify_python. Install with uv or pipx instead.- The agent still greps: that is by design when
graphify-out/graph.jsondoes not exist yet. The rule permits raw reads in that case, so build the graph first.
Cursor FAQ
Does Graphify replace Cursor's built-in codebase indexing?
No. Cursor's own retrieval keeps working exactly as before. Graphify adds something different: a typed graph of functions, classes, modules, and their call, import, and reference edges, parsed locally with tree-sitter, that the agent queries explicitly. Similarity search tells the agent what looks relevant; the graph tells it what actually connects to what, with a confidence tag on every edge.
Should I commit .cursor/rules/graphify.mdc?
Yes. The rule is a plain project file and is meant to be committed, so one install covers the whole team. Teammates need the graphifyy CLI installed and a built graph (graphify-out/graph.json) for the queries to work.
Does the rule apply to Cursor's subagents?
The rule instructs the agent to include the same query-first guidance in every subagent prompt that involves code exploration, so spawned agents are pointed at the graph too.
Do I need the MCP server in Cursor?
No. The rule plus the CLI is the complete default setup, and it is what graphify cursor install configures. The MCP server is optional, for when you want the graph exposed to Cursor as native tools via .cursor/mcp.json.
Does my code leave my machine?
Source code is parsed locally with tree-sitter (36 language grammars); building code edges never requires an API call. Non-code files such as docs and PDFs are read by the model you already use. Nothing is sent to Graphify: there is no telemetry and no account.
How do I remove it?
graphify cursor uninstall deletes the rule file; graphify uninstall removes Graphify from every platform at once. Add --purge to also delete the graphify-out/ directory.
Next steps
The quickstart walks the whole flow from install to first query, and the CLI reference covers every command the rule points Cursor at. Running Claude Code alongside Cursor? The same graph serves both: see Graphify + Claude Code, or browse all 17 assistants on the integrations page.