Rpg Encoder

io.github.userFRM由 GitHub 帳號 userFRM 發布v0.6.7更新於 Oct 24, 2026

Semantic code graph for AI-assisted code understanding via tree-sitter and MCP.

概覽

AI 產生的概覽

為本機程式碼庫建立語意圖譜,讓助理能依意圖搜尋、探索程式碼並規劃變更,不必反覆 grep 檔案。

可以做什麼
使用 Tree-sitter 索引程式碼庫,支援 15 種語言,擷取函式、類別、方法與相依邊。接著由 LLM 為每個實體標註動賓式特徵,並聚類成三層語意階層。工具包括 build_rpg、update_rpg、semantic_snapshot、search_node、fetch_node、explore_rpg、context_pack、impact_radius、plan_change、analyze_health 與 detect_cycles。工作區變動時圖譜會自動重新同步。
適用情境
適合需要整體理解程式碼庫的情境:依行為而非名稱定位程式碼、追蹤呼叫者與被呼叫者、評估變更影響範圍,或規劃重構。主要針對較大型程式碼庫,避免反覆 grep、cat 與讀取檔案浪費 token。
執行需求
以 stdio 本機程序執行,透過 npx 從 npm 套件 rpg-encoder 安裝,不需要 Rust 工具鏈或編譯。它會從工作目錄自動辨識專案根目錄。選用的自主標註會呼叫外部 LLM 服務,需要 API 金鑰,可從 ANTHROPIC_API_KEY 等環境變數取得。
安裝前請注意
圖譜會寫入儲存庫中的 .rpg/graph.json,並可安裝 pre-commit 鉤子在提交時更新。自主標註會把實體原始碼傳送給第三方 LLM 服務並產生費用,約每 100 個實體 0.02 美元;建議先用 dry-run 估算成本。由助理標註則消耗助理自身的訂閱額度。清單中未宣告任何憑證。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 Rpg Encoder,將其新增到工作區。
  2. 為需要使用其工具的對話啟用該服務。

Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。

其他 MCP 客戶端

參照 儲存庫 中的啟動說明。

README

rpg-encoder

Give your AI agent a brain for your codebase.

[CI] [MIT License] [Rust 1.85+] [npm] [MCP] [Stars]


AI coding agents waste most of their tool calls fumbling through your codebase with grep, cat, find, and file reads. rpg-encoder fixes that. It builds a semantic graph of your code with Tree-sitter — not just what calls what, but what every function does — and gives your AI assistant whole-repo understanding via MCP in a single tool call.

[Without RPG: 34,000 chaotic grep/cat/find calls. With RPG: one semantic_snapshot call returns a structured map of the whole repo.]


Quick Start

bash
claude mcp add rpg -- npx -y -p rpg-encoder rpg-mcp-server

One command. Works with Claude Code, Cursor, opencode, Windsurf, or any MCP-compatible agent. No Rust toolchain, no cloning, no building — npx downloads a pre-built binary for your platform.

Then open any repo and tell your agent:

"Build and lift the RPG for this repo"

Your agent handles everything: indexes entities (seconds), reads each function and adds intent-level features (a few minutes), organizes them into a semantic hierarchy, and commits .rpg/graph.json for your team.

For repos with ~100+ entities, lifting_status will tell your agent to delegate the lifting loop to a sub-agent or a cheaper model — feature extraction is pattern-matching, not novel reasoning. If your runtime has no sub-agent mechanism, run rpg-encoder lift --provider anthropic|openai from the terminal with an API key — the CLI drives an external LLM directly with no agent involvement. After the CLI finishes, call reload_rpg in your session to load the updated graph. The CLI lifts entities with no features; re-lifting stale entities (features present but outdated after code changes) is handled by the in-session MCP flow, not the CLI.

Once lifted, try:

  • "What handles authentication?" — finds code even when nothing is named "auth"
  • "Show everything that depends on the database connection"
  • "Plan a change to add rate limiting to API endpoints"

Use RPG before grep, cat, find

The server instructions tell your agent to reach for RPG tools FIRST for any question about code structure or behavior. That reflex matters — grep, cat, and ad-hoc file reads burn tokens and miss semantic relationships RPG already knows.

If you'd otherwise reach for...Use this instead
grep -r / rg (by intent)search_node(query="...")
grep -r / rg (by name)search_node(query="...", mode="snippets")
cat / reading a functionfetch_node(entity_id="file:name")
chained greps for callers/calleesexplore_rpg(entity_id="...", direction="...")
recursive grep for "what depends on X"impact_radius(entity_id="...")
wc -l / find / treerpg_info
reading many files for contextsemantic_snapshot
manual search → fetch → explore chainscontext_pack(query="...")
"how do I refactor X safely"plan_change(goal="...")

Fall back to grep, cat, or file reads only when the query is about literal text (string search, comments, TODOs, log messages) — not about structure.


How It Works

[Four-stage pipeline: Parse (tree-sitter) → Lift (verb-object features) → Organize (3-level hierarchy) → Understand (LLM gets full repo knowledge)]

  1. Parse — Tree-sitter extracts entities (functions, classes, methods) and dependency edges (imports, calls, inheritance) from 15 languages.
  2. Lift — An LLM (your agent, or a cheap API like Haiku) reads each entity and writes verb-object features: "validate JWT tokens", "serialize config to disk".
  3. Organize — Features cluster into a 3-level semantic hierarchy (Area → Category → Subcategory) that emerges from what the code does, not the file tree.
  4. Understand — semantic_snapshot compresses the whole graph into ~25K tokens. Your LLM reads it once and knows the repo.

The semantic snapshot

[The whole repo — ~500K tokens of source — compressed 20x into a ~25K token snapshot containing hierarchy, features, dependencies, and hot spots]

Instead of grepping through files, the LLM calls semantic_snapshot once and receives:

  • Hierarchy — every functional area with aggregate features
  • Entities — every function, class, method grouped by area, with its semantic features
  • Dependency skeleton — condensed call graph with qualified names
  • Hot spots — top 10 most-connected entities (the architectural backbone)

~25K tokens covers ~1000 entities. That's 2-3% of a 1M context window — the LLM starts every session already knowing your repo.

Self-maintaining graph

[Git HEAD moves → RPG Server auto-syncs → update_rpg applies additions/modifications/removals → graph always fresh, zero agent action]

Whenever your working tree changes — committed, staged, or unstaged — the MCP server automatically re-syncs before responding to the next query. A changeset hash over (path, size, mtime) means repeated saves of the same file trigger one sync, and idle queries trigger none. Reverts are detected too: if a previously-dirty file returns to its HEAD state, the graph is restored.

Two ways to lift

ModeCommandCostWho pays
Agent lifting"Build and lift the RPG"Subscription tokensYour Claude Code / Cursor subscription
Autonomous liftingauto_lift(provider="anthropic", api_key_env="ANTHROPIC_API_KEY")~$0.02 per 100 entitiesExternal API key (Haiku, GPT-4o-mini, OpenRouter, Gemini)

auto_lift calls a cheap external LLM directly — your coding subscription never touches the lifting work. Use api_key_env to resolve keys from environment variables so they never appear in tool call transcripts.


Architecture

[Your codebase (15 languages) → RPG Engine (5 Rust crates: parser, encoder, nav, lift, mcp) → Clients (Claude Code, Cursor, opencode) via MCP Protocol]

Seven Rust crates, one MCP server binary, one CLI binary:

CrateRole
rpg-coreGraph types (RPGraph, Entity, HierarchyNode), storage, LCA algorithm
rpg-parserTree-sitter entity + dependency extraction (15 languages)
rpg-encoderEncoding pipeline, lifting utilities, incremental evolution
rpg-navSearch, fetch, explore, snapshot, TOON serialization
rpg-liftAutonomous LLM lifting (Anthropic, OpenAI, OpenRouter, Gemini)
rpg-cliCLI binary (rpg-encoder)
rpg-mcpMCP server binary (rpg-mcp-server) with 27 tools

MCP Tools (27)

Build & Maintain (4 tools)
ToolDescription
build_rpgIndex the codebase (run once, instant)
update_rpgIncremental update from git changes
reload_rpgReload graph from disk after external changes
rpg_infoGraph statistics, hierarchy overview, per-area lifting coverage
Navigate & Search (5 tools)
ToolDescription
semantic_snapshotWhole-repo semantic understanding in one call (~25K tokens for 1000 entities)
search_nodeSearch entities by intent or keywords (hybrid embedding + lexical scoring)
fetch_nodeGet entity metadata, source code, dependencies, and hierarchy context
explore_rpgTraverse dependency graph (upstream, downstream, or both)
context_packSingle-call search + fetch + explore with token budget
Plan & Analyze (7 tools)
ToolDescription
impact_radiusBFS reachability analysis — "what depends on X?"
plan_changeChange planning — find relevant entities, modification order, blast radius
find_pathsK-shortest dependency paths between two entities
slice_betweenExtract minimal connecting subgraph between entities
analyze_healthCode health: coupling, instability, god objects, clone detection
detect_cyclesFind circular dependencies and architectural cycles
reconstruct_planDependency-safe reconstruction execution plan
Semantic Lifting (11 tools)
ToolDescription
auto_liftOne-call autonomous lifting via cheap LLM API (Haiku, GPT-4o-mini, OpenRouter, Gemini)
lifting_statusDashboard — coverage, per-area progress, NEXT STEP
get_entities_for_liftingGet entity source code for your agent to analyze
submit_lift_resultsSubmit the agent's semantic features back to the graph
finalize_liftingAggregate file-level features, rebuild hierarchy metadata
get_files_for_synthesisGet file-level entity features for holistic synthesis
submit_file_synthesesSubmit holistic file-level summaries
build_semantic_hierarchyGet domain discovery + hierarchy assignment prompts
submit_hierarchyApply hierarchy assignments to the graph
get_routing_candidatesGet entities needing semantic routing (drifted or newly lifted)
submit_routing_decisionsSubmit routing decisions (hierarchy path or "keep")

Supported Languages

15 languages via Tree-sitter:

LanguageEntity ExtractionDependency Resolution
PythonFunctions, classes, methodsimports, calls, inheritance
RustFunctions, structs, traits, impl methodsuse, calls, trait impls
TypeScriptFunctions, classes, methods, interfacesimports, calls, inheritance
JavaScriptFunctions, classes, methodsimports, calls, inheritance
GoFunctions, structs, methods, interfacesimports, calls
JavaClasses, methods, interfacesimports, calls, inheritance
C / C++Functions, classes, methods, structsincludes, calls, inheritance
C#Classes, methods, interfacesusing, calls, inheritance
PHPFunctions, classes, methodsuse, calls, inheritance
RubyClasses, methods, modulesrequire, calls, inheritance
KotlinFunctions, classes, methodsimports, calls, inheritance
SwiftFunctions, classes, structs, protocolsimports, calls, inheritance
ScalaFunctions, classes, objects, traitsimports, calls, inheritance
BashFunctionssource, calls

Install

MCP server (recommended)

bash
# Claude Codeclaude mcp add rpg -- npx -y -p rpg-encoder rpg-mcp-server
# Cursor — add to ~/.cursor/mcp.json{  "mcpServers": {    "rpg": {      "command": "npx",      "args": ["-y", "-p", "rpg-encoder", "rpg-mcp-server"]    }  }}

The server auto-detects the project root from the current working directory — no path argument needed.

CLI
bash
npm install -g rpg-encoder
# Build a graphrpg-encoder build
# Queryrpg-encoder search "parse entities from source code"rpg-encoder fetch "src/parser.rs:extract_entities"rpg-encoder explore "src/parser.rs:extract_entities" --direction both --depth 2rpg-encoder info
# Autonomous lifting via APIrpg-encoder lift --provider anthropic --dry-run  # estimate costrpg-encoder lift --provider anthropic           # lift with Haiku (~$0.02/100 entities)
# Incremental updaterpg-encoder update
# Pre-commit hook (auto-updates graph on commit)rpg-encoder hook install
Build from source
bash
git clone https://github.com/userFRM/rpg-encoder.gitcd rpg-encoder && cargo build --release

Then point your MCP config at target/release/rpg-mcp-server.


Documentation

  • How RPG Compares — honest comparison with GitNexus, Serena, Repomix, and others
  • Paper Fidelity — algorithm-by-algorithm comparison with the research paper
  • Use Cases — practical examples of what RPG enables
  • CHANGELOG — release history

Inspirations & References

rpg-encoder is built on the theoretical framework from the RPG-Encoder research paper, with original extensions inspired by tools across the code intelligence landscape:

  • RPG-Encoder paper (Luo et al., 2026, Microsoft Research) — semantic lifting model, 3-level hierarchy construction, incremental evolution algorithms, formal graph model G = (V_H ∪ V_L, E_dep ∪ E_feature).
  • GitNexus — precomputed relational intelligence, blast radius analysis, Claude Code hooks. Showed that a code graph tool must be invisible to be essential.
  • Serena — symbol-level precision via LSP. Demonstrated that real-time code awareness matters more than batch analysis.
  • TOON — Token-Oriented Object Notation for LLM-optimized output.

This is an independent implementation. All code is original work under the MIT license. Not affiliated with or endorsed by Microsoft.


License

MIT

來源:README.md,提交 26b24ee

工具

0
SourceWeft 尚未在沙箱中啟動過該軟體包,因此其工具未知。

版本歷史

1
  1. v0.6.7最新Sep 16, 2026

評分

已滿足適用檢查項的 50%

該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。

  • 近 30 天內可連通25 分

    請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。

  • 已宣告認證方式10 分

    請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。

  • 已列出工具15 分

    請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。

  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分