Skip to main content
Glama
mcp-knowledge-base

mcp-knowledge-base

by shelldon0x

mcp-knowledge-base

A local, self-contained MCP (Model Context Protocol) server that lets AI assistants search, retrieve, and manage a local document collection using BM25 retrieval with stemming and stopword filtering. No external APIs required.

Built with the official MCP TypeScript SDK. Works with Claude Desktop, Cursor, Windsurf, and any MCP-compatible client.

Features

  • BM25 search with Porter stemming and stopword filtering for high-quality retrieval

  • Document chunking (~500 tokens with overlap) preserving original Markdown formatting

  • 6 MCP tools: search, list, get, ingest, update, delete

  • Stdio transport (standard for local MCP servers)

  • File locking with stale lock detection for safe concurrent access

  • Corrupt store recovery with automatic backup

  • Zero external dependencies for search (no OpenAI/Anthropic API calls needed)

  • 9 unit tests with Vitest

  • Example document auto-ingested on first run

Related MCP server: KB-MCP Server

Requirements

  • Node.js 20+

  • npm

Quick Start

git clone https://github.com/shelldon0x/mcp-knowledge-base.git
cd mcp-knowledge-base
npm install
npm run build

MCP Tools

Tool

Description

search_knowledge_base

BM25 search across indexed document chunks with relevance scoring

list_documents

List all indexed documents with metadata and timestamps

get_document

Retrieve full content of a specific document by ID

ingest_document

Add a new document (Markdown or plain text) to the knowledge base

update_document

Update title, content, or metadata of an existing document (re-indexes on content change)

delete_document

Remove a document and all its chunks from the knowledge base

MCP Client Configuration

Claude Desktop

Add to your Claude Desktop config (~/Library/Application Support/Claude/claude_desktop_config.json on macOS):

{
  "mcpServers": {
    "knowledge-base": {
      "command": "node",
      "args": ["/absolute/path/to/mcp-knowledge-base/dist/index.js"]
    }
  }
}

Cursor / Windsurf

Add the same mcpServers block to your editor's MCP settings.

Usage Examples

Search the knowledge base

{
  "query": "retrieval augmented generation",
  "top_k": 5
}

Returns ranked chunks with scores, source attribution, and original formatting preserved.

Ingest a new document

{
  "title": "Team onboarding notes",
  "content": "# Welcome\nThese are the team onboarding notes...",
  "metadata": {
    "source": "docs/onboarding.md",
    "tags": ["onboarding", "internal"]
  }
}

Update a document

{
  "document_id": "abc-123",
  "title": "Updated title",
  "content": "New content here..."
}

Content changes automatically trigger re-chunking and re-indexing.

Delete a document

{
  "document_id": "abc-123"
}

How It Works

Search Pipeline

  1. Tokenization: Text is lowercased and split into alphanumeric tokens

  2. Stopword removal: 90+ common English words filtered out

  3. Stemming: Basic Porter stemmer handles -ing, -ed, -s, -ly, -tion, -ness suffixes with double-consonant reduction

  4. BM25 scoring: Okapi BM25 with k1=1.5, b=0.75 ranks chunks by relevance

  5. Source attribution: Results include document title, chunk snippet (with original formatting), and metadata

Document Storage

  • Documents are split into ~500 token chunks with 50-token overlap

  • Chunks preserve the original text (including Markdown formatting) while using stemmed tokens for indexing

  • All data stored in data/knowledge-base.json (created automatically)

  • File locking prevents concurrent write corruption (stale locks auto-expire after 30s)

  • Corrupt JSON files are backed up to .corrupt and the store reinitializes gracefully

Development

npm run dev    # Run with tsx (hot reload)
npm run build  # Compile TypeScript
npm test       # Run Vitest test suite

Architecture

src/
├── index.ts          # Entry point, stdio transport setup
├── server.ts         # MCP server with 6 registered tools
├── knowledge-base.ts # Document store, BM25 search, chunking, stemming
├── types.ts          # TypeScript interfaces
└── __tests__/
    └── knowledge-base.test.ts  # 9 unit tests

Tech Stack

License

MIT

Available Tools

6 tools
delete_documentB

Delete a document and its chunks from the knowledge base.

Inputs: document_id (required).

get_documentB

Retrieve full content of a specific document.

Inputs: document_id (required).

ingest_documentB

Add a new document (markdown or plain text) to the knowledge base.

Inputs: title (required), content (required), metadata.

list_documentsB

List all indexed documents with metadata.

Inputs: no named parameters.

search_knowledge_baseC

Semantic search across indexed documents.

Inputs: query (required), top_k.

update_documentC

Update an existing document and reindex if content changes.

Inputs: document_id (required), title, content, metadata.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.5/5.0

    Scored across 6 tools

    Disambiguation5/5

    Each tool targets a distinct resource+action: search across docs, list metadata, get content, and create/update/delete lifecycle operations. The boundaries between search, list, and get are clear from the descriptions, and CRUD operations are unambiguous.

    Naming Consistency5/5

    All six tools follow a consistent snake_case verb_noun pattern (search_knowledge_base, list_documents, get_document, ingest_document, delete_document, update_document). The convention is predictable throughout with no deviations.

    Tool Count5/5

    Six tools is well-scoped for a knowledge base server, covering search, listing, retrieval, ingestion, update, and deletion without redundancy. Each tool earns its place.

    Completeness5/5

    The surface covers full document lifecycle: create (ingest), read (get/list/search), update (with reindex), and delete. No obvious gaps for a knowledge base domain.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      RAG-powered document search server that enables semantic search across large collections of legal and business documents (PDF, Word, Excel, PowerPoint) using local embeddings with no API costs.
      5
      MIT
    • F
      license
      A
      quality
      Not graded
      maintenance
      A local-first knowledge base server that enables AI clients to store, retrieve, and manage documents using semantic search. Provides privacy-focused, offline-capable memory for AI assistants with tools for ingesting, querying, updating, and deleting knowledge.
      7
      21 npm
      -
    • F
      license
      Not graded
      quality
      B
      maintenance
      Enables any MCP-compatible AI assistant to search, filter, and retrieve information from a local document collection using a hybrid search pipeline with vector, BM25, reranking, and LLM enrichment.
      4
      -
    • A
      license
      A
      quality
      D
      maintenance
      Local-first RAG indexing and semantic search MCP server. Enables document retrieval and context-aware queries using local embedding models.
      3
      6 npm
      MIT