MCP RAG 服务器 logo

MCP RAG 服务器

Community
karaage0703

MCP RAG Serverは、Model Context Protocol (MCP)に準拠したRAG(Retrieval-Augmented…

Publisherkaraage0703
Repositorymcp-rag-server
LanguagePython
Forks
18
Stars
71
Available tools
0
Transport typestdio
Categories
LicenseMIT
Links
  • Connect tools to AI workflows

    MCP RAG 服务器 exposes MCP capabilities that can be used by compatible AI clients and agents.

  • 0 available tools

    Browse the callable actions below, including names and descriptions when provided by the server.

  • Ready-to-copy setup

    Use the installation snippets to configure this server in your preferred MCP client.

  • Open source signals

    71 stars and 18 forks from the linked repository.

MCP RAG Server

MCP RAG Serverは、Model Context Protocol (MCP)に準拠したRAG(Retrieval-Augmented Generation)機能を持つPythonサーバーです。マークダウン、テキスト、パワーポイント、PDFなど複数の形式のドキュメントをデータソースとして、multilingual-e5-largeモデルを使用してインデックス化し、ベクトル検索によって関連情報を取得する機能を提供します。

概要

このプロジェクトは、MCPサーバーの基本的な実装に加えて、RAG機能を提供します。複数形式のドキュメントをインデックス化し、自然言語クエリに基づいて関連情報を検索することができます。

機能

  • MCPサーバーの基本実装

    • JSON-RPC over stdioベースで動作
    • ツールの登録と実行のためのメカニズム
    • エラーハンドリングとロギング
  • RAG機能

    • 複数形式のドキュメント(マークダウン、テキスト、パワーポイント、PDF)の読み込みと解析
    • 階層構造を持つソースディレクトリに対応
    • markitdownライブラリを使用したパワーポイントやPDFからのマークダウン変換
    • 選択可能なエンベディングモデル(multilingual-e5-large、ruriなど)を使用したエンベディング生成
    • PostgreSQLのpgvectorを使用したベクトルデータベース
    • ベクトル検索による関連情報の取得
    • 前後のチャンク取得機能(コンテキストの連続性を確保)
    • ドキュメント全文取得機能(完全なコンテキストを提供)
    • 差分インデックス化機能(新規・変更ファイルのみを処理)
  • ツール

    • ベクトル検索ツール(MCP)
    • ドキュメント数取得ツール(MCP)
    • インデックス管理ツール(CLI)

前提条件

  • Python 3.10以上
  • PostgreSQL 14以上(pgvectorエクステンション付き)

インストール

依存関係のインストール

bash
# uvがインストールされていない場合は先にインストール
# pip install uv

# 依存関係のインストール
uv sync

PostgreSQLとpgvectorのセットアップ

Dockerを使用する場合

bash
# pgvectorを含むPostgreSQLコンテナを起動
docker run --name postgres-pgvector -e POSTGRES_PASSWORD=password -p 5432:5432 -d pgvector/pgvector:pg17

データベースの作成

PostgreSQLコンテナを起動した後、以下のコマンドでデータベースを作成します:

bash
# ragdbデータベースの作成
docker exec -it postgres-pgvector psql -U postgres -c "CREATE DATABASE ragdb;"

既存のPostgreSQLにpgvectorをインストールする場合

sql
-- pgvectorエクステンションをインストール
CREATE EXTENSION vector;

環境変数の設定

.envファイルを作成し、以下の環境変数を設定します:

# PostgreSQL接続情報
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
POSTGRES_USER=postgres
POSTGRES_PASSWORD=password
POSTGRES_DB=ragdb

# ドキュメントディレクトリ
SOURCE_DIR=./data/source
PROCESSED_DIR=./data/processed

# エンベディングモデル設定
EMBEDDING_MODEL=intfloat/multilingual-e5-large
EMBEDDING_DIM=1024
EMBEDDING_PREFIX_QUERY="query: "
EMBEDDING_PREFIX_EMBEDDING="passage: "

エンベディングモデルの設定

このサーバーでは、環境変数でエンベディングモデルを選択できます。

サポートされているモデル

multilingual-e5-large(デフォルト)

env
EMBEDDING_MODEL=intfloat/multilingual-e5-large
EMBEDDING_DIM=1024
EMBEDDING_PREFIX_QUERY="query: "
EMBEDDING_PREFIX_EMBEDDING="passage: "

cl-nagoya/ruri-v3-30m

env
EMBEDDING_MODEL=cl-nagoya/ruri-v3-30m
EMBEDDING_DIM=256
EMBEDDING_PREFIX_QUERY="検索クエリ: "
EMBEDDING_PREFIX_EMBEDDING="検索文書: "

プレフィックスについて

多くのエンベディングモデル(特にE5系)では、テキストの種類に応じてプレフィックスを付けることで性能が向上します:

  • 検索クエリ用: EMBEDDING_PREFIX_QUERY - ユーザーの検索クエリに自動で追加
  • 文書用: EMBEDDING_PREFIX_EMBEDDING - インデックス化される文書に自動で追加

プレフィックスは自動で処理されるため、MCPクライアントは意識する必要がありません。

モデル変更時の注意

エンベディングモデルを変更した場合は、ベクトル次元が変わる可能性があるため、既存のインデックスをクリアして再作成してください:

bash
python -m src.cli clear
python -m src.cli index

使い方

MCPサーバーの起動

uvを使用する場合(推奨)

bash
uv run python -m src.main

オプションを指定する場合:

bash
uv run python -m src.main --name "my-rag-server" --version "1.0.0" --description "My RAG Server"

通常のPythonを使用する場合

bash
python -m src.main

コマンドラインツール(CLI)の使用方法

インデックスのクリアとインデックス化を行うためのコマンドラインツールが用意されています。

ヘルプの表示

bash
python -m src.cli --help

インデックスのクリア

bash
python -m src.cli clear

ドキュメントのインデックス化

bash
# デフォルト設定でインデックス化(./data/source ディレクトリ)
python -m src.cli index

# 特定のディレクトリをインデックス化
python -m src.cli index --directory ./path/to/documents

# チャンクサイズとオーバーラップを指定してインデックス化
python -m src.cli index --directory ./data/source --chunk-size 300 --chunk-overlap 50
# または短い形式で
python -m src.cli index -d ./data/source -s 300 -o 50

# 差分インデックス化(新規・変更ファイルのみを処理)
python -m src.cli index --incremental
# または短い形式で
python -m src.cli index -i

インデックス内のドキュメント数の取得

bash
python -m src.cli count

MCPホストでの設定

MCPホスト(Claude Desktop、Cline、Cursorなど)でこのサーバーを使用するには、以下のような設定を行います。設定するjsonファイルについては、各MCPホストの ドキュメントを参照してください。

設定例

json
{
  "mcpServers": {
    "mcp-rag-server": {
      "command": "uv",
      "args": [
        "run",
        "--directory",
        "/path/to/mcp-rag-server",
        "python",
        "-m",
        "src.main"
      ]
    }
  }
}

設定のポイント

  • command: uv(推奨)またはpython
  • args: 実行引数の配列
  • /path/to/mcp-rag-server: このリポジトリの実際のパスに置き換えてください

uvを使用しない場合

uvがインストールされていない環境では、通常のPythonを使用できます:

json
{
  "command": "python",
  "args": [
    "-m",
    "src.main"
  ],
  "cwd": "/path/to/mcp-rag-server"
}

RAGツールの使用方法

search

ベクトル検索を行います。

json
{
  "jsonrpc": "2.0",
  "method": "search",
  "params": {
    "query": "Pythonのジェネレータとは何ですか?",
    "limit": 5,
    "with_context": true,
    "context_size": 1,
    "full_document": false
  },
  "id": 1
}

パラメータの説明

  • query: 検索クエリ(必須)
  • limit: 返す結果の数(デフォルト: 5)
  • with_context: 前後のチャンクも取得するかどうか(デフォルト: true)
  • context_size: 前後に取得するチャンク数(デフォルト: 1)
  • full_document: ドキュメント全体を取得するかどうか(デフォルト: false)

検索結果の改善

このツールは以下の機能により、より良い検索結果を提供します:

  1. 前後のチャンク取得機能:

    • 検索でヒットしたチャンクの前後のチャンクも取得して結果に含めます
    • with_contextパラメータで有効/無効を切り替え可能
    • context_sizeパラメータで前後に取得するチャンク数を調整可能
  2. ドキュメント全文取得機能:

    • 検索でヒットしたドキュメントの全文を取得して結果に含めます
    • full_documentパラメータで有効/無効を切り替え可能
    • 特に短いドキュメントや全体の文脈が重要なドキュメントを扱う場合に有用
  3. 結果の整形改善:

    • 検索結果をファイルごとにグループ化
    • 「検索ヒット」「前後のコンテキスト」「ドキュメント全文」を視覚的に区別
    • チャンクインデックスでソートして文書の流れを維持

get_document_count

インデックス内のドキュメント数を取得します。

json
{
  "jsonrpc": "2.0",
  "method": "get_document_count",
  "params": {},
  "id": 2
}

使用例

  1. ドキュメントファイルを data/source ディレクトリに配置します。サポートされるファイル形式は以下の通りです:

    • マークダウン(.md, .markdown)
    • テキスト(.txt)
    • パワーポイント(.ppt, .pptx)
    • Word(.doc, .docx)
    • PDF(.pdf)
  2. CLIコマンドを使用してドキュメントをインデックス化します:

    bash
    # 初回は全件インデックス化
    python -m src.cli index
    
    # 以降は差分インデックス化で効率的に更新
    python -m src.cli index -i
  3. MCPサーバーを起動します:

    bash
    uv run python -m src.main
  4. searchツールを使用して検索を行います。

バックアップと復元

インデックス化したデータベースを別のPCで使用するには、以下の手順でバックアップと復元を行います。

最小限のバックアップ(PostgreSQLデータベースのみ)

単純に他のPCでRAG検索機能を使いたいだけなら、PostgreSQLデータベースのバックアップだけで十分です。ベクトル化されたデータはすべてデータベースに保存されているためです。

PostgreSQLデータベースのバックアップ

PostgreSQLデータベースをバックアップするには、Dockerコンテナ内でpg_dumpコマンドを使用します:

bash
# Dockerコンテナ内でデータベースをバックアップ
docker exec -it postgres-pgvector pg_dump -U postgres -d ragdb -F c -f /tmp/ragdb_backup.dump

# バックアップファイルをコンテナからホストにコピー
docker cp postgres-pgvector:/tmp/ragdb_backup.dump ./ragdb_backup.dump

これにより、PostgreSQLデータベースのバックアップファイル(例:239MB)がカレントディレクトリに作成されます。

最小限の復元手順

  1. 新しいPCでPostgreSQLとpgvectorをセットアップします:
bash
# Dockerを使用する場合
docker run --name postgres-pgvector -e POSTGRES_PASSWORD=password -p 5432:5432 -d pgvector/pgvector:pg17

# データベースを作成
docker exec -it postgres-pgvector psql -U postgres -c "CREATE DATABASE ragdb;"
  1. バックアップからデータベースを復元します:
bash
# バックアップファイルをコンテナにコピー
docker cp ./ragdb_backup.dump postgres-pgvector:/tmp/ragdb_backup.dump

# コンテナ内でデータベースを復元
docker exec -it postgres-pgvector pg_restore -U postgres -d ragdb -c /tmp/ragdb_backup.dump
  1. 環境設定を確認します:

新しいPCでは、.envファイルのPostgreSQL接続情報が正しく設定されていることを確認してください。

  1. 動作確認:
bash
python -m src.cli count

これにより、インデックス内のドキュメント数が表示されます。元のPCと同じ数が表示されれば、正常に復元されています。

完全バックアップ(オプション)

将来的に新しいドキュメントを追加する予定がある場合や、差分インデックス化機能を使用したい場合は、以下の追加バックアップも行うと良いでしょう:

処理済みドキュメントのバックアップ

処理済みドキュメントディレクトリをバックアップします:

bash
# 処理済みドキュメントディレクトリをZIPファイルにバックアップ
zip -r processed_data_backup.zip data/processed/

環境設定ファイルのバックアップ

.envファイルをバックアップします:

bash
# .envファイルをコピー
cp .env env_backup.txt

完全復元手順

  1. 前提条件

新しいPCには以下のソフトウェアがインストールされている必要があります:

  • Python 3.10以上
  • PostgreSQL 14以上(pgvectorエクステンション付き)
  • mcp-rag-serverのコードベース
  1. PostgreSQLデータベースを上記の「最小限の復元手順」で復元します。

  2. 処理済みドキュメントを復元します:

bash
# ZIPファイルを展開
unzip processed_data_backup.zip -d /path/to/mcp-rag-server/
  1. 環境設定ファイルを復元します:
bash
# .envファイルを復元
cp env_backup.txt /path/to/mcp-rag-server/.env

必要に応じて、新しいPC環境に合わせて.envファイルの設定(特にPostgreSQL接続情報)を編集します。

  1. 動作確認:
bash
python -m src.cli count

注意点

  • PostgreSQLのバージョンとpgvectorのバージョンは、元のPCと新しいPCで互換性がある必要があります。
  • 大量のデータがある場合は、バックアップと復元に時間がかかる場合があります。
  • 新しいPCでは、必要なPythonパッケージ(sentence-transformers、psycopg2-binaryなど)をインストールしておく必要があります。

ディレクトリ構造

mcp-rag-server/
├── data/
│   ├── source/        # 原稿ファイル(階層構造対応)
│   │   ├── markdown/  # マークダウンファイル
│   │   ├── docs/      # ドキュメントファイル
│   │   └── slides/    # プレゼンテーションファイル
│   └── processed/     # 処理済みファイル(テキスト抽出済み)
│       └── file_registry.json  # 処理済みファイルの情報(差分インデックス用)
├── docs/
│   └── design.md      # 設計書
├── logs/              # ログファイル
├── src/
│   ├── __init__.py
│   ├── document_processor.py  # ドキュメント処理モジュール
│   ├── embedding_generator.py # エンベディング生成モジュール
│   ├── example_tool.py        # サンプルツールモジュール
│   ├── main.py                # メインエントリーポイント
│   ├── mcp_server.py          # MCPサーバーモジュール
│   ├── rag_service.py         # RAGサービスモジュール
│   ├── rag_tools.py           # RAGツールモジュール
│   └── vector_database.py     # ベクトルデータベースモジュール
├── tests/
│   ├── __init__.py
│   ├── conftest.py
│   ├── test_document_processor.py
│   ├── test_embedding_generator.py
│   ├── test_example_tool.py
│   ├── test_mcp_server.py
│   ├── test_rag_service.py
│   ├── test_rag_tools.py
│   └── test_vector_database.py
├── .env           # 環境変数設定ファイル
├── .gitignore
├── LICENSE
├── pyproject.toml
└── README.md

ライセンス

このプロジェクトはMITライセンスの下で公開されています。詳細はLICENSEファイルを参照してください。

Installation

TypingMind
Prerequisites:

Node.js 18+

{
  "mcpServers": {
    "karaage0703-mcp-rag-server": {
      "command": "",
      "args": []
    }
  }
}

Use MCP RAG 服务器 MCP with multiple AI models

TypingMind connects MCP tools at the workspace level, so once MCP RAG 服务器 is connected, you can use it with different AI models in TypingMind instead of setting it up separately for each model. This MCP runs locally through the TypingMind MCP connector on your device.

Setup guide to use the local connector

Use this when the MCP server needs access to local files, apps, or private resources on your computer.

1

Open the MCP settings

In TypingMind, go to Settings, Advanced Settings, then Model Context Protocol and choose Setup Connector.

  1. Open TypingMind in your browser.
  2. Click the Settings icon.
  3. Go to Advanced Settings.
  4. Open the Model Context Protocol section.
  5. Click Setup Connector and choose This Device.
TypingMind MCP connector setup screen with This Device selected
2

Run the connector command

Choose This Device, copy the command from TypingMind, and run it in Terminal. Keep the process running while you use MCP.

  1. Copy the setup command shown by TypingMind.
  2. Open Terminal on macOS or Windows Terminal on Windows.
  3. Paste and run the command.
  4. Approve the package install if Terminal asks you to proceed.
  5. Keep the Terminal window running while using MCP tools.
3

Add MCP RAG 服务器 as a server

When the connector status is Ready, click Edit Servers and paste the MCP server configuration.

  1. Wait until the connector status shows Ready.
  2. Click Edit Servers.
  3. Paste the MCP RAG 服务器 MCP server configuration.
  4. Save the server list.
  5. Refresh if you want to confirm the connector is still ready.
TypingMind MCP settings showing active server and Edit Servers button
{
  "mcpServers": {
    "karaage0703-mcp-rag-server": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-rag-server"
      ]
    }
  }
}
4

Use it across models

Save the server list, open Plugins, enable the MCP RAG 服务器 MCP tools, then select any supported AI model in TypingMind and use the tools in chat or assign them to an AI agent.

  1. Open the Plugins page in TypingMind.
  2. Enable the MCP RAG 服务器 MCP tools.
  3. Start a chat and choose the AI model you want to use.
  4. Use the MCP tools in chat or assign them to an AI agent.
  5. Switch to another AI model whenever needed without reconnecting MCP.
TypingMind chat using enabled MCP tools with a selected AI model
Can you use MCP RAG 服务器 to help me with this task?
MCP RAG 服务器
Sure. I read it.
Here is what I found using MCP RAG 服务器.

Frequently asked questions

What is the MCP RAG 服务器 MCP server used for?

MCP RAG 服务器 is an MCP server that lets compatible AI clients connect to external tools and context. In TypingMind, you can add this MCP server once and make its tools available in your AI workspace.

Can I use MCP RAG 服务器 MCP with multiple AI models in TypingMind?

Yes. TypingMind connects MCP tools at the workspace level, so you can use MCP RAG 服务器 with different AI models such as Claude, ChatGPT, Gemini, or other models you have configured in TypingMind without setting up the MCP server separately for each model.

Why use MCP RAG 服务器 MCP with TypingMind?

TypingMind is one of the best frontends for LLM chat because it brings multiple AI models, prompts, plugins, AI agents, API keys, and MCP tools into one workspace. With MCP RAG 服务器 connected, you can use its MCP tools across your preferred models while keeping your chat workflow organized in TypingMind.

How do I connect MCP RAG 服务器 MCP to TypingMind?

MCP RAG 服务器 runs through the TypingMind local MCP connector. This is best when the MCP server needs access to local files, desktop apps, command-line tools, or private resources on your computer.

What tools does MCP RAG 服务器 MCP provide in TypingMind?

MCP RAG 服务器 exposes MCP capabilities that can be enabled from the TypingMind Plugins page and used in chat or assigned to AI agents.

Do I need to share my API keys with TypingMind to use MCP RAG 服务器 MCP?

No. TypingMind is local-first and lets you keep your model providers, API keys, prompts, and MCP configuration under your control. If MCP RAG 服务器 requires authentication, add the required headers, OAuth settings, or local configuration for that MCP server when you create the connection.

Related MCP Servers

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇