Skip to main content
Glama
chelslava

ContextTree MCP

by chelslava

ContextTree MCP 🌳

AIアシスタント向けのディープセマンティックコード検索 — AST解析とローカル埋め込みにより実現。100%オフライン。

Python License: MIT MCP README (RU)

ContextTree MCPは、AIコーディングアシスタントにコードベースの構造的理解を提供するローカルなModel Context Protocolサーバーです。2つの世界を組み合わせます:

  • tree-sitterがソースコードをASTに解析し、論理ブロック(関数、メソッド、docstring付きのクラス署名)を抽出します。

  • sentence-transformers(all-MiniLM-L6-v2)は、ファイルパス・クラス名・メソッド名・docstringを付与した各ブロックを、ローカルなChromaDBベクターストアに埋め込みます。

その結果、アシスタントはキーワードではなく意味によってコードを見つけることができ、すべての検索結果が正確なファイルパスと行番号付きで返ってきます。

🔒 プライバシー最優先。 すべてがあなたのマシン上で動作します:解析、埋め込みモデル、ベクターインデックス。クラウドへの送信も、テレメトリも、コードがディスクを離れることも一切ありません。


なぜプレーンテキスト検索では不十分なのか

grepや全文検索は文字列に一致します。それらが失敗するのは、開発者が最も支援を必要とする場面そのものです:

タスク

テキスト検索

ContextTree MCP

"Where do we validate JWT tokens?" の検索

❌ 正確なキーワードの推測が必要

✅ コード内に「validate」が登場しなくてもAuthService.verify_token()がヒット

リファクタリングで名前が変わったメソッドを見つける

❌ リネームで壊れる

✅ docstringと周囲のコンテキストが意味を保持

定義と使用箇所を区別する

❌ 正規表現なしでは不可能

✅ 宣言と呼ばれ箇所をASTレベルで分離

正確な位置を返す

⚠️ 一致した行のみ

✅ file、class、method、start_line、end_lineというメタデータ

コメント・文字列・インポートなどのノイズを無視できる

❌

✅ 実際の論理ユニットのみをインデックス

Related MCP server: Paparats MCP

機能

  • 🌲 AST対応チャンキング分割 — 任意のテキストウィンドウではなく、tree-sitterにより関数・メソッド・クラス署名をインデックス化します。

  • 🧩 拡張された論理ブロック — インデックスされる各ドキュメントには、ファイルパス、所属クラス、メソッド名、docstring、本文が埋め込まれるため、「payment retry logic」 のような検索が正しいメソッドに届きます。

  • ⚡ インクリメンタルインデックス — ファイルごとのSHA-256コンテンツハッシュにより、変更・新規・削除されたファイルのみが再処理されます。

  • 🔍 セマンティック検索 — 自然言語のクエリから、正確な行範囲付きのランク付けされたコードフラグメントを取得します。

  • 📞 ASTの使用箇所検索 — 関数/クラスの実際の呼び出し箇所を検索し、文字列リテラルやコメントによる誤検出を除外します。

  • 🗄️ 永続的なローカルインデックス — ChromaDBが.chroma/に保存され、再起動後も存続、Gitにはコミットされません。

  • 🔌 Stdio MCPトランスポート — Claude Desktop、OpenCode、Cursor、Cline、その他のMCP互換クライアントに接続します。

技術スタック

レイヤー

技術

言語

Python 3.12+

プロトコル

公式mcp SDK(stdioトランスポート)

AST解析

tree-sitter + Python、TypeScript、JavaScriptのバインディング

ベクターデータベース

chromadb(ローカル永続モード)

埋め込み

sentence-transformers · all-MiniLM-L6-v2

インストール

Python 3.12以上が必要です。高速でモダンなパッケージマネージャとしてuvを推奨します:

git clone https://github.com/<your-org>/mcp-context-tree.git
cd mcp-context-tree

# Option A — uv (recommended): resolves dependencies from pyproject.toml, locks uv.lock
uv sync

# Option B — classic pip + venv
python -m venv venv && source venv/bin/activate   # Windows: venv\Scripts\activate
pip install -r requirements.txt

💡 初回実行時に、埋め込みモデル(約90MB)がダウンロードされます。PyTorchははsentence-transformersの依存パッケージとしてインストールされます。CPU版で十分です、GPUは不要です。

MCPクライアントへの登録

設定例(Claude Desktop / stdioサーバーに対応したクライアント):

{
  "mcpServers": {
    "context-tree": {
      "command": "<path-to-venv>/bin/python",
      "args": ["-m", "context_tree"],
      "env": {}
    }
  }
}

(Windowsの場合是\Scripts\python.exe`を指定します。)

アシスタントに公開されるツール

ツール

シグネチャ

説明

index_workspace

(directory_path: str)

プロジェクトを走査し、ハッシュで変更されたファイルを検出、ChromaDBコレクションを増分更新します。

semantic_search

(query: str, limit: int = 5)

インデックス化されたコードを対象に自然言語検索。file、class、start_line、end_lineを含むリッチなスニペットを返します。

find_ast_usages

(symbol_name: str)

ASTに基づき、関数/クラスの実際の呼び出し箇所・インスタンス生成を検索します。

一般的な利用の流れ:

1. index_workspace("D:/projects/my-app")
2. semantic_search("where do we handle payment retries", limit=8)
3. find_ast_usages("PaymentGateway.retry")

対応言語

言語

対応状況

Python

✅ ローンチ時点で対応

TypeScript / TSX

✅ ローンチ時点で対応

JavaScript / JSX

✅ ローンチ時点で対応

Go、Java、Rust…

🗺 ロードリップ — パーサーレジストリは拡張しやすい設計です

ドキュメント

  • 分数ط ARCHITECTURE.md — プロジェクト構成、ChromaDBのデータスキーマ、AST抽出ロジック、インクリメンタルインデックスの設計。

  • ❓ README.ru.md — ロシア語のドキュメント。

ロードマップ

  • Watchモード — ファイル変更を検知して自動再インデックス(fsウォッチャー)

  • tree-sitterバインディングによる言語対応の拡大

  • ハイブリッド検索(BM25 + ベクトルの再ランク付け)

  • コールグラフを考慮したランキング(「誰がこれを呼んでいるか?」)

  • PyPIリリース(context-tree-mcp)

コントリビューション

IssueやPRを歓迎します。変更はARCHITECTURE.mdとの整合性を保ってください。

ライセンス

MIT — 詳細はLICENSEを参照してください。

Available Tools

4 tools
find_ast_usagesA

AST-based lookup of real call sites / instantiations of a function or class. Filters out string literals, comments, and non-call occurrences.

ParametersJSON Schema
NameRequiredDescriptionDefault
limitNo
symbol_nameYes
directory_pathNo.

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A3.6/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations supplied, the description carries the full behavioral burden. It does disclose a valuable filtering behavior: "Filters out string literals, comments, and non-call occurrences." However, it does not mention whether indexing is required, how missing symbols are handled, or any result behavior beyond being AST-based.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single focused sentence that communicates the mechanism, target resource, and exclusion behavior without redundancy. Every clause adds useful information.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The tool is simple enough that the core lookup behavior is adequately described, and an output schema exists. The main gaps are the lack of usage guidance around semantic_search/index_workspace and the absence of practical details about scoping and limit behavior, which leaves the description merely adequate rather than complete.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema has 0% description coverage, so the description should compensate. It adds meaning for symbol_name by stating it refers to "a function or class," but it gives no guidance on directory_path or limit, such as how the directory is searched or what the limit controls. This leaves non-obvious semantics undocumented.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description uses a specific verb plus precise resource: "AST-based lookup of real call sites / instantiations of a function or class." It also clarifies what is excluded, which distinguishes it from string or semantic search. This is far more informative than the bare tool name.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The AST-based wording implicitly indicates this is for exact code-structure matching rather than fuzzy search, and the sibling tools suggest a semantic-search alternative. However, the description does not explicitly state when to use this tool versus semantic_search or index_workspace, nor does it mention any exclusions or preconditions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

go_to_definitionA

Finds the exact definition/declaration location of a symbol (function, method, class, struct, trait, interface) across workspace files.

ParametersJSON Schema
NameRequiredDescriptionDefault
limitNo
symbol_nameYes
directory_pathNo.

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A3.5/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It adds meaningful context by stating the search is workspace-wide and targets exact definition/declaration locations. Still, it leaves important behavioral details undisclosed, such as whether an index must exist first, how missing or ambiguous symbols are handled, and whether the operation is purely read-only.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, front-loaded sentence with no filler or redundant restatement of the tool name. It conveys the core action, target, and scope efficiently while listing relevant symbol categories without over-elaborating.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Although an output schema exists and the basic action is clear, the description lacks usage guidance relative to its three sibling tools and fails to explain two of three parameters. With no annotations, this is too thin to fully support an agent in choosing and invoking the tool correctly across realistic scenarios.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate for bare parameter schemas. It partially clarifies symbol_name by listing supported symbol types, but it says nothing about the format of symbol_name (e.g., fully qualified vs simple name, case sensitivity). The limit and directory_path parameters are completely unaddressed in the description, leaving their semantics to inference from the schema titles and defaults.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description uses a specific verb ('Finds') with a precise resource: the exact definition/declaration location of symbols, listing supported symbol categories and clarifying the search scope ('across workspace files'). This clearly distinguishes it from sibling tools like find_ast_usages or semantic_search, which target usages or semantically similar matches rather than exact definitions.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The phrasing 'exact definition/declaration location' implies the tool is appropriate when precise definitions are needed, rather than usages or semantic matches. However, it does not explicitly state when to prefer this tool over semantic_search or find_ast_usages, nor does it mention any exclusions or prerequisites such as requiring an indexed workspace.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

index_workspaceA

Walks the project, detects changed files by SHA-256 hash, and incrementally updates the persistent local ChromaDB vector store.

ParametersJSON Schema
NameRequiredDescriptionDefault
directory_pathNo.

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A3.9/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It covers that the operation walks the project, uses SHA-256 hashing for change detection, and mutates a persistent local ChromaDB store. This is meaningful behavioral context beyond 'index workspace' though it does not mention potential costs, permissions, or failure modes.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

A single sentence with no filler. It front-loads the core action and packs in the hashing, incrementality, and storage target without becoming verbose.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a tool with one optional parameter and an output schema, the description covers the essential behavior: what is walked, how changes are detected, and what is updated. It is reasonably complete, though it could add an explicit note about running after source changes or before semantic_search.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

There is only one parameter and schema description coverage is 0%, so the description needs to clarify the parameter's meaning. It never mentions directory_path or the default of '.', forcing the agent to rely on the schema's 'Directory Path' title and default value. The description does not compensate for the low schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description names a specific action sequence ('Walks the project', 'detects changed files', 'updates the vector store') and a concrete resource ('persistent local ChromaDB vector store'). It is clearly distinct from the sibling tools semantic_search and find_ast_usages, which do search and AST lookup rather than indexing.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The phrase 'incrementally updates' and 'detects changed files' implies the tool is meant to keep the index fresh after edits, but the description never explicitly says when to run it relative to semantic_search or find_ast_usages. It also does not mention exclusions or alternatives.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 2 tool updatesv0.4.0
    • Addedgo_to_definition
    • Changedsemantic_search2 fields changed
      • addedInput schema / properties / mode
        Added value: +{
        +  "default": "hybrid",
        +  "enum": [
        +    "hybrid",
        +    "semantic",
        +    "keyword"
        +  ],
        +  "title": "Mode",
        +  "type": "string"
        +}
      • addedInput schema / properties / rerank
        Added value: +{
        +  "default": false,
        +  "title": "Rerank",
        +  "type": "boolean"
        +}
  2. 3 tool updatesv0.1.0
    • First observedfind_ast_usages
    • First observedindex_workspace
    • First observedsemantic_search

TDQS

A3.9/5.0

Scored across 4 tools

Disambiguation5/5

Each tool targets a distinct part of code navigation: semantic search vs. exact definitions vs. AST usages vs. index maintenance. There is no realistic confusion between their purposes.

Naming Consistency4/5

Three of four tools use imperative verb-first names (find_ast_usages, index_workspace, go_to_definition), and all are snake_case. semantic_search breaks the pattern slightly by starting with an adjective instead of a verb, but the naming remains readable and predictable.

Tool Count5/5

With 4 tools, the server is well-scoped and each tool earns its place in the code indexing/search/navigation workflow. There is no redundancy or bloat.

Completeness4/5

The core lifecycle is covered: index the workspace, search semantically, go to definitions, and find AST usages. Minor gaps such as no explicit index status or reset operation prevent a perfect score, but agents can work around them.

Maintenance

ActivitySlowing
ResponsivenessResponsive

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables semantic code search for AI assistants by indexing codebases with embeddings and Tree-sitter, returning relevant snippets via natural language queries.
    15
    MIT
  • A
    license
    Not graded
    quality
    B
    maintenance
    Provides AI coding assistants with deep, semantic understanding of local codebases via AST-aware chunking, cross-repo symbol graphs, and architectural memory, enabling context-aware code search and dependency tracing.
    11
    MIT
  • A
    license
    A
    quality
    D
    maintenance
    Enables AI assistants to perform intelligent semantic code search across codebases using local AI embeddings for meaning-based retrieval.
    6
    35 npm
    MIT