UNPKG

@sofianedjerbi/knowledge-tree-mcp

Version:

MCP server for hierarchical project knowledge management

451 lines (334 loc) β€’ 11.4 kB
# 🌳 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](https://img.shields.io/npm/v/@sofianedjerbi/knowledge-tree-mcp)](https://www.npmjs.com/package/@sofianedjerbi/knowledge-tree-mcp) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) --- ## ✨ Features <table> <tr> <td width="33%"> ### πŸ—οΈ **Smart Organization** Auto-categorized paths with custom overrides and project-specific categories </td> <td width="33%"> ### 🎯 **Priority System** Four-tier priority system: **CRITICAL** β†’ **REQUIRED** β†’ **COMMON** β†’ **EDGE-CASE** </td> <td width="33%"> ### πŸ”— **Relationship Mapping** Six relationship types with bidirectional validation and automatic linking </td> </tr> <tr> <td> ### πŸ” **Advanced Search** Full-text search with regex, field-specific targeting, and multi-criteria filtering </td> <td> ### πŸ“Š **Usage Analytics** Track access patterns, search trends, and tool usage with privacy-first design </td> <td> ### 🌐 **Interactive Dashboard** Real-time web UI with graph visualization, tree explorer, and analytics </td> </tr> </table> --- ## πŸš€ Quick Start ### Using with Claude Desktop (Recommended) ```bash # 🎯 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 ```bash # πŸ“¦ 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 <details> <summary><b>πŸ“ add_knowledge</b> - Create entries with auto-generated paths</summary> **Create knowledge entries from Markdown with automatic categorization** ```typescript 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:** ```markdown --- 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" ``` </details> <details> <summary><b>πŸ” search_knowledge</b> - Find entries with advanced filtering</summary> **Search with field-specific targeting and multi-criteria filtering** ```typescript 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):** ```bash # 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" ``` </details> <details> <summary><b>🏷️ manage_categories</b> - Dynamic category management</summary> **Add, update, remove, and merge categories for better organization** ```typescript 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):** ```bash # 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" ``` </details> <details> <summary><b>πŸ”— link_knowledge</b> - Connect related entries</summary> **Create typed relationships between knowledge entries** ```typescript 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 </details> <details> <summary><b>πŸ—ΊοΈ index_knowledge</b> - Browse knowledge structure</summary> **Get comprehensive overview of your knowledge base** ```typescript 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 </details> <details> <summary><b>πŸ“Š usage_analytics</b> - Track usage patterns</summary> **Analyze how your knowledge base is being used** ```typescript 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 </details> <details> <summary><b>βœ… More Tools</b> - Additional capabilities</summary> - **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 </details> --- ## 🌐 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`: ```javascript // 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 ```bash # 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](LICENSE) file --- ## πŸ‘¨β€πŸ’» Author **Created by [sofianedjerbi](https://github.com/sofianedjerbi)** --- <div align="center"> **🌟 Star this project if it helps organize your AI assistant's knowledge!** </div>