Skip to main content
Glama
Simonsms

TiDB RAG MCP Server

by Simonsms

TiDB RAG MCP Server

一个用于读取 TiDB 数据库中 RAG 知识库的 MCP (Model Context Protocol) 服务器。

功能特性

  • 📚 知识库浏览 - 列出和查看知识条目

  • 🔍 关键词搜索 - 在知识库中搜索内容

  • 🎯 向量搜索 - 支持 TiDB 向量相似度搜索(开发中)

  • 🔄 双模式支持 - Mock 数据模式和 TiDB 数据库模式

Related MCP server: Dify Knowledge MCP Server

快速开始

1. 安装依赖

npm install

2. 配置环境变量

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_db

3. 构建和运行

# 构建
npm run build

# 运行
npm start

MCP 工具

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 协议" }

向量相似度搜索(开发中)。

参数:

参数

类型

必填

说明

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 模式包含以下示例知识:

  1. MCP 协议简介

  2. TiDB 向量搜索指南

  3. RAG 最佳实践

  4. TypeScript 类型系统进阶

  5. 知识库系统架构设计

开发

# 开发模式 (热重载)
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

文档

License

MIT

Available Tools

4 tools
tidb_get_knowledgeGet Knowledge EntryA
Read-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" }

ParametersJSON Schema
NameRequiredDescriptionDefault
idYesKnowledge entry ID
response_formatNoOutput format: 'markdown' for human-readable or 'json' for machine-readablemarkdown

TDQS

A4/5.0
Behavior4/5

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.

Conciseness4/5

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.

Completeness5/5

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.

Parameters3/5

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.

Purpose5/5

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.

Usage Guidelines3/5

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 EntriesA
Read-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 }

ParametersJSON Schema
NameRequiredDescriptionDefault
limitNoMaximum number of results to return (1-100)
offsetNoNumber of results to skip for pagination
categoryNoFilter by category
response_formatNoOutput format: 'markdown' for human-readable or 'json' for machine-readablemarkdown

TDQS

A3.7/5.0
Behavior4/5

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.

Conciseness4/5

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.

Completeness4/5

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.

Parameters3/5

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.

Purpose4/5

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.

Usage Guidelines3/5

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 KnowledgeA
Read-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 }

ParametersJSON Schema
NameRequiredDescriptionDefault
limitNoMaximum number of results to return (1-100)
queryYesSearch query string
offsetNoNumber of results to skip for pagination
categoryNoFilter by category
response_formatNoOutput format: 'markdown' for human-readable or 'json' for machine-readablemarkdown

TDQS

A3.6/5.0
Behavior4/5

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.

Conciseness4/5

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.

Completeness5/5

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.

Parameters3/5

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.

Purpose4/5

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.

Usage Guidelines2/5

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.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections. Dates show when Glama detected each change.

  1. 4 tool updatesv1.0.0
    • First observedtidb_get_knowledge
    • First observedtidb_list_knowledge
    • First observedtidb_search_knowledge
    • First observedtidb_vector_search

TDQS

A3.8/5.0
Disambiguation5/5

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.

Naming Consistency4/5

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.

Tool Count5/5

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.

Completeness2/5

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

ActivityInactive
ResponsivenessNo issues

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

Related MCP Servers

  • F
    license
    B
    quality
    D
    maintenance
    A Model Context Protocol server that allows executing SELECT queries on TiDB databases, with optional support for INSERT, UPDATE, and DELETE operations when explicitly enabled.
    1
    17
    -
  • A
    license
    B
    quality
    D
    maintenance
    A Model Context Protocol server that enables AI assistants like Cursor to directly query and retrieve information from Dify knowledge bases through natural language.
    2
    26
    6
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    A 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

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