notes-rag-mcp

notes-rag-mcp

A Python MCP server for note management with RAG capabilities, enabling adding, searching, asking questions, summarizing, and deleting notes, using PostgreSQL and ChromaDB with Google Gemini for embeddings and generation.

Category
Visit Server

README

Notatki RAG — przykładowy serwer MCP

Serwer MCP (Model Context Protocol) w Pythonie, który łączy LLM + bazę danych w pełny przepływ RAG zbudowany na LangChain (LCEL). Notatki trafiają do PostgreSQL (system zapisu), ich treść+embeddingi do ChromaDB, a odpowiedzi generuje Google Gemini. Ćwiczenie do kursu IBM Build AI Agents using MCP.

Architektura

Warstwa Rola Plik
PostgreSQL system zapisu dla notatek (notes, CRUD, lista) db.py, schema.sql
ChromaDB (langchain-chroma) vector store: treść + embeddingi → retriever rag_chain.py
Gemini (langchain-google-genai) embeddingi (gemini-embedding-001) + generacja (gemini-2.5-flash) rag_chain.py
LCEL łańcuch RAG: retriever | prompt | llm | parser rag_chain.py
MCP / FastMCP wystawia narzędzia klientowi MCP (stdio) server.py

Przepływ pytania (ask) jako łańcuch LCEL:

{"context": retriever | format_docs, "question": RunnablePassthrough()}
    | prompt | llm | StrOutputParser()

retriever (Chroma) zwraca dopasowane notatki → format_docs skleja kontekst → Gemini odpowiada tylko na jego podstawie. PostgreSQL pozostaje źródłem prawdy dla treści i pozwala odbudować indeks (rag_chain.reindex_all).

Narzędzia MCP

Narzędzie Opis
add_note(title, content) zapis do Postgresa + embedding do Chromy
search_notes(query, top_k=3) wyszukiwanie semantyczne (tytuł, fragment, dystans)
ask(question, top_k=3) pełny RAG: retrieval + odpowiedź Gemini
list_notes() lista wszystkich notatek
summarize_note(note_id) streszczenie notatki przez Gemini
delete_note(note_id) usuwa z Postgresa i z Chromy

Dodatkowo zasób notes://{id} zwraca treść notatki.

Wymagania

  • Python ≥ 3.12 (przetestowane na 3.14)
  • PostgreSQL działający lokalnie (tu: Homebrew postgresql@15 na :5432)
  • Klucz API Gemini: https://aistudio.google.com/apikey

Setup

# 1. Zależności (w aktywnym venv)
python -m pip install -e .

# 2. Baza danych (jeśli jeszcze nie istnieje)
createdb notes_mcp

# 3. Konfiguracja
cp .env.example .env
#   → wpisz GEMINI_API_KEY w .env
#   → sprawdź DATABASE_URL (domyślnie konto bieżącego usera, trust na localhost)

Tabela notes tworzy się automatycznie przy starcie serwera (db.init_schema()). Można też ręcznie: psql -d notes_mcp -f schema.sql.

Uruchomienie i test

Z inspektorem MCP (interaktywny GUI w przeglądarce — najwygodniej do nauki):

mcp dev server.py

W Inspectorze (zakładka Tools):

  1. add_note("Python GIL", "GIL to globalna blokada interpretera CPython...")
  2. dodaj jeszcze 2–3 notatki na różne tematy,
  3. search_notes("czym jest GIL") → trafienie wskazuje notatkę o GIL,
  4. ask("wyjaśnij GIL na podstawie moich notatek") → odpowiedź ugruntowana w treści,
  5. summarize_note(1), potem delete_note(1) → sprawdź spójność Postgres ↔ Chroma.

Podpięcie do klienta MCP (np. Claude Desktop) — wpis w configu:

{
  "mcpServers": {
    "notes-rag": {
      "command": "/pełna/ścieżka/.venv/bin/python",
      "args": ["/pełna/ścieżka/server.py"]
    }
  }
}

Pliki

server.py        # FastMCP + narzędzia MCP (entry point)
rag_chain.py     # LangChain: Gemini + Chroma + łańcuch LCEL (RAG)
db.py            # PostgreSQL (psycopg3) — system zapisu
schema.sql       # tabela notes
pyproject.toml   # zależności
.env(.example)   # konfiguracja

Poza zakresem (świadomie)

Chunking długich dokumentów, autoryzacja/multi-user, testy automatyczne — ćwiczenie skupia się na integracji RAG + MCP.

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured