Skip to content

sofianedjerbi/knowledge-tree-mcp

Repository files navigation

๐ŸŒณ Knowledge MCP Server

Hierarchical knowledge management system for AI assistants
Transform scattered project insights into an organized, searchable knowledge base with intelligent relationships and priority-based organization.

npm version License: MIT


โœจ Features

๐Ÿ—๏ธ Smart Organization

Auto-categorized paths with custom overrides and project-specific categories

๐ŸŽฏ Priority System

Four-tier priority system: CRITICAL โ†’ REQUIRED โ†’ COMMON โ†’ EDGE-CASE

๐Ÿ”— Relationship Mapping

Six relationship types with bidirectional validation and automatic linking

๐Ÿ” Advanced Search

Full-text search with regex, field-specific targeting, and multi-criteria filtering

๐Ÿ“Š Usage Analytics

Track access patterns, search trends, and tool usage with privacy-first design

๐ŸŒ Interactive Dashboard

Real-time web UI with graph visualization, tree explorer, and analytics


๐Ÿš€ Quick Start

Using with Claude Desktop (Recommended)

# ๐ŸŽฏ Simple installation
claude mcp add knowledge -- npx @sofianedjerbi/knowledge-tree-mcp

# ๐ŸŽจ With web interface on port 9000
claude mcp add knowledge -- npx @sofianedjerbi/knowledge-tree-mcp -- --port 9000 --docs ./docs

# ๐Ÿ“ Custom port and docs location
claude mcp add knowledge -- npx @sofianedjerbi/knowledge-tree-mcp -- --port 9000 --docs /path/to/docs

Local Development

# ๐Ÿ“ฆ Setup
git clone https://github.com/sofianedjerbi/knowledge-tree-mcp
cd knowledge-tree-mcp
npm install && npm run build

# ๐Ÿƒ Run with web interface
npm start -- --port 9000

# ๐Ÿงช Run tests
npm test

CLI Options:

  • --docs, -d <path> โ†’ Documentation directory (default: ./docs)
  • --port, -p <number> โ†’ Web interface port (enables UI at http://localhost:PORT)
  • --help, -h โ†’ Show help

๐Ÿ› ๏ธ Core Tools

๐Ÿ“ add_knowledge - Create entries with auto-generated paths

Create knowledge entries from Markdown with automatic categorization

add_knowledge({
  content: string,     // Markdown with frontmatter
  path?: string        // Optional: override auto-generated path
})

Auto-Path Generation Examples:

  • "How to implement JWT authentication" โ†’ security/authentication/jwt-implementation.json
  • "Fix Redis connection timeout" โ†’ database/redis/troubleshooting/connection-timeout.json
  • "React hooks best practices" โ†’ frontend/react/best-practices/hooks.json

Markdown Format:

---
title: Implement JWT refresh token rotation
priority: REQUIRED
tags: [jwt, authentication, security]
---

# Problem
JWT tokens expire but users need seamless authentication

# Context
Mobile apps and SPAs need to maintain auth state without frequent logins

# Solution
Implement refresh token rotation with secure storage...

# Examples
```typescript
// Token rotation implementation
const refreshToken = async () => {
  // Implementation here
}

**Path Override Options (Ask your AI assistant):**
```bash
# Full custom path
"Add this JWT guide to security/auth/my-jwt-guide"

# Directory only (filename from title)
"Add this authentication knowledge to the security/auth/ directory"
๐Ÿ” search_knowledge - Find entries with advanced filtering

Search with field-specific targeting and multi-criteria filtering

search_knowledge({
  query?: string,              // Search text (supports regex)
  searchIn?: string[],         // Fields to search
  priority?: string[],         // Filter by priorities
  category?: string,           // Filter by category
  sortBy?: string,            // Sort results
  limit?: number,             // Max results
  regex?: boolean,            // Enable regex mode
  caseSensitive?: boolean     // Case sensitivity
})

Search Fields:

  • title, problem, solution, context, code, tags, path, all

Examples (Ask your AI assistant):

# Simple search
"Search for authentication patterns"

# Field-specific search  
"Find entries with JWT in the title or tags"

# Multi-criteria filtering
"Show me all CRITICAL and REQUIRED security vulnerabilities"

# Regex search
"Search for React hooks usage in code (useState, useEffect, useMemo)"

# Find all entries
"Show me all knowledge entries"
๐Ÿท๏ธ manage_categories - Dynamic category management

Add, update, remove, and merge categories for better organization

manage_categories({
  action: "add" | "update" | "remove" | "list" | "merge",
  category?: string,
  keywords?: string[],
  subcategories?: string[],
  scope?: "project" | "system" | "both",
  description?: string
})

Examples (Ask your AI assistant):

# List all categories
"Show me all available categories"

# Add project-specific category
"Add a payment-gateway category for Stripe and PayPal integrations"

# Merge keywords without replacing
"Add Svelte and SvelteKit to the frontend category keywords"
๐Ÿ”— link_knowledge - Connect related entries

Create typed relationships between knowledge entries

link_knowledge({
  from: string,
  to: string,
  relationship: string,
  description?: string
})

Relationship Types:

  • ๐Ÿค related โ†’ General connection (bidirectional)
  • โฌ†๏ธ supersedes โ†’ This replaces the target
  • โฌ‡๏ธ superseded_by โ†’ This is replaced by target
  • โšก conflicts_with โ†’ Conflicting approaches (bidirectional)
  • ๐Ÿ”ง implements โ†’ Implementation of a pattern
  • ๐Ÿ“‹ implemented_by โ†’ Has implementations
๐Ÿ—บ๏ธ index_knowledge - Browse knowledge structure

Get comprehensive overview of your knowledge base

index_knowledge({
  format?: "tree" | "list" | "summary" | "categories",
  include_content?: boolean,
  max_entries?: number
})

Formats:

  • ๐ŸŒณ tree โ†’ Hierarchical folder structure
  • ๐Ÿ“‹ list โ†’ Flat list with metadata
  • ๐Ÿ“Š summary โ†’ Statistics and overview
  • ๐Ÿ“ categories โ†’ Grouped by category
๐Ÿ“Š usage_analytics - Track usage patterns

Analyze how your knowledge base is being used

usage_analytics({
  days?: number,
  include?: string[]
})

Analytics Types:

  • ๐Ÿ‘๏ธ access โ†’ Entry access patterns
  • ๐Ÿ” searches โ†’ Search query analysis
  • ๐Ÿ› ๏ธ tools โ†’ Tool usage statistics
  • ๐ŸŒ interface โ†’ Web UI interactions
  • ๐Ÿ“ˆ patterns โ†’ Usage trends over time
โœ… More Tools - Additional capabilities
  • update_knowledge โ†’ Modify existing entries
  • delete_knowledge โ†’ Remove entries with cleanup
  • validate_knowledge โ†’ Check consistency and fix issues
  • export_knowledge โ†’ Generate documentation (MD/HTML/JSON)
  • stats_knowledge โ†’ Get detailed statistics
  • recent_knowledge โ†’ View recent changes
  • setup_project โ†’ Configure project settings
  • help โ†’ Get contextual guidance

๐ŸŒ Web Dashboard

Access the interactive dashboard at http://localhost:9000 (when using --port 9000)

Features:

  • ๐Ÿ“Š Overview Dashboard โ†’ KPIs, activity metrics, tag cloud
  • ๐Ÿ•ธ๏ธ Knowledge Graph โ†’ Interactive network visualization with physics simulation
  • ๐ŸŒฒ Knowledge Explorer โ†’ Hierarchical tree view with expand/collapse
  • ๐Ÿ” Search Interface โ†’ Real-time search with filters
  • ๐Ÿ“ˆ Analytics View โ†’ Usage patterns and trends
  • ๐Ÿ”„ Recent Activity โ†’ Latest additions and modifications

Graph Visualization:

  • Continuous Physics โ†’ Nodes auto-arrange to prevent overlaps
  • Priority Colors โ†’ Visual distinction by importance
  • Relationship Lines โ†’ See connections between entries
  • Fullscreen Mode โ†’ Maximize for large knowledge bases
  • Search & Filter โ†’ Find specific nodes with dimming highlight

๐Ÿ—๏ธ Project Configuration

The AI assistant can configure project-specific settings using setup_project:

// Ask your AI assistant to run this:
"Initialize project configuration for our Next.js app with Stripe payments"

// The AI will execute:
setup_project({
  action: "init",
  name: "My Project",
  pathPrefix: "my-project",
  technologies: ["nodejs", "react", "postgres"],
  categories: {
    "payments": {
      keywords: ["stripe", "billing", "subscription"],
      subcategories: ["webhooks", "invoices"]
    }
  }
})

This creates .knowledge-tree.json in your docs directory for:

  • Custom categories and keywords
  • Auto-tagging rules
  • Path prefix for all entries
  • Technology stack awareness

๐Ÿ“‚ Example Directory Structure

The system automatically organizes knowledge based on content. Here's a typical structure:

docs/
โ”œโ”€โ”€ .knowledge-tree.json      # Project configuration (auto-created)
โ”œโ”€โ”€ logs/
โ”‚   โ””โ”€โ”€ usage.jsonl          # Usage analytics (gitignored)
โ”œโ”€โ”€ frontend/                 # Auto-detected from React/Vue/UI content
โ”‚   โ”œโ”€โ”€ react/
โ”‚   โ”‚   โ””โ”€โ”€ hooks/
โ”‚   โ””โ”€โ”€ performance/
โ”œโ”€โ”€ backend/                  # Auto-detected from server/API content
โ”‚   โ”œโ”€โ”€ api/
โ”‚   โ”œโ”€โ”€ database/
โ”‚   โ””โ”€โ”€ security/
โ”œโ”€โ”€ testing/                  # Auto-detected from test-related content
โ”‚   โ”œโ”€โ”€ unit/
โ”‚   โ””โ”€โ”€ integration/
โ””โ”€โ”€ architecture/             # Auto-detected from design/pattern content
    โ”œโ”€โ”€ patterns/
    โ””โ”€โ”€ decisions/

Note: Directories are created automatically as you add knowledge. You don't need to create this structure manually!


๐Ÿ” Privacy & Security

  • Local First: All data stored locally in your project
  • No Telemetry: Zero external data collection
  • Git Friendly: JSON format for version control
  • Private Analytics: Usage logs in .gitignore by default

๐Ÿงช Development

# Run tests
npm test

# Run with file watching
npm run dev

# Build TypeScript
npm run build

# Lint & format
npm run lint
npm run format

# Type checking
npm run typecheck

Architecture:

  • TypeScript with strict mode
  • Modular design with clear separation of concerns
  • MCP SDK for Claude integration
  • Fastify for web server
  • Vis.js for graph visualization
  • WebSockets for real-time updates

๐Ÿค Contributing

Contributions welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Add tests for new functionality
  4. Ensure all tests pass
  5. Submit a pull request

๐Ÿ“„ License

MIT License - see LICENSE file


๐Ÿ‘จโ€๐Ÿ’ป Author

Created by sofianedjerbi


๐ŸŒŸ Star this project if it helps organize your AI assistant's knowledge!

About

MCP server for hierarchical project knowledge management with priority-based organization and real-time web interface

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors