pi-codegraph
Provides read-only CodeGraph tools for exploring, navigating, and analyzing indexed codebases and worktrees.
Search indexed declarations by symbol name, kind, and limit.
Inspect a file with line-numbered source, symbol maps, and dependents, or inspect a named symbol and its relationships.
Browse the indexed file tree with path prefixes, patterns, depth, format, and metadata.
Find callers and callees of a symbol, optionally narrowed by definition file.
Analyze a symbol’s transitive impact radius.
Explore architecture, flows, and broad code questions with related symbols and grouped source.
Check CodeGraph index health and pending synchronization state.
Target projects/worktrees via optional
projectPath; Pi defaults it to the active cwd, while OMP child agents should pass their exact worktree path.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@pi-codegraph explore the architecture of the main module"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
@isac322/pi-codegraph
CodeGraph tools for Pi and OMP, with worktree-aware index lifecycle management.
Why this package
The extension exposes CodeGraph's structural tools with native Pi metadata and rendering while keeping OMP on its native MCP path. Indexes are separated per worktree, stored centrally, synchronized automatically, identity-checked, and garbage-collected after worktrees disappear.
Related MCP server: code-auditor-mcp
Install
Pi
pi install npm:@isac322/pi-codegraphOMP
omp install @isac322/pi-codegraph
omp plugin listRestart OMP or run /reload-plugins after installation. omp install uses the user scope by default.
OMP loads the package-local .mcp.json and omp.extensions entry. Pi loads pi.extensions and starts the internal MCP facade at session start, never during extension discovery.
The package installs @colbymchenry/codegraph@1.6.2 as an optional dependency and falls back to a codegraph executable on PATH.
Node.js 22.19 through Node 24 is required. OMP itself may run under Bun, but it starts this package's compiled MCP facade with the node command declared in .mcp.json; MCP child processes do not inherit or need to match the host agent's runtime.
The repository contains TypeScript source only. Release builds compile it into dist, and the npm tarball includes the compiled JavaScript, declarations, and source maps rather than the TypeScript runtime source.
Tools
codegraph_explore: broad architecture and flow exploration with line-numbered sourcecodegraph_search: symbol-name lookupcodegraph_node: indexed file reading, symbol inspection, and file/line disambiguationcodegraph_files: indexed project structurecodegraph_callers: inbound calls, optionally narrowed to a definition filecodegraph_callees: outbound calls, optionally narrowed to a definition filecodegraph_impact: transitive change impact, optionally narrowed to a definition filecodegraph_status: CodeGraph index health
codegraph_node accepts file without symbol to return current source with line numbers and dependents. Use offset and limit for a line range, symbolsOnly for a structural overview, or combine symbol with file or line to select a same-named definition.
Pi adds compact call/result rendering and /codegraph status|sync|doctor|gc.
Worktrees
Each worktree gets a distinct database. New indexes are stored under the configured central index store and exposed to CodeGraph through the worktree's .codegraph symlink. Existing real .codegraph directories remain in place and receive identity metadata.
A project path is accepted only when it is inside an allowed root or resolves to a worktree with the same Git common directory as the session root. Repository and worktree identities are checked before an index is reused. Missing or replaced worktrees fail closed.
Projects listed in excludedProjectRoots are never indexed. Sessions started in an excluded project skip CodeGraph initialization and prompt guidance, and tool calls for it return an error. Nothing is excluded by default.
Garbage collection runs when the facade starts and then hourly. It removes managed indexes whose worktree is gone, was replaced, or is now excluded. It also removes index directories that never received metadata once no prepare holds their lock and they have been untouched for 24 hours. Collection waits while the shared daemon or a project writer may still hold a database open. Live, malformed, or changing ownership records retain the index; removal reserves CodeGraph's rebuild lock before deleting a verified stale index.
Configuration
Global configuration is read from ~/.config/pi-codegraph/config.json, or from PI_CODEGRAPH_CONFIG.
{
"autoSync": true,
"autoGc": true,
"indexStore": "/home/me/.cache/pi-codegraph",
"workerIdleTimeoutMs": 300000,
"maxWorkers": 6,
"requestTimeoutMs": 30000,
"syncMinIntervalMs": 15000,
"maxOutputChars": 60000,
"allowedProjectRoots": ["/work/company"],
"excludedProjectRoots": ["/tmp", "~/scratch/**"],
"promptInjection": true,
"codegraphExecutable": ""
}Environment overrides:
PI_CODEGRAPH_AUTO_SYNCPI_CODEGRAPH_AUTO_GCPI_CODEGRAPH_INDEX_STOREPI_CODEGRAPH_WORKER_IDLE_MSPI_CODEGRAPH_MAX_WORKERSPI_CODEGRAPH_REQUEST_TIMEOUT_MSPI_CODEGRAPH_SYNC_MIN_INTERVAL_MSPI_CODEGRAPH_MAX_OUTPUT_CHARSPI_CODEGRAPH_ALLOWED_ROOTSPI_CODEGRAPH_EXCLUDED_ROOTSPI_CODEGRAPH_PROMPT_INJECTIONPI_CODEGRAPH_EXECUTABLE
PI_CODEGRAPH_ALLOWED_ROOTS and PI_CODEGRAPH_EXCLUDED_ROOTS use the platform path delimiter.
An excludedProjectRoots entry matches a project whose root is exactly that directory. Add /** to also exclude every project below it. For example, "/tmp" stops a session started in /tmp from indexing the whole temp directory but still indexes a Git worktree at /tmp/fix-123, while "/tmp/**" excludes both. Entries may start with ~. Symlinks are resolved, so /tmp also matches /private/tmp on macOS.
Runtime behavior
Pi defers process startup until
session_startand closes all resources onsession_shutdown.OMP uses the package-local MCP server and its native
tool_callhook. For CodeGraph MCP tools, an omittedprojectPathis rewritten to the trusted sessionctx.cwd; an explicit path, sibling worktree, and unrelated OMP tool are left unchanged.Workers are capped, evicted by least-recently-used idle order, and terminated after the idle timeout.
Tool cancellation and timeout propagate to the worker. Diagnostics are ANSI-stripped, size-limited, and redact common token and secret forms.
On the first prepare after a CodeGraph engine upgrade, the facade checks the index extraction version and performs one quiet full rebuild when CodeGraph marks it stale. The rebuild runs independently of a client request timeout. A successful check is cached for the facade's lifetime; a status or rebuild failure preserves the existing index and allows a later prepare to check again.
codegraph_files.pathand supported toolfilearguments accept absolute in-project paths and~; the facade normalizes them to repo-relative POSIX paths.Large results are bounded and retain both their beginning and end with an explicit truncation marker.
After CodeGraph initializes, rebuilds, or syncs an index, the facade truncates the SQLite write-ahead log so a large indexing transaction does not leave a WAL file as large as the data it wrote. A reader holding the log only postpones this until the next sync.
Development
npm ci
npm run typecheck
npm run buildnpm pack and local npm publish run the build through prepack. Pull requests and releases run the shared Release QA workflow, including both supported Node versions, OMP, Pi, shared-daemon integration, and an installed-package smoke test. The release workflow checks the exact revision before Release Please creates a tag, then typechecks and builds the tagged distribution before publishing through npm OIDC.
Security
Pi checks project trust before initialization or tool execution. The MCP facade resolves real paths and restricts access to the active workspace, sibling worktrees of the same repository, and explicitly configured roots.
Pi package gallery
The npm package declares the pi-package keyword and an explicit pi.extensions manifest. After npm publication, Pi's package gallery can index it at pi.dev/packages.
Releases are managed by Release Please. Conventional commits on main update a release PR. Merging that PR updates package.json and CHANGELOG.md, creates the version tag and GitHub Release, and publishes the package through npm trusted publishing in the same workflow. See CONTRIBUTING.md for the version rules and release process.
Use fix: for patch releases, feat: for minor releases, and a ! or BREAKING CHANGE: footer for major releases. Configure the npm trusted publisher with GitHub owner isac322, repository pi-codegraph, workflow filename publish.yml, no environment, and the npm publish action.
Shared daemon lifecycle
All Pi and OMP sessions that use the same indexStore attach to one CodeGraph daemon. Each tool request forwards its canonical projectPath, so the daemon can serve multiple repositories and Git worktrees without merging their indexes.
maxWorkers controls the shared daemon's query worker count. workerIdleTimeoutMs controls how long the daemon remains alive after the last Pi or OMP client disconnects; the default is five minutes. Set the same indexStore for every session that should share a daemon.
License
MIT
Available Tools
8 toolscodegraph_calleesARead-onlyIdempotent
Find functions and methods called by a symbol, optionally selecting its definition by file.
Inputs: symbol (required), file, limit, projectPath.
codegraph_callersBRead-onlyIdempotent
Find functions and methods that call a symbol, optionally selecting its definition by file.
Inputs: symbol (required), file, limit, projectPath.
codegraph_exploreARead-onlyIdempotent
Explore related symbols and line-numbered source grouped by file. Best first tool for architecture, flows, and broad code questions.
Inputs: query (required), maxFiles, projectPath.
codegraph_filesBRead-onlyIdempotent
Read the indexed project file tree. Paths are normalized to repo-relative POSIX prefixes.
Inputs: path, format, pattern, maxDepth, +2 more.
codegraph_impactBRead-onlyIdempotent
Analyze the transitive impact radius of a symbol, optionally selecting its definition by file.
Inputs: symbol (required), file, depth, projectPath.
codegraph_nodeARead-onlyIdempotent
Read an indexed file with line numbers and dependents, or inspect a named symbol with its source and relationships.
Inputs: file, line, limit, offset, +4 more.
codegraph_searchARead-onlyIdempotent
Search indexed declarations by symbol name. Returns locations only; use codegraph_explore when you need source and relationships.
Inputs: query (required), kind, limit, projectPath.
codegraph_statusARead-onlyIdempotent
Report CodeGraph index health and pending synchronization state.
Inputs: projectPath.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 8 tools
Most tools have distinct purposes: search returns locations, callers/callees handle direct relationships, impact handles transitive reach, and files/status serve different concerns. The main overlap is between codegraph_node and codegraph_explore, both of which can return source and relationships, but the descriptions clarify that node is for a single named symbol or file while explore is for broader code questions.
All tools share a consistent codegraph_ prefix and use readable lowercase names. The pattern is slightly mixed between noun-style names (node, files, status, callers, callees, impact) and verb-style names (search, explore), but the naming is still predictable and easy to navigate.
Eight tools is well-scoped for a code graph query server. Each tool covers a meaningful query mode without redundant bloat, and the count feels appropriate for both simple lookups and deeper dependency analysis.
The surface covers the core code graph workflow: locating symbols, reading source, viewing file trees, finding callers/callees, assessing transitive impact, exploring related code, and checking index health. No major lifecycle gaps are apparent for a read-only code indexing tool.
Maintenance
Related MCP Connectors
Search indexed code, trace dependencies, assess change impact, and recall repository memory.
Ask a codebase what calls what: search, blast radius, paths between symbols, and diffs.
Code intelligence for coding agents: semantic, AST, graph, and full-text search. 279+ languages.
Hosted code graph over MCP: exact callers, dependencies, and cross-repo blast radius for AI agents.
Related MCP Servers
- FlicenseAqualityCmaintenanceIndexes a workspace and exposes code-navigation tools to Codex, enabling symbol lookup, reference finding, dependency analysis, and security audit for local codebases.10-
- AlicenseAqualityBmaintenanceEnables AI assistants to search, analyze, and understand multi-language codebases by providing indexed code intelligence via MCP.16630 npm8MIT
- AlicenseNot gradedqualityFmaintenanceProvides worktree-aware semantic code indexing and search via MCP, enabling agents to query indexed code and monitor indexing status while keeping lifecycle operations separate.MIT
- AlicenseNot gradedqualityBmaintenanceEnables coding agents to query a local, multi-repo code graph for symbol exploration, blast radius analysis, co-change mining, and durable code-anchored memory via MCP tools.223 npm16Business Source 1.1