TiDB RAG MCP Server
Click on "Install 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 Serversearch 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" }
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | Knowledge entry ID | |
| response_format | No | Output format: 'markdown' for human-readable or 'json' for machine-readable | markdown |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
Annotations already declare read-only, idempotent, and non-destructive behavior. The description adds useful behavioral context by disclosing the response_format options, the exact JSON return shape, and concrete examples, which go beyond the annotations without contradicting them.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is well-organized into purpose, arguments, return format, and examples, and the key purpose is front-loaded. There is slight redundancy between the first two sentences, but overall every remaining sentence earns its place.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
For a simple two-parameter read tool with no output schema, the description is complete: it states the ID requirement, the response_format behavior, the JSON return structure, and usage examples. No critical information needed to call the tool correctly is missing.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is 100%, so the schema already documents both parameters. The description adds only mild value by giving an example ID format ('kb-001') and a concise usage example, but it largely restates what the schema already provides.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
States a specific verb ('Get'), resource ('single knowledge entry by ID from TiDB RAG knowledge base'), and emphasizes retrieval of 'full content'. It is clearly distinct from siblings like list, search, and vector search, which do not fetch by exact ID.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description implies the tool is for cases where the caller already knows the knowledge entry ID, but it does not explicitly contrast with siblings (list/search/vector) or state when to use an alternative. The usage context is clear but not enforced with exclusions.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
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 }
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Maximum number of results to return (1-100) | |
| offset | No | Number of results to skip for pagination | |
| category | No | Filter by category | |
| response_format | No | Output format: 'markdown' for human-readable or 'json' for machine-readable | markdown |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
Annotations already declare readOnly, idempotent, and non-destructive behavior. The description adds useful behavioral context beyond annotations by documenting pagination semantics, response_format options, and the JSON return contract including has_more and next_offset. It does not specify ordering or entry field shapes, but the annotation coverage lowers that burden.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is well-organized with Summary, Args, Returns, and Examples sections, and the key purpose is front-loaded. There is minor redundancy: the second sentence largely restates the first ('List knowledge entries... with pagination' vs 'retrieves knowledge entries... supporting... pagination'), which costs a little efficiency.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
For a read-only, paginated list tool with no output schema, the description covers all parameters, defaults, pagination mechanics, JSON return shape, and includes examples. It omits markdown output shape and ordering semantics, but these are minor given the annotations and schema coverage.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is 100%, so the schema already documents all four parameters fully. The description repeats parameter defaults and adds practical examples, but it does not add substantive semantic meaning beyond what the schema provides.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description states a specific verb and resource: 'List knowledge entries from TiDB RAG knowledge base with pagination' and adds category filtering. It is clear and distinct in practice, but it never explicitly references sibling tools like tidb_get_knowledge or tidb_search_knowledge to explain how listing differs from getting or searching.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description implies usage for paginated browsing and category filtering, which gives some context. However, it provides no explicit when-to-use or when-not-to-use guidance and does not mention alternative tools or conditions that would route an agent to search or vector_search instead.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
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 }
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Maximum number of results to return (1-100) | |
| query | Yes | Search query string | |
| offset | No | Number of results to skip for pagination | |
| category | No | Filter by category | |
| response_format | No | Output format: 'markdown' for human-readable or 'json' for machine-readable | markdown |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
The annotations already cover safety traits (readOnlyHint, idempotentHint, non-destructive), so the description's added value is appropriate: it explains that results match title/content, documents the markdown/json response formats, and details pagination semantics like has_more and next_offset. This goes beyond the structured annotations without contradicting them.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is well organized with clear sections: purpose, args, returns, and examples. It is longer than minimal, but the extended return-shape documentation is justified because there is no output schema. The only minor redundancy is the second sentence partially restating the first.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Given that there is no output schema, the detailed JSON return structure and pagination fields are essential and are fully provided. Examples cover simple search, category filtering, and pagination. The definition is complete enough for an agent to invoke the tool correctly; cross-tool routing is absent but is already scored separately under usage guidelines.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is 100%, so the baseline is 3. The Args section largely restates the schema: query length, limit range, default values, category filtering, and response_format enum. The examples add usage context but not new parameter-level meaning, so the description neither hurts nor significantly supplements the schema.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The opening sentence names a specific verb and resource: 'Search knowledge entries by keyword in TiDB RAG knowledge base.' It further clarifies that matching occurs in title or content, which conveys a lexical-scope distinction from siblings. However, it never explicitly names or contrasts sibling tools such as tidb_vector_search, so differentiation is implicit rather than stated.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
There is no explicit when-to-use or when-not-to-use guidance. The description does not mention alternatives like tidb_list_knowledge for browsing, tidb_get_knowledge for single entries, or tidb_vector_search for semantic search. The keyword-scoped phrasing implies one usage context, but no exclusions or routing rules are provided.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
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.
| Name | Required | Description | Default |
|---|---|---|---|
| top_k | No | Number of similar results to return | |
| embedding | Yes | Query embedding vector | |
| threshold | No | Minimum similarity threshold (0-1) | |
| response_format | No | Output format | markdown |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
Beyond the readOnly and idempotent annotations, the description discloses the most important runtime behavior: this is a placeholder and will return a not-implemented message. This is critical information that the annotations alone could not convey. There is no contradiction between the description and annotations.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The core message is concise and the placeholder warning is front-loaded, which is helpful. However, the Args and Returns sections largely duplicate the input schema without adding new information, so not every sentence truly earns its place.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Between the schema, annotations, and description, a caller knows the parameters, safety profile, intended behavior, and the fact that the tool is currently non-functional. The main gaps are the lack of sibling-tool alternatives and the absence of a more concrete return format, but these are minor for a placeholder tool.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The input schema already describes all four parameters with types, defaults, ranges, and required status, so schema coverage is 100%. The description's Args section merely repeats that information and adds no additional semantic nuance. A baseline of 3 is appropriate when the schema carries the parameter documentation burden.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description opens with a specific verb and resource: 'Search knowledge entries by vector similarity in TiDB', which clearly conveys the intended function. The placeholder note adds important context without obscuring the purpose. However, it does not explicitly differentiate this tool from the sibling tidb_search_knowledge tool.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The placeholder warning gives an explicit reason not to call this tool now: 'Currently returns a not-implemented message.' That provides some usage guidance. But it never states when to use this tool versus the sibling list/get/search tools, nor does it recommend an alternative.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections. Dates show when Glama detected each change.
4 tool updates
v1.0.0- First observed
tidb_get_knowledge - First observed
tidb_list_knowledge - First observed
tidb_search_knowledge - First observed
tidb_vector_search
TDQS
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
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
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.
DocBase MCP server for AI agents
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.117-
- AlicenseBqualityDmaintenanceA Model Context Protocol server that enables AI assistants like Cursor to directly query and retrieve information from Dify knowledge bases through natural language.2266MIT
- 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
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/Simonsms/readKnowledgeMcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server