MCP Knowledge Base Server
MCP 知识库服务器
一个 MCP(模型上下文协议) 服务器,为 AI 助手——Claude Desktop、Cursor 或任何 MCP 客户端——提供对公司内部知识库中 Markdown 文档的可搜索、结构化访问。
向你的助手提问 "如何部署到生产环境?" 或 "我有多少天年假?",它会搜索知识库、阅读相关文章,并附上引用作答——而不是凭空捏造你的内部流程。
功能特性
6 个工具 — 带摘要的关键词搜索、全文获取、过滤列表、标签浏览、热重载和统计
2 种资源类型 — 直接浏览整个索引或任意文档(
kb://index、kb://documents/{doc_id})1 个提示模板 —
answer_from_knowledge_base将回答锚定在搜索结果中并强制引用零基础设施 — 知识库就是一个包含可选 frontmatter 的
.md文件文件夹;配合 Git 仓库使用效果极佳两种传输方式 — stdio 用于本地客户端,HTTP 用于共享/远程部署
依赖精简 — FastMCP + 内置的小型 TF-IDF 风格索引;无需数据库,无需嵌入服务
Related MCP server: search-docs
架构
┌─────────────────┐ stdio / HTTP (JSON-RPC) ┌──────────────────────────┐
│ MCP client │ ───────────────────────────▶ │ FastMCP server │
│ (Claude, …) │ ◀─────────────────────────── │ ├─ tools (search, get…) │
└─────────────────┘ │ ├─ resources (kb://…) │
│ └─ prompts (answer…) │
│ │ │
│ KnowledgeBaseIndex │
│ (tokenize → TF-IDF) │
└──────────┬─────────────┘
│ scans
┌──────────▼─────────────┐
│ knowledge_base/ │
│ engineering/*.md │
│ hr/*.md product/*.md │
└────────────────────────┘快速开始
git clone <your-repo-url> mcp-knowledge-base-server
cd mcp-knowledge-base-server
pip install .将服务器指向你自己的文档(或使用附带的示例语料库):
export KB_DIR=/path/to/your/markdown/docs运行演示
pip install fastmcp # only dependency the demo needs
python examples/demo_client.py演示通过 stdio 启动服务器并演练所有能力——搜索、文档获取、列表、资源和基于引用的回答提示——打印真实客户端会看到的完整 JSON-RPC 载荷。
连接 Claude Desktop
在 claude_desktop_config.json 中添加:
{
"mcpServers": {
"knowledge-base": {
"command": "python",
"args": ["-m", "mcp_knowledge_base.server"],
"env": {
"PYTHONPATH": "/absolute/path/to/mcp-knowledge-base-server/src",
"KB_DIR": "/absolute/path/to/mcp-knowledge-base-server/knowledge_base"
}
}
}
}重启 Claude Desktop,然后提问:"搜索我们的知识库——如果部署出错,回滚流程是什么?"
通过 HTTP 运行(共享/远程部署)
KB_DIR=/path/to/docs mcp-knowledge-base --transport http --port 8000
# → streamable HTTP endpoint at http://127.0.0.1:8000/mcp文档格式
任何包含 .md 文件的文件夹都可以。可选的 frontmatter 可丰富结果:
---
title: Deploying to Production
tags: [deploy, production, runbook]
department: engineering
updated: 2025-11-02
---
# Deploying to Production
…文档的 doc_id 是其相对于 KB_DIR 的路径(不含扩展名)(例如 engineering/deploy-guide)。标题回退到第一个 # 标题,然后是文件名。
API 参考
工具
工具 | 描述 |
| 排序关键词搜索;返回 doc_id、标题、标签、摘要、得分 |
| 单篇文章的完整 Markdown 内容 + 元数据 |
| 列出所有文章,可选过滤 |
| 所有标签及其文档数量 |
| 重新扫描 |
| 文档数量、标签数量、索引年龄 |
资源
URI | 描述 |
| 每篇文档的可读索引 |
| 单篇文档的完整内容 |
提示
提示 | 描述 |
| 搜索知识库,然后指示模型仅根据摘录作答并引用 doc_ids |
环境变量
变量 | 默认值 | 描述 |
|
| Markdown 文档的根文件夹 |
|
| 向 MCP 客户端显示的服务器名称 |
项目结构
├── knowledge_base/ # sample corpus (replace with your own)
│ ├── engineering/*.md
│ ├── hr/*.md
│ └── product/*.md
├── src/mcp_knowledge_base/
│ ├── server.py # FastMCP server: tools, resources, prompts
│ └── index.py # document loading + TF-IDF-style search
├── examples/
│ └── demo_client.py # end-to-end demo over stdio
└── pyproject.toml扩展它
更好的搜索:将
KnowledgeBaseIndex替换为嵌入 + 向量数据库(工具接口保持不变)。其他来源:索引 Confluence/Notion 导出——任何最终成为 Markdown 的内容都可以原样使用。
新鲜度:按计划运行
reload_knowledge_base,或使用文件系统监视器监视KB_DIR。
许可证
MIT — 参见 LICENSE。
Available Tools
6 toolsget_documentA
Fetch the full Markdown content of one knowledge-base article.
Inputs: doc_id (required). Returns: object
list_documentsA
List every article in the knowledge base, optionally filtered.
Inputs: tag, department. Returns: result
list_tagsA
List all tags used across the knowledge base, with document counts.
Inputs: no named parameters. Returns: object
reload_knowledge_baseA
Re-scan the knowledge-base directory to pick up new or edited articles.
Returns: Number of documents now indexed.
Inputs: no named parameters. Returns: object
search_knowledge_baseA
Search the company knowledge base with natural language or keywords.
Use this FIRST whenever a question might be answered by internal documentation (processes, runbooks, policies, architecture, onboarding…).
Inputs: query (required), tag, limit. Returns: result
statsB
Basic knowledge-base statistics (document count, tags, index age).
Inputs: no named parameters. Returns: object
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 6 tools
Each tool has a clearly distinct purpose: searching, fetching full documents, listing documents, listing tags, reloading the index, and showing stats. There is no overlap that would cause an agent to select the wrong tool.
All tool names follow a consistent verb_noun pattern (search_, get_, list_, reload_, etc.). The pattern is predictable and easy to infer for additional tools.
Six tools is well within the ideal range for a knowledge base server. Each tool serves a distinct function, and the count feels neither too sparse nor bloated.
The tool set covers all core operations: search, read, list, and maintenance. Minor gaps exist (e.g., no tool to add or delete documents via the API, but that may be intentionally managed filesystem-side). Reload and stats provide necessary lifecycle support.
Related MCP Connectors
Search and reason over your Obsidian-style Markdown vault, right from ChatGPT.
Convert PDFs, Office docs, websites and audio into AI-ready Markdown, then search and ask your docs.
Shared markdown docs for people and AI agents, kept as plain files in your team's GitHub repo.
- Very Simple NotesDeprecatedcom.verysimplenotes
Markdown notes in folders, with files, that your AI assistant can read, write and organise.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables AI models to seamlessly access and query local markdown technical documentation files, providing automatic documentation context without explicit prompting.5ISC
- AlicenseAqualityBmaintenanceEnables AI agents to search local Markdown documents using natural language, with automatic indexing and section-level retrieval.101MIT
- AlicenseNot gradedqualityDmaintenanceProvides AI assistants with direct access to local Markdown documentation libraries, enabling them to list, read, and search through docs on demand.MIT
- AlicenseNot gradedqualityCmaintenanceEnables AI assistants to search, read, and navigate a folder of Markdown notes as a knowledge base, with full-text search, backlinks, tags, metadata, and note resources for conversation attachment.1MIT