Agentic RAG MCP Server
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 implementationInstallation & 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/activate2. Abhängigkeiten installieren
pip install -U pip
pip install -r requirements.txt3. 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 serveZiehen 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/tagsAusführen des Systems
Option 1: Chat-Schnittstelle (Interaktiv)
Führen Sie die interaktive Chat-Schleife aus:
python rag_agent.pyDies wird:
Beispieldokumente in den Vektorspeicher laden
Einen interaktiven Chat starten, in dem Sie Fragen stellen können
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.pyDer Server ist verfügbar unter: http://localhost:8000
API-Endpunkte
Gesundheitsprüfung
GET /healthAgent 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 /statsPython-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.pyErweiterungen & 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-transformersBeim 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 istStellen Sie sicher, dass
persist_dirin der Konfiguration mit dem tatsächlichen Pfad übereinstimmt
Lizenz
MIT-Lizenz - Siehe LICENSE-Datei für Details
Mitwirken
Beiträge sind willkommen! Bitte:
Forken Sie das Repository
Erstellen Sie einen Feature-Branch
Committen Sie Änderungen
Pushen Sie und öffnen Sie einen Pull Request
Referenzen
This server cannot be installed
Maintenance
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
- FlicenseNot gradedqualityDmaintenanceA 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.
- AlicenseNot gradedqualityDmaintenanceProvides 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.1MIT
- AlicenseNot gradedqualityDmaintenanceProvides 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.1MIT
- FlicenseNot gradedqualityDmaintenanceA 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.
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.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
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