TiDB RAG MCP Server
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@TiDB RAG MCP Server search for RAG best practices"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
TiDB RAG MCP Server
一个用于读取 TiDB 数据库中 RAG 知识库的 MCP (Model Context Protocol) 服务器。
功能特性
📚 知识库浏览 - 列出和查看知识条目
🔍 关键词搜索 - 在知识库中搜索内容
🎯 向量搜索 - 支持 TiDB 向量相似度搜索(开发中)
🔄 双模式支持 - Mock 数据模式和 TiDB 数据库模式
Related MCP server: Dify Knowledge MCP Server
快速开始
1. 安装依赖
npm install2. 配置环境变量
cp .env.example .env编辑 .env 文件:
# Mock 模式 (无需数据库)
USE_MOCK=true
# TiDB 数据库配置 (USE_MOCK=false 时需要)
TIDB_HOST=localhost
TIDB_PORT=4000
TIDB_USER=root
TIDB_PASSWORD=your_password
TIDB_DATABASE=knowledge_db3. 构建和运行
# 构建
npm run build
# 运行
npm startMCP 工具
tidb_list_knowledge
列出知识库条目,支持分页和分类过滤。
参数:
参数 | 类型 | 必填 | 默认值 | 说明 |
limit | number | 否 | 20 | 返回数量 (1-100) |
offset | number | 否 | 0 | 跳过数量 |
category | string | 否 | - | 按分类过滤 |
response_format | string | 否 | markdown | 输出格式: markdown/json |
示例:
{ "limit": 10, "category": "技术文档" }tidb_get_knowledge
获取单条知识详情。
参数:
参数 | 类型 | 必填 | 说明 |
id | string | 是 | 知识条目 ID |
response_format | string | 否 | 输出格式: markdown/json |
示例:
{ "id": "kb-001" }tidb_search_knowledge
在知识库中搜索。
参数:
参数 | 类型 | 必填 | 说明 |
query | string | 是 | 搜索关键词 |
limit | number | 否 | 返回数量 |
offset | number | 否 | 跳过数量 |
category | string | 否 | 按分类过滤 |
response_format | string | 否 | 输出格式 |
示例:
{ "query": "MCP 协议" }tidb_vector_search
向量相似度搜索(开发中)。
参数:
参数 | 类型 | 必填 | 说明 |
embedding | number[] | 是 | 查询向量 |
top_k | number | 否 | 返回数量 |
threshold | number | 否 | 相似度阈值 |
Claude Desktop 配置
在 Claude Desktop 配置文件中添加:
Windows: %APPDATA%\Claude\claude_desktop_config.json
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
{
"mcpServers": {
"tidb-rag": {
"command": "node",
"args": ["E:\\code\\mcp_test\\readKnowledgeMcp\\dist\\index.js"],
"env": {
"USE_MOCK": "true"
}
}
}
}使用 TiDB 数据库
{
"mcpServers": {
"tidb-rag": {
"command": "node",
"args": ["E:\\code\\mcp_test\\readKnowledgeMcp\\dist\\index.js"],
"env": {
"USE_MOCK": "false",
"TIDB_HOST": "your-tidb-host",
"TIDB_PORT": "4000",
"TIDB_USER": "root",
"TIDB_PASSWORD": "your-password",
"TIDB_DATABASE": "knowledge_db"
}
}
}
}数据库表结构
当使用 TiDB 数据库时,需要以下表结构:
CREATE TABLE knowledge_base (
id VARCHAR(36) PRIMARY KEY,
title VARCHAR(255) NOT NULL,
content TEXT NOT NULL,
category VARCHAR(100),
embedding VECTOR(1536), -- 向量嵌入 (可选)
metadata JSON,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
-- 向量索引 (可选,用于向量搜索)
CREATE VECTOR INDEX idx_embedding ON knowledge_base(embedding);Mock 数据
Mock 模式包含以下示例知识:
MCP 协议简介
TiDB 向量搜索指南
RAG 最佳实践
TypeScript 类型系统进阶
知识库系统架构设计
开发
# 开发模式 (热重载)
npm run dev
# 构建
npm run build
# 清理构建
npm run clean使用 MCP Inspector 测试
npx @modelcontextprotocol/inspector node dist/index.js项目结构
tidb-rag-mcp-server/
├── src/
│ ├── index.ts # MCP Server 入口
│ ├── types.ts # 类型定义
│ ├── constants.ts # 常量配置
│ ├── schemas/ # Zod 验证 schemas
│ │ └── index.ts
│ ├── services/ # 数据库和 Mock 服务
│ │ ├── database.ts
│ │ └── mock-data.ts
│ ├── tools/ # MCP 工具实现
│ │ ├── index.ts
│ │ ├── knowledge.ts
│ │ └── search.ts
│ └── utils/ # 工具函数
│ └── format.ts
├── dist/ # 编译输出
├── package.json
├── tsconfig.json
└── .env.example文档
TiDB 知识库接入指南 - 从 Mock 模式切换到真实 TiDB 数据库的完整指南
License
MIT
Available Tools
4 toolstidb_get_knowledgeGet Knowledge EntryARead-onlyIdempotent
Get a single knowledge entry by ID from TiDB RAG knowledge base.
This tool retrieves the full content of a specific knowledge entry.
Args:
id (string): Knowledge entry ID (e.g., "kb-001")
response_format ('markdown' | 'json'): Output format (default: 'markdown')
Returns: For JSON format: { "id": string, "title": string, "content": string, "category": string | null, "metadata": object | null, "created_at": string, "updated_at": string }
Examples:
Get by ID: { "id": "kb-001" }
Get as JSON: { "id": "kb-001", "response_format": "json" }
Inputs: id (required), response_format.
tidb_list_knowledgeList Knowledge EntriesARead-onlyIdempotent
List knowledge entries from TiDB RAG knowledge base with pagination.
This tool retrieves knowledge entries from the database, supporting filtering by category and pagination.
Args:
limit (number): Maximum results to return, 1-100 (default: 20)
offset (number): Number of results to skip for pagination (default: 0)
category (string, optional): Filter by category
response_format ('markdown' | 'json'): Output format (default: 'markdown')
Returns: For JSON format: { "total": number, // Total entries matching criteria "count": number, // Entries in this response "offset": number, // Current pagination offset "items": [...], // Array of knowledge entries "has_more": boolean, // Whether more results exist "next_offset": number // Offset for next page (if has_more) }
Examples:
List first 10 entries: { "limit": 10 }
Filter by category: { "category": "技术文档", "limit": 20 }
Paginate: { "limit": 20, "offset": 20 }
Inputs: limit, offset, category, response_format.
tidb_search_knowledgeSearch KnowledgeARead-onlyIdempotent
Search knowledge entries by keyword in TiDB RAG knowledge base.
This tool searches for knowledge entries matching a query string in title or content.
Args:
query (string): Search query string (1-500 characters)
limit (number): Maximum results to return, 1-100 (default: 20)
offset (number): Number of results to skip for pagination (default: 0)
category (string, optional): Filter by category
response_format ('markdown' | 'json'): Output format (default: 'markdown')
Returns: For JSON format: { "total": number, // Total matching entries "count": number, // Entries in this response "offset": number, // Current pagination offset "items": [...], // Array of matching knowledge entries "has_more": boolean, // Whether more results exist "next_offset": number // Offset for next page (if has_more) }
Examples:
Simple search: { "query": "MCP" }
Search with category filter: { "query": "向量", "category": "数据库" }
Paginated search: { "query": "RAG", "limit": 10, "offset": 10 }
Inputs: query (required), limit, offset, category, +1 more.
tidb_vector_searchVector Similarity SearchARead-onlyIdempotent
Search knowledge entries by vector similarity in TiDB (requires vector embeddings).
NOTE: This is a placeholder for future TiDB vector search functionality. Currently returns a not-implemented message.
Args:
embedding (number[]): Query embedding vector
top_k (number): Number of similar results to return, 1-100 (default: 10)
threshold (number): Minimum similarity threshold, 0-1 (default: 0.7)
response_format ('markdown' | 'json'): Output format (default: 'markdown')
Returns: Vector search results with similarity scores.
Inputs: embedding (required), top_k, threshold, response_format.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 4 tools
The four tools have clear, non-overlapping purposes: paginated listing, single-item retrieval by ID, keyword search, and vector similarity search. Even though list and search both return multiple entries, one is for browsing and the other requires a query, so an agent can reliably distinguish them.
Three tools follow a consistent tidb_verb_noun pattern: tidb_list_knowledge, tidb_get_knowledge, and tidb_search_knowledge. tidb_vector_search breaks the verb-first convention somewhat, but the shared prefix and parallel structure keep the naming readable.
Four tools is a well-scoped size for a read-focused knowledge base server. Each tool earns its place by covering a distinct retrieval need without unnecessary redundancy.
List, get, and keyword search form a functional read path, but the only semantic retrieval tool is explicitly a placeholder that always returns a not-implemented message. For a server claiming RAG capabilities, the missing working vector search and the lack of knowledge-entry management operations are significant gaps.
Maintenance
Related MCP Connectors
A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yo…
A Model Context Protocol server for Wix AI tools
Token-free MCP server for structured RevoGrid Core, Pro, and Enterprise knowledge retrieval.
Related MCP Servers
- FlicenseBqualityDmaintenanceA Model Context Protocol server that allows executing SELECT queries on TiDB databases, with optional support for INSERT, UPDATE, and DELETE operations when explicitly enabled.18 npm-
- AlicenseBqualityDmaintenanceA Model Context Protocol server that enables AI assistants like Cursor to directly query and retrieve information from Dify knowledge bases through natural language.26MIT
- AlicenseNot gradedqualityDmaintenanceA Model Context Protocol server that enables intelligent document search and retrieval from PDF collections, providing semantic search capabilities powered by OpenAI embeddings and ChromaDB vector storage.13MIT
- AlicenseNot gradedqualityDmaintenanceA local RAG server that enables document indexing and sentence window retrieval across multiple file formats like PDF, MD, and DOCX. It supports both local Hugging Face models and OpenAI embeddings for efficient context-aware querying through the Model Context Protocol.GPL 3.0