Agentic RAG MCP Server
MCP 기반 에이전트형 RAG 시스템
Model Context Protocol(MCP)을 사용하여 LLM을 벡터 데이터베이스 및 문서 로더와 같은 외부 도구에 연결하는 로컬 모듈형 검색 증강 생성(RAG) 시스템입니다.
개요
이 프로젝트는 다음과 같은 기능을 수행하는 에이전트형 RAG 시스템을 구현합니다:
검색: 로컬 벡터 데이터베이스(ChromaDB)에서 관련 문서 검색
증강: 검색된 컨텍스트로 프롬프트 증강
생성: 로컬 LLM(Ollama)을 사용하여 정보에 기반한 응답 생성
노출: 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 | 대화형 웹 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/activate2. 의존성 설치
pip install -U pip
pip install -r requirements.txt3. 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이 작업은 다음을 수행합니다:
샘플 문서를 벡터 저장소에 로드
질문을 할 수 있는 대화형 채팅 시작
에이전트가 관련 문서를 검색하고 답변 생성
대화 예시:
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 /statsPython 사용 예시
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 설정: 모델, 온도(temperature), 최대 토큰
벡터 저장소: 임베딩 모델, 컬렉션 이름
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
⬜ 웹 검색 도구 통합
⬜ 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 파일을 참조하세요.
기여
기여를 환영합니다! 다음 단계를 따라주세요:
저장소 포크
기능 브랜치 생성
변경 사항 커밋
푸시 후 풀 리퀘스트 생성
참조
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