RAG MCP Claude

RAG MCP Claude

A semantic search MCP server for YouTube transcripts using OpenAI embeddings and ChromaDB, enabling natural language queries to find conceptually similar content beyond keyword matching.

Category
访问服务器

README

RAG MCP Claude

MCP (Model Context Protocol) Server สำหรับ Semantic Search บน YouTube transcripts ใช้ OpenAI Embeddings + ChromaDB

ต่างจาก keyword search ทั่วไป (FTS5) ที่ค้นได้เฉพาะ "คำตรงกัน" RAG ค้นหาด้วย ความหมาย ได้ เช่น ค้นว่า "วิธีฝึกจิตให้เข้มแข็ง" จะเจอข้อความเกี่ยวกับ "สมาธิ" แม้ไม่มีคำว่า "ฝึกจิต" ในข้อความเลย

ดูรายละเอียดเปรียบเทียบ RAG vs Keyword Search ที่ docs/concept-comparison.md

Features

  • rag_search - ค้นหาด้วย semantic similarity (ความหมายใกล้เคียง)
  • rag_ingest - นำ transcript / text เข้า knowledge base
  • rag_list_collections - แสดง collections พร้อมสถิติ
  • rag_delete - ลบข้อมูลออกจาก knowledge base

Architecture

                         rag-mcp-claude
                         Port: 3020
┌──────────────────────────────────────────────────┐
│                                                  │
│  ┌──────────┐    ┌─────────────┐                 │
│  │  Ingest   │───▶│ Text Splitter│                 │
│  │  Pipeline │    │ (chunk 500   │                 │
│  └──────────┘    │  overlap 50) │                 │
│                   └──────┬──────┘                 │
│                          ▼                        │
│                  ┌───────────────┐                │
│                  │ OpenAI API     │                │
│                  │ text-embedding │                │
│    ┌──────┐      │ -3-small       │                │
│    │Search│─────▶│ (1536 dims)   │                │
│    └──────┘      └───────┬───────┘                │
│                          ▼                        │
│                  ┌───────────────┐                │
│                  │  ChromaDB      │                │
│                  │  Vector Store  │                │
│                  │  (cosine sim)  │                │
│                  └───────────────┘                │
│                                                  │
└──────────────────────────────────────────────────┘

Quick Start

1. สร้าง OpenAI API Key

ไปที่ https://platform.openai.com/api-keys แล้วสร้าง key

2. สร้าง .env

cp .env.example .env
# แก้ไข .env ใส่ API key
OPENAI_API_KEY=sk-your-api-key-here

3. Deploy ด้วย Docker

docker compose up -d

จะ start 2 containers:

  • rag-chromadb - Vector database (port 8100)
  • rag-mcp-claude - MCP server (port 3020)

4. ตรวจสอบ

curl http://localhost:3020/health

5. Ingest transcript ตัวอย่าง

# Ingest ทุกไฟล์ใน data/sources/
node src/cli-ingest.js --dir ./data/sources

# Ingest ไฟล์เดียว
node src/cli-ingest.js data/sources/SF6Tskjx6Qw.md

ดูคู่มือ ingest ละเอียดที่ docs/guide-ingest.md

MCP Client Configuration

เพิ่มใน .mcp.json หรือ Claude Desktop config:

{
  "mcpServers": {
    "rag": {
      "url": "http://localhost:3020/mcp"
    }
  }
}

Project Structure

rag-mcp-claude/
├── src/
│   ├── server-sse.js    # Streamable HTTP transport server (port 3020)
│   ├── index.js         # Stdio transport server
│   ├── config.js        # Configuration
│   ├── embeddings.js    # OpenAI embedding API wrapper
│   ├── vectorstore.js   # ChromaDB operations (CRUD)
│   ├── ingest.js        # Chunk → Embed → Store pipeline
│   ├── search.js        # Semantic search
│   └── cli-ingest.js    # CLI batch ingest tool
├── data/
│   └── sources/         # Transcript files (.md)
├── docs/
│   ├── concept-comparison.md  # RAG vs FTS5 comparison
│   ├── guide-ingest.md        # คู่มือ ingest ข้อมูล
│   ├── guide-search.md        # คู่มือ search
│   └── guide-openai-key.md    # คู่มือสร้าง OpenAI API Key
├── Dockerfile
├── docker-compose.yml
├── .env.example
└── package.json

API Endpoints

Endpoint Method Description
/mcp POST MCP message endpoint (Streamable HTTP)
/mcp GET SSE stream endpoint
/mcp DELETE Session termination
/health GET Health check + status

MCP Tools Reference

rag_search

ค้นหาจาก knowledge base ด้วย semantic search

Parameter Type Required Default Description
query string Yes - คำค้นหา (ภาษาธรรมชาติ)
collection string No youtube_transcripts ชื่อ collection
top_k number No 5 จำนวนผลลัพธ์ (max 20)

Response:

{
  "query": "สมาธิเปลี่ยนสมองได้อย่างไร",
  "collection": "youtube_transcripts",
  "totalResults": 3,
  "sources": [
    {
      "source": "SF6Tskjx6Qw",
      "title": "Ep0 - Journey Within: สำรวจโลกในหัวคุณ",
      "url": "https://www.youtube.com/watch?v=SF6Tskjx6Qw",
      "channel": "The Mind Architect",
      "chunks": [
        {
          "text": "สมาธิทำให้สมองส่วน Prefrontal Cortex หนาขึ้น...",
          "score": 0.892,
          "chunk_index": 3
        }
      ]
    }
  ]
}

rag_ingest

นำข้อมูลเข้า knowledge base

Parameter Type Required Description
file_path string No* Path ของ transcript markdown file (.md)
text string No* ข้อความที่จะ ingest โดยตรง
source string No ชื่อแหล่งข้อมูล (เช่น video ID)
title string No ชื่อเรื่อง
collection string No ชื่อ collection

*ต้องระบุอย่างน้อย file_path หรือ text

rag_list_collections

แสดง collections ทั้งหมดพร้อมจำนวน documents

Response:

{
  "total": 1,
  "collections": [
    { "name": "youtube_transcripts", "count": 45 }
  ]
}

rag_delete

ลบข้อมูลออกจาก knowledge base

Parameter Type Required Description
collection string Yes ชื่อ collection
source string No ลบ documents จาก source นี้
delete_collection boolean No ลบทั้ง collection

Environment Variables

Variable Default Description
PORT 3020 Server port
HOST 0.0.0.0 Server host
OPENAI_API_KEY (required) OpenAI API key
EMBEDDING_MODEL text-embedding-3-small OpenAI embedding model
CHROMA_URL http://localhost:8100 ChromaDB URL
CHROMA_COLLECTION youtube_transcripts Default collection name
CHUNK_SIZE 500 Tokens per chunk
CHUNK_OVERLAP 50 Overlap tokens between chunks
DEFAULT_TOP_K 5 Default search results

Docker Details

Container Image Port Description
rag-mcp-claude node:22-slim (custom) 3020 MCP server (Streamable HTTP)
rag-chromadb chromadb/chroma:latest 8100 Vector database
  • ChromaDB data persisted in Docker volume chroma-data
  • RAG server ใช้ network_mode: host เพื่อเข้าถึง ChromaDB
  • OpenAI API Key ส่งผ่าน .env file

Data Flow

YouTube Video
     │  (youtube-mcp-claude ดึง transcript)
     ▼
data/sources/*.md        ← Transcript files
     │
     ▼ (rag_ingest / cli-ingest.js)
┌────────────────┐
│ 1. Parse        │  แยก metadata + transcript text
│ 2. Chunk        │  ตัดเป็นท่อนๆ (500 tokens, overlap 50)
│ 3. Embed        │  OpenAI API → vector [1536 dims]
│ 4. Store        │  ChromaDB (cosine similarity index)
└────────────────┘
     │
     ▼ (rag_search)
┌────────────────┐
│ 1. Embed query  │  แปลงคำถามเป็น vector
│ 2. Search       │  หา vectors ที่ใกล้เคียงที่สุด
│ 3. Return       │  ส่งกลับ chunks + metadata + score
└────────────────┘

Cost Estimation (OpenAI)

Model Price 1 transcript (~10K tokens) 1 search query
text-embedding-3-small $0.02 / 1M tokens ~$0.0002 (< 1 สตางค์) ~$0.000002
text-embedding-3-large $0.13 / 1M tokens ~$0.0013 ~$0.000013

ใช้ text-embedding-3-small ราคาถูกมาก ingest transcript 1,000 วิดีโอ ≈ $0.20 (7 บาท)

Related Projects

Server Port Description
youtube-mcp-claude 3010 YouTube transcript extraction
rag-mcp-claude 3020 RAG semantic search
chat-mcp-claude 3001 Chat history (FTS5)
thudong-mcp-claude 3002 Survey analysis (FTS5)

Documentation

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选