MCPunk
MCPunk 🤖
LLM ツールを使用してコードをインテリジェントに検索することで、埋め込みなしでコードベースとチャットできます。
MCPunk は、会話を通してコードベースを探索し、理解することを可能にします。その仕組みは以下のとおりです。
ファイルを論理的なチャンク(関数、クラス、マークダウンセクション)に分割する
LLMにこれらのチャンクを検索およびクエリするツールを提供する
LLMが質問に答えるために必要な特定のコードを見つけられるようにする
埋め込みや複雑な設定は一切不要。明確で監査可能な検索機能で、操作も分かりやすく、ガイドも簡単です。Claude Desktop やその他のMCPクライアントと連携して動作します。
以下の点を念頭に置いて構築
コンテキストが重要です- LLM は優れたものになり得ますが、適切なコンテキストが提供された場合のみです。
コンテキストは貴重です- LLMはコンテキストを必要としますが、多すぎると処理できません。これは悲劇です!MCPunkは、LLMにコンテキストヒントを提供することでLLMが関連コンテンツのみに絞り込むことを可能にするRAGです。
人間が関与- LLM が検討したデータとそのデータをどのように見つけたかを正確に確認できます。チャットに参加し、好きなように指示することができます。
設定
これらは Claude Desktop に関する手順ですが、MCPunk は MCP が使用されている場所であればどこでも使用できます。
以下のスニペットを
claude_desktop_config.jsonに挿入します( 場所を含むclaude_desktop_config.jsonの詳細)Claude Desktopを再起動すると、下のスクリーンショットのように、少し遅れて利用可能なツールが表示されます。
チャットで: 「ねえ、~/git/mcpunk プロジェクトを設定して、Python ファイルがどのようにチャンク化されるか教えてくれませんか」
( "command": "uvx",機能しない可能性があり、例えば"command": "/Users/michael/.local/bin/uvx",を使用する必要があるかもしれません)
{
"mcpServers": {
"MCPunk": {
"command": "uvx",
"args": ["mcpunk"]
}
}
}
使用例
コードベースに関する質問に答える
**[ユーザー]**ちょっと、~/git/mcpunk リポジトリを設定してくれませんか。それから、mcpunk のユーザーが、mcpunk で設定したリポジトリ内の現在チェックアウトされているブランチの git diff を取得する方法を教えてください。
[クロード]
configure_projectを呼び出す[クロード]
list_all_files_in_projectを呼び出す[クロード]
find_files_by_chunk_contentを呼び出す[クロード] ... MCPunk で合計 21 回のツール呼び出しを行います。
[クロード] mcpunk の git diff 機能の仕組みが分かりました。現在チェックアウトされているブランチの git diff を取得する方法をまとめます。mcpunk が設定されたリポジトリで、現在チェックアウトされているブランチの git diff を取得するには、以下の手順を実行します。
まず、ユーザーはconfigure_projectツールを使用して、プロジェクトで動作するようにmcpunkを設定する必要があります。
最近チェックアウトされたブランチを確認する(何と比較するかを識別するため)
次に、現在のブランチ(HEAD)と参照ブランチの差分を取得します。これにより、現在のブランチ(HEAD)と指定した参照ブランチの差分が表示されます。refパラメータには、比較対象となるベースブランチの名前(「main」や「develop」など)を指定します。
**[ユーザー]**素晴らしい仕事だよ!
PRレビュー
**[ユーザー]**ねえ、~/git/mcpunk リポジトリを設定して、現在のブランチと
scratch/1.5比較してもらえませんか?[Claude] ~/git/mcpunk をセットアップし、
scratch/1.5のdiff_with_refを呼び出します。**[Claude]**いくつかの変更が加えられ、主に新しいテスト ファイル
tests/test_git_analysis.pyが追加されました...**[ユーザー]**これはコードベースの残りの部分にどのように適合するのでしょうか?
**[クロード]**チャンクごとにファイルをリストし、チャンクをリストし、チャンクの詳細を取得するための 5 つのツール呼び出しを実行します。
**[クロード]**なるほど。このコードはgit reflogの出力を解析して、最近チェックアウトされたブランチを追跡しているんですね。メイン関数のget_recent_branchesはリポジトリパスを受け取り、チェックアウトされた最後のN個のブランチを返します。その際に、_branches_from_reflogをヘルパーとして使い、生のreflog出力を解析しています。
**[ユーザー]**もし急いでいて、誰かにこの作品をレビューするよう指示しなければならない場合、何を見るように指示しますか? 作業内容の概要を具体的に教えてください。
[クロード]
_branches_from_reflog の
split("to ")[-1]脆弱に見えるテスト データには単純なブランチ名のみが表示されますが、スペースや特殊文字はどうなりますか?
example_reflog は実際の git reflog 出力を表していますか?
実際の git の動作に対してテストしていますか?
**[ユーザー]**君は最高だよ!
複数のコードベースで作業する
LLMに複数のプロジェクトを設定するよう指示するだけで、LLMはそれらのプロジェクト間を自由にクエリできます。あるプロジェクトが別のプロジェクトに依存していて、それらが異なるリポジトリにある場合に便利です。この場合、LLMはインポートを通じてこれを認識するはずです。
MCPunkとその他の背景とは
MCPunkは、ツールを提供するMCPサーバーです。
プロジェクト(ファイルのディレクトリ)を設定します。設定すると、ファイルは論理的なチャンクに分割されます。MCPunkはコード用に構築されていますが、実際にはあらゆるドキュメント、さらには必要に応じて画像にも適用できます。
プロジェクト内の特定のテキストを含むファイルを検索する
特定のテキストを含むファイル内のチャンクを検索する
特定のチャンクの完全な内容を表示する
これに加えて、いくつかのチャンカーが組み込まれています。最も成熟しているのは Python チャンカーです。
MCPunkは会話に使う必要はありません。例えば、CIパイプラインのコードレビューの一部として使うこともできます。まさに汎用的なRAGです。
sequenceDiagram
participant User
participant Claude as Claude Desktop
participant MCPunk as MCPunk Server
participant Files as File System
Note over User,Files: Setup Phase
User->>Claude: Ask question about codebase
Claude->>MCPunk: configure_project(root_path, project_name)
MCPunk->>Files: Scan files in root directory
Note over MCPunk,Files: Chunking Process
MCPunk->>MCPunk: For each file, apply appropriate chunker:
MCPunk->>MCPunk: - PythonChunker: functions, classes, imports
MCPunk->>MCPunk: - MarkdownChunker: sections by headings
MCPunk->>MCPunk: - VueChunker: template/script/style sections
MCPunk->>MCPunk: - WholeFileChunker: fallback
MCPunk->>MCPunk: Split chunks >10K chars into parts
MCPunk-->>Claude: Project configured with N files
Note over User,Files: Navigation Phase<br>(LLM freely uses all these tools repeatedly to drill in)
Claude->>MCPunk: list_all_files_in_project(project_name)
MCPunk-->>Claude: File tree structure
Claude->>MCPunk: find_files_by_chunk_content(project_name, "search term")
MCPunk-->>Claude: Files containing matching chunks
Claude->>MCPunk: find_matching_chunks_in_file(project_name, file_path, "search term")
MCPunk-->>Claude: List of matching chunk IDs in file
Claude->>MCPunk: chunk_details(chunk_id)
MCPunk-->>Claude: Full content of specific chunk
Claude->>User: Answer based on relevant code chunks
Note over User,Files: Optional Git Analysis
Claude->>MCPunk: list_most_recently_checked_out_branches(project_name)
MCPunk->>Files: Parse git reflog
MCPunk-->>Claude: List of recent branches
Claude->>MCPunk: diff_with_ref(project_name, "main")
MCPunk->>Files: Generate git diff
MCPunk-->>Claude: Diff between HEAD and referenceローミングRAGクラッシュコース
見る
ローミングRAGの要点は
コンテンツ(コードベース、PDFファイルなど)を「チャンク」に分割します。各チャンクは、関数、マークダウンドキュメントのセクション、コードファイル内のすべてのインポートなど、論理的に「小さな」項目です。
チャンクを検索するためのLLMツールを提供します。MCPunkは、特定のテキストを含むチャンクを含むファイルを検索し、特定のチャンクの完全な内容を一覧表示するツールを提供することでこれを実現します。
従来の「ベクトル検索」RAG と比較すると、次のようになります。
LLM はチャンクを見つけるためにドリルダウンする必要があり、当然ながらチャンクのより広いコンテキスト(どのファイルにあるかなど)を認識しています。
チャンクは常に一貫性を保たなければなりません。完全な関数のように。
LLM が何を検索しているかを正確に把握でき、検索がうまくいかない場合はそれが一般的に明らかであり、改善された検索用語を提案することで LLM を支援できます。
正確な検索一致が必要です。MCPunk はあいまい検索を一切提供していません。
チャンク
チャンクとはファイルのサブセクションです。例えば、
単一のPython関数
マークダウンセクション
Pythonファイルからのすべてのインポート
チャンクはチャンカーによってファイルから作成され、MCPunk にはいくつかのチャンクが組み込まれています。
MCPunkでプロジェクトがセットアップされると、すべてのファイルを調べ、最初に適用可能なチャンカーを適用します。LLMはツールを使用して、(1) 特定のテキストを含むチャンクを含むファイルのクエリ、(2) 特定のファイル内のすべてのチャンクのクエリ、(3) チャンクの完全な内容の取得を行うことができます。
この基本的な基盤により、claude は、関連するファイルの広範な検索から始めて関連する領域を絞り込むことで、比較的大規模なコードベースを効果的にナビゲートできるようになります。
組み込みチャンカー:
PythonChunker、クラス、関数、ファイルレベルのインポート、ファイルレベルのステートメント(例:グローバル)に分割します.pyで終わるファイルに適用できます。VueChunker、「テンプレート」、「スクリプト」、「スタイル」、あるいはトップレベルの<blah>....</blah>項目に分割します.vueで終わるファイルに適用可能です。MarkdownChunker、見出しごとにMarkdownセクションに分割します.mdで終わるファイルに適用できます。WholeFileChunker、ファイル全体を単一のチャンクとして作成するフォールバックチャンカーです。任意のファイルに適用できます。
10,000 文字を超えるチャンク (設定可能) は、自動的に複数のチャンクに分割され、名前にpart1 、 part2などの接尾辞が付きます。これにより、コンテキストが無視されることを防ぎながら、チャンクの適切なナビゲーションが可能になります。
カスタムチャンカー
ファイルの種類(例:PythonとC)ごとにカスタムチャンカーが必要です。MCPunkには組み込みのチャンカーが付属しています。特定のチャンカーがファイルに一致しない場合は、ファイル全体を1つのチャンクにまとめるデフォルトのチャンカーが使用されます。
現在推奨されているチャンク追加方法は、このプロジェクトをフォークしてチャンクを追加し、開発ごとにMCPunkを実行することです。チャンカーを追加するには
BaseChunkerから継承して、 file_chunkers.pyに追加します。file_breakdown.pyの
ALL_CHUNKERSに追加します。
pytest のプラグイン システムのように、MCPunk が使用できるカスタム チャンカーがあることをモジュールに通知するための何らかのプラグイン システムを実装することは可能ですが、現在これを実装する予定はありません (誰かがそれをやりたい場合を除く)。
制限事項
LLMは検索が苦手な場合があります。例えば、「dependency」を検索すると「dependencies」という用語が見つかりません。検索語を絞り込む余地があります。
LLM は、重要なコードの特定の部分を見つけようとしますが、見つけられず、コンテキスト認識が限られていることを認識せずに続行することがあります。
「大規模」プロジェクトは十分にテストされていません。約1000個のPythonファイルと合計約25万行のコードで構成されるプロジェクトは問題なく動作します。プロジェクトのセットアップには約5秒かかります。コードベースのサイズが大きくなるにつれて、初期のチャンク化にかかる時間が増加し、より高度な検索が必要になる可能性があります。コードは一般的に大規模なコードベースを想定して記述されていません。すべてのデータがメモリに保存され、すべてのデータを反復処理して検索が行われるなど、基本的な最適化が求められる様々な点が見られます。
小規模なプロジェクトでは、すべてのコードを連結してコンテキストに組み込む方がおそらく効果的です。MCPunkは、それが現実的でない場合にのみ適しています。
場合によっては、LLMがチャンクを一つずつ取り出すよりも、ファイル全体を取得できるようにした方が明らかに良いでしょう。MCPunkにはそのための仕組みがありません。実際には、これが大きな問題になることはありませんでした。
構成
MCPUNK_で始まる環境変数を使って、様々な設定を行うことができます。利用可能なオプションについては、 settings.py を参照してください。これらのオプションは、 Pydantic Settingsを介して環境変数から読み込まれます。
たとえば、 include_chars_in_responseオプションを構成するには、次のようにします。
{
"mcpServers": {
"MCPunk": {
"command": "uvx",
"args": ["mcpunk"],
"env": {
"MCPUNK_INCLUDE_CHARS_IN_RESPONSE": "false"
}
}
}
}ロードマップと開発状況
MCPunkはほぼ機能が完成していると考えられています。まだ広く利用されていないため、ユーザーとしてバグや粗い部分に遭遇する可能性があります。バグ報告はhttps://github.com/jurasofish/mcpunk/issuesまで歓迎いたします。
ロードマップのアイデア
MCPunkの使い方をサポートするプロンプトをいくつか追加してください。「エイリアンにパンケーキの作り方を説明する」といった類のプロンプトがないと、少し物足りなく感じます。
Python モジュール レベルのステートメントを抽出するときに、モジュール レベルのコメントを含めます。
検索のための語幹処理の可能性あり
「プロジェクト」の概念全体を変更して、ファイルが実際に存在する必要がないようにします。これにより、プロジェクト内で「仮想」ファイルが許可されるようになります。
ファイルのパスをURIに変更することを検討してください。たとえば
file://.../http[s]:///gitdiff:/// などの任意のURIです。
Gitの差分をチャンク化します。現在、差分全体を取得するツールがありますが、これは非常に大きくなる可能性があります。代わりに、このツールを
add_diff_to_projectに変更し、gitdiff://URIまたは何らかの偽のパスの下にファイルを配置することができます。プロジェクトのキャッシュ。MCPクライアントを再起動するたびにすべてのファイルを再解析する必要がなくなります。チャンカー内のコードを変更するとキャッシュが無効になるため、これは難しいかもしれません。私のユースケースではそれほど遅くないので、優先順位は高くないかもしれません。
ユーザーがチャンクを実行するためのカスタムコードを提供できる機能(おそらくpytestプラグインに似ている)
ツリーシッターのようなものは、より一般的なチャンカーとして使用できる可能性があります
理想的にはチャットで送受信された文字を追跡します。
チャットによる状態、ログなど
発達
claude デスクトップを以下のように設定すると、リポジトリのローカル バージョンから MCPunk を操作するときに、再起動して最新の変更を確認できます。
{
"mcpServers": {
"MCPunk": {
"command": "/Users/michael/.local/bin/uvx",
"args": [
"--from",
"/Users/michael/git/mcpunk",
"--no-cache",
"mcpunk"
]
}
}
}テスト、リンティング、CI
Makefileと github アクションのワークフローを参照してください。
Available Tools
8 toolschunk_detailsA
Get full content of a specific chunk.
Returns chunk content as string.
Common patterns:
1. Final step after find_matching_chunks_in_file finds relevant chunks
2. Examining implementations after finding definitions/uses
Inputs: chunk_id (required).
configure_projectA
Configure a new project containing files.
Each file in the project is split into 'chunks' - logical sections like functions,
classes, markdown sections, and import blocks.
After configuring, a common workflow is:
1. list_all_files_in_project to get an overview of the project (with
an initial limit on the depth of the search)
2. Find files by function/class definition:
find_files_by_chunk_content(... ["def my_funk"])
3. Find files by function/class usage:
find_files_by_chunk_content(... ["my_funk"])
4. Determine which chunks in the found files are relevant:
find_matching_chunks_in_file(...)
5. Get details about the chunks:
chunk_details(...)
Use ~ (tilde) literally if the user specifies it in paths.
Inputs: root_path (required), project_name (required).
diff_with_refA
Return a summary of the diff between HEAD and the given ref.
You probably want the ref to be the 'base' branch like develop or main, off which PRs are made - and you can likely determine this by viewing the most recently checked out branches.
Inputs: project_name (required), ref (required).
find_files_by_chunk_contentA
Step 1: Find files containing chunks with matching text.
Returns file tree only showing which files contain matches.
You must use find_matching_chunks_in_file on each relevant file
to see the actual matches.
Example workflow:
1. Find files:
files = find_files_by_chunk_content(project, ["MyClass"])
2. For each file, find actual matches:
matches = find_matching_chunks_in_file(file, ["MyClass"])
3. Get content:
content = chunk_details(file, match_id)
Inputs: project_name (required), chunk_contents_filter (required).
find_matching_chunks_in_fileA
Step 2: Find the actual matching chunks in a specific file.
Required after find_files_by_chunk_content or list_all_files_in_project to see
matches, as those tools only show files, not their contents.
This can be used for things like:
- Finding all chunks in a file that make reference to a specific function
(e.g. find_matching_chunks_in_file(..., ["my_funk"])
- Finding a chunk where a specific function is defined
(e.g. find_matching_chunks_in_file(..., ["def my_funk"])
Some chunks are split into multiple parts, because they are too large. This
will look like 'chunkx_part1', 'chunkx_part2', ...
Inputs: project_name (required), rel_path (required), filter_ (required).
get_a_jokeD
Get a really funny joke! For testing :)
Inputs: animal (required).
list_all_files_in_projectA
List all files in a project, returning a file tree.
This is useful for getting an overview of the project, or specific subdirectories of the project.
A project may have many files, so you are suggested to start with a depth limit to get an overview, and then continue increasing the depth limit with a filter to look at specific subdirectories.
Inputs: project_name (required), path_filter, limit_depth_from_root.
list_most_recently_checked_out_branchesB
List the n most recently checked out branches in the project
Inputs: project_name (required), n.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 8 tools
Each tool has a clearly distinct purpose: project configuration, file listing, content search, chunk details, diff, branch listing, and a joke tool. No overlapping functionalities.
All tools use a consistent snake_case naming pattern with descriptive verb_noun structure (e.g., `list_all_files_in_project`, `configure_project`). No mixing of conventions.
8 tools is well-scoped for a code analysis server. Each tool serves a necessary role in the typical workflow, and there are no redundant or missing core tools.
Covers the main analysis workflow: configure, list files, search, get details, diff, and branch info. However, lacks modification tools (e.g., update/delete project or chunks), which is a minor gap for a full lifecycle.
Maintenance
Related MCP Connectors
Code intelligence for LLMs. Analyze, search, and retrieve code from any public git repository.
Ask how your codebase works. Hosted codebase intelligence for repos indexed on repowise.dev.
Shared memory for coding agents. Stop re-explaining your codebase every session.
Code intelligence for coding agents: semantic, AST, graph, and full-text search. 279+ languages.
Related MCP Servers
- AlicenseNot gradedqualityFmaintenanceProvides AI-powered code intelligence for any codebase using local LLMs and vector search, enabling semantic code search, pattern analysis, and context-optimized code generation with 90% token savings.2MIT
- AlicenseNot gradedqualityDmaintenanceAdds semantic code search to AI coding agents, enabling natural language queries across entire codebases to retrieve relevant code chunks, saving tokens and providing deep context.22 npm1MIT
- AlicenseNot gradedqualityFmaintenanceEnables local-first codebase intelligence, allowing chat, search, and audit operations on any repository with file:line citations, and supports offline deterministic modes without an LLM.15 npm2MIT
- AlicenseAqualityBmaintenanceEnables semantic and keyword search over a local codebase by chunking source files along function and class boundaries, embedding them offline, and fusing vector and BM25 results. Runs entirely on your machine in a single SQLite file, so AI coding agents can find relevant code with no API keys, telemetry, or cloud calls.714 npmMIT