pi-codegraph

pi-codegraph

Enables structural code analysis with worktree-aware index management, supporting explore, search, impact, and more via CodeGraph tools for Pi and OMP.

Category
访问服务器

README

@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.

Install

Pi

pi install npm:@isac322/pi-codegraph

OMP

omp install @isac322/pi-codegraph
omp plugin list

Restart 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.4.1 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
  • codegraph_search: symbol-name lookup
  • codegraph_node: one known symbol and its relationships
  • codegraph_files: indexed project structure
  • codegraph_callers: inbound calls
  • codegraph_callees: outbound calls
  • codegraph_impact: transitive change impact
  • codegraph_status: CodeGraph index health

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.

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"],
  "promptInjection": true,
  "codegraphExecutable": ""
}

Environment overrides:

  • PI_CODEGRAPH_AUTO_SYNC
  • PI_CODEGRAPH_AUTO_GC
  • PI_CODEGRAPH_INDEX_STORE
  • PI_CODEGRAPH_WORKER_IDLE_MS
  • PI_CODEGRAPH_MAX_WORKERS
  • PI_CODEGRAPH_REQUEST_TIMEOUT_MS
  • PI_CODEGRAPH_SYNC_MIN_INTERVAL_MS
  • PI_CODEGRAPH_MAX_OUTPUT_CHARS
  • PI_CODEGRAPH_ALLOWED_ROOTS
  • PI_CODEGRAPH_PROMPT_INJECTION
  • PI_CODEGRAPH_EXECUTABLE

PI_CODEGRAPH_ALLOWED_ROOTS uses the platform path delimiter.

Runtime behavior

  • Pi defers process startup until session_start and closes all resources on session_shutdown.
  • OMP uses one package-local MCP facade and project-scoped CodeGraph workers.
  • 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.
  • codegraph_files accepts absolute in-project paths and ~, normalizing them to repo-relative POSIX prefixes.
  • Large results are bounded and retain both their beginning and end with an explicit truncation marker.

Development

npm ci
npm run typecheck
npm run build

npm pack and local npm publish run the build through prepack. The release workflow installs locked dependencies, typechecks, builds dist, and publishes that distribution 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

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选