MCP Local RAG
AIエージェントが、自分のPDF、Word、Markdown、テキストのファイルを、埋め込みAPIに送らずに、ローカルで検索できるようにします。
429 GitHubのスター作者 shinprライセンス MIT更新 19 日前
導入方法
このMCPはローカル型です。あなたのパソコンで動きます。
パソコンに入れたアプリ(Claude Desktop、Claude Code、Cursor、VS Codeなど)で使えます。アプリを選んでください:
ターミナルに貼り付け:
claude mcp add local-rag -- npx -y mcp-local-rag
入力するもの
| 名前 | 内容 | 必須 |
|---|---|---|
BASE_DIR | Base directory for document storage (defaults to current working directory). Ignored when BASE_DIRS is set. | いいえ |
BASE_DIRS | JSON array of base directories (e.g. '["/a","/b"]'). Takes precedence over BASE_DIR. | いいえ |
IGNORE_PATHS | JSON array of glob patterns for files to keep out of the index, each matched against the file's path relative to its root (e.g. '["plugs/**","**/*.draft.md"]'). | いいえ |
DB_PATH | Path to LanceDB database directory (defaults to ./lancedb/) | いいえ |
CACHE_DIR | Directory where Transformers.js models are cached (defaults to ./models/) | いいえ |
HF_ENDPOINT | Hugging Face model download endpoint. Set this to a mirror URL when direct downloads are blocked (defaults to https://huggingface.co). | いいえ |
MODEL_NAME | Embedding model name (defaults to Xenova/all-MiniLM-L6-v2) | いいえ |
MAX_FILE_SIZE | Maximum file size in bytes (defaults to 104857600 / 100MB) | いいえ |
RAG_MAX_DISTANCE | Maximum distance threshold for filtering search results. Results with distance greater than this value will be excluded. Lower values mean stricter filtering (e.g., 0.5 for high relevance only) | いいえ |
RAG_GROUPING | Grouping mode for quality filtering. 'similar' returns only the most similar group (stops at first distance jump). 'related' includes related groups (stops at second distance jump). Unset means no grouping filter | いいえ |
RAG_MAX_FILES | Maximum number of files to keep in search results. Results are filtered to include only chunks from the top N best-scoring files. For example, 1 returns only the single best-matching file's chunks. Unset means no file filtering. | いいえ |
CHUNK_MIN_LENGTH | Minimum chunk length in characters (1-10000, defaults to 50). Chunks shorter than this threshold are filtered out during ingestion. | いいえ |
STORE_IMAGES | Store supported PDF and DOCX images during ingestion and return them with matched chunks (defaults to false). | いいえ |
EMBED_TITLE_PREFIX | Embed each chunk together with its document title, which can help when passages don't restate the topic the title names (defaults to false). After changing it, use a new DB_PATH or delete the index and re-ingest. | いいえ |
EMBED_HEADING_PREFIX | Add section headings to chunk embeddings when they fit (defaults to false). Independent of EMBED_TITLE_PREFIX. Re-ingest documents after changing it. | いいえ |
RAG_DEVICE | Execution device for the embedder (defaults to cpu). Passed straight to ONNX Runtime; see the Transformers.js device source for the supported backend names. If the requested device fails to initialize, the server throws an error. | いいえ |
RAG_DTYPE | Embedding quantization dtype for the embedder (defaults to fp32). Opt-in and pass-through; accepts any dtype the chosen model provides (fp32, fp16, q8, int8, ...). If the model has no variant for the requested dtype, the server throws an error. Changing this changes the embedding space — re-ingest existing data. | いいえ |
RAG_HYBRID_WEIGHT | Keyword boost factor for hybrid search (0.0-1.0, defaults to 0.6). 0 means semantic similarity only; higher values increase the keyword-match contribution to the final score. | いいえ |
RAG_RERANK_CMD | External reranker command template. Use {query} and {top} for query text and result count; unset disables reranking. | いいえ |
RAG_RERANK_TIMEOUT_MS | Time budget per rerank call in milliseconds (100-600000, defaults to 10000). On timeout the spawned command is killed and the pre-rerank ordering is returned. | いいえ |
準備完了!試してみましょう
アプリを再起動して、次のどれかをチャットに貼ってください:
設定されたフォルダーのすべての文書を同期して、終わったら教えてください。
APIのドキュメントは、認証について何と書いていますか?
概要
このサーバーは、お使いのパソコン上で文書にインデックスを作り、意味と完全一致のキーワードの両方で検索します。結果には、元の一節と、可能な場合は見出し、行番号、ページ番号が含まれます。モデルを最初にダウンロードした後は、インデックスの作成と検索はオフラインで動きます。
できること
sync_start: インデックスを、お使いのフォルダーと同じ最新の状態にしますsync_status: 実行中の同期を確認しますingest_file: 1つのファイルを追加または置き換えますingest_data: クライアントが持つテキスト、Markdown、HTMLを追加しますquery_documents: 意味とキーワードの一致で検索しますread_chunk_neighbors: 結果の前後のテキストを読みますlist_files: ファイルと、そのインデックスの状態を表示しますdelete_file: インデックス化されたファイルを削除します
使う場面
- ›プライベートな文書のフォルダーについて、質問したいとき
- ›エラーコードやAPI名などの完全一致と、意味による検索の両方が必要なとき
- ›ページや行の参照付きで、出典を確認できる回答が欲しいとき
必要なもの
相性のいいスキル
MCPかスキルか
MCPはエージェントに手を与え、スキルはその正しい使い方を教えます。組み合わせると、結果が良くなりトークンも節約できます。
google-cloud-solution-rag-enterprise-search-gke-sqldbAlloyDB のベクトル、オープンモデル、GKE を使い、社内文書への質問に答える非公開のエンタープライズ検索システムを設計します。xerj-knowledgeエージェントが、ローカルのドキュメント、メモ、PDF、表計算、メールを検索し、各回答の出典であるファイルとページを示せるよう支援します。doc-reader1つのツールで、PDF、WordやExcelのファイル、PowerPointのスライド、画像などの多くの種類の文書から、読めるテキストを取り出せるようエージェントを支援します。よくある質問
データはクラウドに送られますか?
いいえ。埋め込みのAPIは使わず、モデルをダウンロードした後はオフラインで動きます。
どのファイルに対応していますか?
PDF、DOCX、TXT、Markdown、そしてクライアントが渡すHTMLまたはテキストです。Excel、PowerPoint、画像、ソースコードのファイルは対応していません。
APIキーは必要ですか?
いいえ。APIキー、Docker、Python、外部のデータベースは不要です。
コマンドラインはありますか?
はい。npx mcp-local-rag ingest、query、sync、list、status、deleteを使えます。
ファイルへのアクセスはどのように制限されていますか?
BASE_DIRがファイル操作のセキュリティの境界で、MCPのファイルパスは絶対パスで、設定されたルートの中になければなりません。
モデルを変えられますか?
はい。MODEL_NAMEで変更できます。モデルを変えたら、新しいDB_PATHで新しいインデックスを作ってください。
うまく動かないとき
- ›プロジェクトごとにインデックスが作られないように、BASE_DIR、DB_PATH、CACHE_DIRを絶対パスに設定してください。
- ›最初の同期には、モデルのダウンロードのため1〜2分かかることがあります。
- ›Hugging Faceのダウンロードがブロックされている場合は、HF_ENDPOINTにミラーのURLを設定してください。
毎週5つの新しいスキル。1分で読めます。