Skip to main content
Glama
MCP Knowledge Base Server

MCP Knowledge Base Server

by Sachin-wish

MCP ナレッジベースサーバー

AIアシスタント(Claude Desktop、Cursor、または任意のMCPクライアント)に、社内の ナレッジベース のMarkdownドキュメントへの検索可能で構造化されたアクセスを提供する MCP(Model Context Protocol) サーバーです。

アシスタントに 「本番环境にデプロイするにはどうすればいい?」 や 「有給休暇は何日ある?」 と尋ねると、ナレッジベースを検索し、関連記事を読み、引用付きで回答します。社内プロセスを幻覚(ハルシネーション)することはありません。

特徴

  • 6つのツール — スニペット付きキーワード検索、ドキュメント全体の取得、フィルタ付き一覧表示、タグブラウジング、ホットリロード、統計

  • 2種類のリソース — インデックス全体または任意のドキュメントを直接参照(kb://index、kb://documents/{doc_id})

  • 1つのプロンプトテンプレート — answer_from_knowledge_base は検索結果に基づいて回答を根拠付け、引用を強制します

  • インフラ不要 — ナレッジベースはオプションのfrontmatter付きの .md ファイルのフォルダだけで、Gitリポジトリとの併用に最適です

  • 2つのトランスポート — ローカルクライアント用のstdio、共有/リモート環境用のHTTP

  • 依存関係が軽量 — FastMCP + 組み込みの小型TF-IDF型インデックス。データベースやembeddingsサービスは不要です

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リファレンス

ツール

ツール

説明

search_knowledge_base(query, limit=5, tag=None)

ランク付きキーワード検索。doc_id、タイトル、タグ、スニペット、スコアを返します

get_document(doc_id)

1記事の完全なMarkdownコンテンツ + メタデータ

list_documents(tag=None, department=None)

すべての記事を一覧表示。オプションでフィルタ可能

list_tags()

ドキュメント数付きの全タグ

reload_knowledge_base()

KB_DIR を再スキャンして編集を反映

stats()

ドキュメント数、タグ数、インデックス経過時間

リソース

URI

説明

kb://index

全ドキュメントの人間可読なインデックス

kb://documents/{doc_id}

1つのドキュメントの完全なコンテンツ

プロンプト

プロンプト

説明

answer_from_knowledge_base(question)

KBを検索し、モデルに抜粋のみから回答しdoc_idを引用するよう指示します

環境変数

変数

デフォルト

説明

KB_DIR

./knowledge_base

Markdownドキュメントのルートフォルダ

KB_NAME

Company Knowledge Base

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 をembeddings + ベクターデータベースに置き換える(ツールのインターフェースはそのままです)。

  • 他のソース: Confluence/Notionのエクスポートをインデックス化 — Markdownになるものであればそのまま動作します。

  • 鮮度: reload_knowledge_base をスケジュール実行するか、ファイルシステムウォッチャーで KB_DIR を監視します。

ライセンス

MIT — LICENSE を参照してください。

Available Tools

6 tools
get_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

    A4/5.0

    Scored across 6 tools

    Disambiguation5/5

    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.

    Naming Consistency5/5

    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.

    Tool Count5/5

    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.

    Completeness4/5

    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

    Related MCP Servers

    • A
      license
      A
      quality
      B
      maintenance
      Enables AI agents to search local Markdown documents using natural language, with automatic indexing and section-level retrieval.
      10
      1
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables 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.
      1
      MIT