Skip to main content
Glama

MCP駆動型Agentic RAGシステム

Model Context Protocol (MCP) を使用して、LLMをベクトルデータベースやドキュメントローダーなどの外部ツールに接続する、ローカルでモジュール化されたRAG(検索拡張生成)システムです。

概要

本プロジェクトは、以下の機能を持つAgentic RAGシステムを実装しています:

  • 取得 (Retrieves): ローカルのベクトルデータベース (ChromaDB) から関連ドキュメントを取得

  • 拡張 (Augments): 取得したコンテキストでプロンプトを拡張

  • 生成 (Generates): ローカルLLM (Ollama) を使用して情報に基づいた回答を生成

  • 公開 (Exposes): FastAPIによるREST API経由で機能を提供

Related MCP server: MCP RAG with ChromaDB

技術スタック

コンポーネント

ツール/ライブラリ

詳細

言語モデル

Ollama

ローカルLLM推論 (mistral, llama3など)

エージェントフレームワーク

mcp + FastAPI

ツール登録機能付きAPIサーバー

RAGパイプライン

LangChain + Custom

コンテキスト取得およびプロンプトエンジニアリング

ベクトルストア

ChromaDB

ローカル永続ベクトルデータベース

埋め込み

SentenceTransformers

all-MiniLM-L6-v2モデル

ファイル処理

pypdf, python-docx

PDFおよびドキュメントの読み込み

フロントエンド (オプション)

Streamlit

インタラクティブなWeb UI

環境

Python 3.10+

virtualenv または Conda

プロジェクト構造

agentic-rag-mcp/
├── main.py                    # FastAPI MCP server
├── rag_agent.py              # Agent query logic and RAG orchestration
├── mcp_config.yaml           # Configuration file
├── requirements.txt          # Python dependencies
├── vector_store/             # Persisted ChromaDB vector store
├── data/
│   └── sample_docs/          # Sample documents for ingestion
└── tools/
    └── chromadb_tool.py      # Vector search tool implementation

インストールとセットアップ

1. クローンと仮想環境の作成

cd agentic-rag-mcp
python -m venv .venv

# On Windows
.venv\Scripts\activate

# On macOS/Linux
source .venv/bin/activate

2. 依存関係のインストール

pip install -U pip
pip install -r requirements.txt

3. Ollamaのセットアップ

公式サイトから Ollama をダウンロードしてインストールします。

Ollamaサーバーを起動します:

# On the system terminal (not in virtual environment)
ollama serve

別のターミナルで、モデルをプルします:

ollama pull mistral    # Recommended for RAG
# or
ollama pull llama3

サーバーが実行中であることを確認します:

curl http://localhost:11434/api/tags

システムの実行

オプション1: チャットインターフェース (インタラクティブ)

インタラクティブなチャットループを実行します:

python rag_agent.py

これにより、以下の処理が行われます:

  1. サンプルドキュメントをベクトルストアに読み込む

  2. 質問ができるインタラクティブなチャットを開始する

  3. エージェントが関連ドキュメントを取得し、回答を生成する

対話例:

You: What is MCP?
Agent: The Model Context Protocol (MCP) enables modular tool use for AI agents by providing a standardized way to connect language models to external services...

[Used 2 retrieved documents as context]

オプション2: APIサーバー

FastAPI MCPサーバーを起動します:

python main.py

サーバーは http://localhost:8000 で利用可能になります。

APIエンドポイント

ヘルスチェック

GET /health

クエリエージェント

POST /query
Content-Type: application/json

{
  "query": "What is artificial intelligence?",
  "use_context": true,
  "n_results": 3
}

ドキュメント検索

POST /search
Content-Type: application/json

{
  "query": "MCP protocol",
  "n_results": 5
}

ドキュメント追加

POST /documents
Content-Type: application/json

{
  "documents": [
    "Document text 1",
    "Document text 2"
  ],
  "ids": ["doc1", "doc2"],
  "metadata": [
    {"source": "file1.txt"},
    {"source": "file2.txt"}
  ]
}

統計取得

GET /stats

Pythonの使用例

from rag_agent import RAGAgent

# Initialize agent
agent = RAGAgent(
    ollama_url="http://localhost:11434",
    model="mistral"
)

# Get a response
result = agent.get_response("What is RAG?")
print(result["response"])
print(f"Retrieved {len(result['retrieved_documents'])} documents")

設定

mcp_config.yaml を編集してカスタマイズします:

  • LLM設定: モデル、温度、最大トークン数

  • ベクトルストア: 埋め込みモデル、コレクション名

  • RAG: 取得するドキュメント数、類似度メトリック

  • サーバー: ホスト、ポート、ログレベル

  • セキュリティ: APIレート制限、認証

カスタムドキュメントの追加

プログラムによる追加

from tools.chromadb_tool import ChromaTool

tool = ChromaTool()
documents = [
    "Your document text 1",
    "Your document text 2"
]
tool.add_documents(documents, ids=["id1", "id2"])

API経由での追加

curl -X POST http://localhost:8000/documents \
  -H "Content-Type: application/json" \
  -d '{
    "documents": ["Document 1", "Document 2"],
    "ids": ["doc1", "doc2"]
  }'

オプションのStreamlitフロントエンド

streamlit_app.py を作成します:

import streamlit as st
import requests

st.set_page_config(page_title="RAG Agent", layout="wide")
st.title("MCP-Powered Agentic RAG")

query = st.text_input("Ask a question:")

if query:
    response = requests.post(
        "http://localhost:8000/query",
        json={"query": query}
    )
    result = response.json()
    
    st.subheader("Response")
    st.write(result["response"])
    
    st.subheader("Retrieved Context")
    for i, doc in enumerate(result["retrieved_documents"], 1):
        st.write(f"**Doc {i}**: {doc[:200]}...")

Streamlitを実行します:

streamlit run streamlit_app.py

拡張機能と今後の課題

  • ✅ ChromaDBによる基本的なRAG

  • ⬜ Web検索ツール統合

  • ⬜ PDFドキュメント取り込みUI

  • ⬜ エージェントメモリ(会話履歴)

  • ⬜ マルチモーダルサポート(画像、テーブル)

  • ⬜ ドメイン固有データでのファインチューニング

  • ⬜ 構造化出力(JSONスキーマ)

  • ⬜ リアルタイムストリーミング応答

トラブルシューティング

Ollamaの「Connection refused」エラー

  • Ollamaサーバーが実行中であることを確認してください: ollama serve

  • アクセス可能か確認してください: curl http://localhost:11434/api/tags

ChromaDBの埋め込みエラー

  • sentence-transformersがインストールされていることを確認してください: pip install sentence-transformers

  • 初回実行時に埋め込みモデル(約30MB)がダウンロードされます

ベクトルストアが永続化されない

  • ./vector_store/ ディレクトリが存在し、書き込み可能であることを確認してください

  • 設定内の persist_dir が実際のパスと一致していることを確認してください

ライセンス

MITライセンス - 詳細はLICENSEファイルを参照してください

コントリビューション

コントリビューションを歓迎します!以下の手順で行ってください:

  1. リポジトリをフォークする

  2. フィーチャーブランチを作成する

  3. 変更をコミットする

  4. プッシュしてプルリクエストを作成する

参考文献

A
license - permissive license
Not graded
quality - not tested
C
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • F
    license
    Not graded
    quality
    D
    maintenance
    A FastAPI-based application that enables document embedding and semantic retrieval using Qdrant vector database, allowing users to convert documents into embeddings and retrieve relevant content through natural language queries.
  • A
    license
    Not graded
    quality
    D
    maintenance
    Provides retrieval-augmented generation (RAG) capabilities by ingesting various document formats into a persistent ChromaDB vector store. It enables semantic search and retrieval using either OpenAI or Ollama embeddings for processing local files, directories, and URLs.
    1
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    Provides token-efficient semantic search and document retrieval by indexing PDFs, text, and markdown files into local notebooks using ChromaDB. It enables AI agents to query relevant passages from large documents through local embedding models like Hugging Face or Ollama.
    1
    MIT
  • F
    license
    Not graded
    quality
    D
    maintenance
    A fully offline local RAG server that utilizes ChromaDB and Ollama to index and query PDF, text, and Markdown documents. It allows users to manage local knowledge bases and perform semantic searches with AI-generated responses.

View all related MCP servers

Related MCP Connectors

  • Persistent semantic memory for AI agents: store and recall text by meaning (RAG). x402

  • Persistent memory and knowledge management for AI agents with semantic search and 50+ tools.

  • Long-term memory for AI assistants. Hybrid retrieval, query expansion, auto-topics.

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/EimanTahir027/MCP-powered-Agentic-RAG'

If you have feedback or need assistance with the MCP directory API, please join our Discord server