Use Graphify from an external MCP client
Connect a coding agent such as Claude Code or Codex to the code graph of a Graphify Knowledge. The agent gets a query_graph tool and answers questions about the repository ("where is the main loop, and what does it call?") from the graph.
The Graphify query MCP server runs on your computer, started by the agent over stdio. It authenticates with the Knowledge's embed key, so it needs no API key. With an embed key, query_graph answers only for that Knowledge, downloads its graph read-only and takes no Knowledge ID.
Before you begin
- A Graphify Knowledge that has finished processing: a Git repository source processed with the Graphify repository rule. See Build a code graph with Graphify.
- Update on the Knowledge row of your role, to generate the embed key. See Manage roles and users.
- A copy of
mcp_server.pyfrom the Graphify Query extension. An administrator can download the extension's files with Download installed extension on its Development tab. See Develop an extension. uvon your computer. On each query the server runs the Graphify CLI throughuvx, so the first query needs internet access to fetch it.
Get the embed key
- Open the Knowledge's settings and select the Embed tab.
- In General, if there is no code yet, select Generate embed code. This saves the settings and creates the embed key.
- Copy the
ek-…value from the embed code.
The key gives read access to the graph, which reveals the repository's structure and symbols. Keep it out of source control. To cut off every client that uses it, select Rotate key on the Embed tab. See Rotate the embed key.
Configure the MCP client
The client starts the server with two environment variables:
| Variable | Value |
|---|---|
RATIONAL_AI_URL | Your workspace's API address, ending in /api/, such as https://example.rational.is/api/ |
RATIONAL_AI_EMBED_KEY | The embed key |
Replace /path/to/mcp_server.py in the examples with the real path. Keep --no-project: without it, uv can pick up the Python project of the folder the agent runs in.
For Claude Code, add the server to the project's .mcp.json:
{
"mcpServers": {
"graphify": {
"command": "uv",
"args": ["run", "--python", "3.12", "--no-project", "/path/to/mcp_server.py"],
"env": {
"RATIONAL_AI_URL": "https://<workspace-host>/api/",
"RATIONAL_AI_EMBED_KEY": "<embed-key>"
}
}
}
}
For Codex, add it to config.toml:
[mcp_servers.graphify]
command = "uv"
args = ["run", "--python", "3.12", "--no-project", "/path/to/mcp_server.py"]
[mcp_servers.graphify.env]
RATIONAL_AI_URL = "https://<workspace-host>/api/"
RATIONAL_AI_EMBED_KEY = "<embed-key>"
Ask the graph a question
-
Restart the coding agent so it loads the server.
-
Ask a question that needs the graph. For a Knowledge built from the public DOOM repository:
Where is the main game loop in DOOM, and what important functions does it call?
The agent calls query_graph, which finds D_DoomLoop() in linuxdoom-1.10/d_main.c and the functions it calls, such as TryRunTics, D_Display and S_UpdateSounds.
query_graph takes a question of up to 4,000 characters. Optional arguments: mode (bfs for broad context, the default, or dfs to trace one path), token_budget (100 to 8,000, default 2,000) and context_filter (a list of values passed to Graphify's --context option).
Troubleshooting
| Symptom | What to check |
|---|---|
| The server can't reach Rational AI | RATIONAL_AI_URL is your workspace's address and ends in /api/. |
| Authentication fails, or access stops working | The embed key is missing, mistyped, or rotated. Copy the current key from the Embed tab. |
query_graph returns nothing, or the graph isn't found | Processing hasn't finished, or the source doesn't use the Graphify repository rule. |
The tool asks for a knowledgeId | RATIONAL_AI_EMBED_KEY doesn't reach the server. Check the env block of the client configuration. |
uv fails to start the server, or loads the wrong environment | The command is missing --no-project. |
| "graphify query failed" | uvx couldn't fetch or run the Graphify CLI. Check internet access on your computer. |
Next steps
- Build a code graph with Graphify: what the graph contains and how it's built.
- Embed a Knowledge: manage the embed key and the rest of the embed settings.