Skip to main content
Glama

MCP-gestütztes agentisches RAG-System

Ein lokales, modulares Retrieval-Augmented Generation (RAG)-System, das das Model Context Protocol (MCP) verwendet, um ein LLM mit externen Tools wie Vektordatenbanken und Dokumenten-Loadern zu verbinden.

Überblick

Dieses Projekt implementiert ein agentisches RAG-System, das:

  • Relevante Dokumente aus einer lokalen Vektordatenbank (ChromaDB) abruft

  • Prompts mit dem abgerufenen Kontext anreichert

  • Informierte Antworten mithilfe eines lokalen LLM (Ollama) generiert

  • Funktionalitäten über eine REST-API mit FastAPI bereitstellt

Related MCP server: MCP RAG with ChromaDB

Tech-Stack

Komponente

Tool/Bibliothek

Details

Sprachmodell

Ollama

Lokale LLM-Inferenz (mistral, llama3, etc.)

Agent-Framework

mcp + FastAPI

API-Server mit Tool-Registrierung

RAG-Pipeline

LangChain + Custom

Kontextabruf und Prompt-Engineering

Vektorspeicher

ChromaDB

Lokale, persistente Vektordatenbank

Embeddings

SentenceTransformers

all-MiniLM-L6-v2 Modell

Dateiverarbeitung

pypdf, python-docx

PDF- und Dokumenten-Laden

Frontend (Optional)

Streamlit

Interaktive Web-UI

Umgebung

Python 3.10+

virtualenv oder Conda

Projektstruktur

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

Installation & Einrichtung

1. Klonen und virtuelle Umgebung erstellen

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

# On Windows
.venv\Scripts\activate

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

2. Abhängigkeiten installieren

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

3. Ollama einrichten

Laden Sie Ollama von der offiziellen Website herunter und installieren Sie es.

Starten Sie den Ollama-Server:

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

Ziehen Sie in einem anderen Terminal ein Modell:

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

Überprüfen Sie, ob der Server läuft:

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

Ausführen des Systems

Option 1: Chat-Schnittstelle (Interaktiv)

Führen Sie die interaktive Chat-Schleife aus:

python rag_agent.py

Dies wird:

  1. Beispieldokumente in den Vektorspeicher laden

  2. Einen interaktiven Chat starten, in dem Sie Fragen stellen können

  3. Der Agent wird relevante Dokumente abrufen und Antworten generieren

Beispielinteraktion:

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]

Option 2: API-Server

Starten Sie den FastAPI-MCP-Server:

python main.py

Der Server ist verfügbar unter: http://localhost:8000

API-Endpunkte

Gesundheitsprüfung

GET /health

Agent abfragen

POST /query
Content-Type: application/json

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

Dokumente durchsuchen

POST /search
Content-Type: application/json

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

Dokumente hinzufügen

POST /documents
Content-Type: application/json

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

Statistiken abrufen

GET /stats

Python-Anwendungsbeispiele

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")

Konfiguration

Bearbeiten Sie mcp_config.yaml, um Folgendes anzupassen:

  • LLM-Einstellungen: Modell, Temperatur, maximale Token

  • Vektorspeicher: Embedding-Modell, Sammlungsname

  • RAG: Anzahl der abgerufenen Dokumente, Ähnlichkeitsmetrik

  • Server: Host, Port, Log-Level

  • Sicherheit: API-Ratenbegrenzungen, Authentifizierung

Hinzufügen eigener Dokumente

Programmatisch

from tools.chromadb_tool import ChromaTool

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

Über API

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

Optionales Streamlit-Frontend

Erstellen Sie 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]}...")

Führen Sie Streamlit aus:

streamlit run streamlit_app.py

Erweiterungen & zukünftige Arbeiten

  • ✅ Basis-RAG mit ChromaDB

  • ⬜ Integration von Websuch-Tools

  • ⬜ UI für den PDF-Dokumenten-Import

  • ⬜ Agenten-Gedächtnis (Konversationsverlauf)

  • ⬜ Multimodale Unterstützung (Bilder, Tabellen)

  • ⬜ Feinabstimmung auf domänenspezifische Daten

  • ⬜ Strukturierte Ausgabe (JSON-Schemas)

  • ⬜ Echtzeit-Streaming-Antworten

Fehlerbehebung

"Connection refused" für Ollama

  • Stellen Sie sicher, dass der Ollama-Server läuft: ollama serve

  • Überprüfen Sie die Erreichbarkeit: curl http://localhost:11434/api/tags

ChromaDB-Embedding-Fehler

  • Stellen Sie sicher, dass sentence-transformers installiert ist: pip install sentence-transformers

  • Beim ersten Ausführen wird das Embedding-Modell heruntergeladen (~30MB)

Vektorspeicher wird nicht persistent gespeichert

  • Überprüfen Sie, ob das Verzeichnis ./vector_store/ existiert und beschreibbar ist

  • Stellen Sie sicher, dass persist_dir in der Konfiguration mit dem tatsächlichen Pfad übereinstimmt

Lizenz

MIT-Lizenz - Siehe LICENSE-Datei für Details

Mitwirken

Beiträge sind willkommen! Bitte:

  1. Forken Sie das Repository

  2. Erstellen Sie einen Feature-Branch

  3. Committen Sie Änderungen

  4. Pushen Sie und öffnen Sie einen Pull Request

Referenzen

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