### Install Project Dependencies Source: https://github.com/andrea9293/mcp-documentation-server/blob/main/docs/CONTRIBUTING.md Install all necessary Node.js dependencies for the project using npm. ```bash npm install ``` -------------------------------- ### Clone and Install Project Dependencies Source: https://github.com/andrea9293/mcp-documentation-server/blob/main/README.md Clone the repository and install project dependencies using npm. ```bash git clone https://github.com/andrea9293/mcp-documentation-server.git cd mcp-documentation-server npm install ``` -------------------------------- ### Configure MCP Client (Basic) Source: https://github.com/andrea9293/mcp-documentation-server/blob/main/README.md Example configuration for an MCP client to connect to the documentation server. This uses the default command and arguments. ```json { "mcpServers": { "documentation": { "command": "npx", "args": [ "-y", "@andrea9293/mcp-documentation-server" ] } } } ``` -------------------------------- ### Start Development Server with Hot Reload Source: https://github.com/andrea9293/mcp-documentation-server/blob/main/docs/CONTRIBUTING.md Starts the development server, which automatically rebuilds and reloads on code changes. ```bash npm run dev ``` -------------------------------- ### Run Direct Development Server Source: https://github.com/andrea9293/mcp-documentation-server/blob/main/docs/CONTRIBUTING.md Starts the development server directly, bypassing the FastMCP wrapper for specific testing scenarios. ```bash npm run dev:direct ``` -------------------------------- ### Conventional Commits Example Source: https://github.com/andrea9293/mcp-documentation-server/blob/main/docs/CONTRIBUTING.md An example demonstrating how to use the Conventional Commits format for commit messages, including a breaking change. ```bash feat: change document storage format BREAKING CHANGE: Document storage format has changed. Existing documents need to be re-imported. ``` -------------------------------- ### List all documents via REST API Source: https://context7.com/andrea9293/mcp-documentation-server/llms.txt Use this `GET` request to retrieve a list of all documents managed by the server. The response includes metadata and a content preview for each document. ```bash curl http://localhost:3080/api/documents # Response: 200 OK [ { "id": "a3f9c1e2b4d67890", "title": "TypeScript Handbook", "created_at": "2024-01-15T10:30:00.000Z", "updated_at": "2024-01-15T10:30:00.000Z", "metadata": { "author": "Microsoft" }, "content_preview": "## Introduction\nTypeScript is a typed superset...", "chunks_count": 42 } ] ``` -------------------------------- ### Add Document MCP Tool Call Source: https://context7.com/andrea9293/mcp-documentation-server/llms.txt This is an example of how to call the `add_document` MCP tool. Provide the document's title, full content, and optional metadata. The server will handle chunking, embedding, and persistence. ```json // MCP tool call { "tool": "add_document", "arguments": { "title": "TypeScript Handbook", "content": "## Introduction\nTypeScript is a typed superset of JavaScript...\n\n## Basic Types\nTypeScript supports `string`, `number`, `boolean`...", "metadata": { "author": "Microsoft", "tags": ["typescript", "programming"], "version": "5.0" } } } ``` ```json // Response "Document added successfully with ID: a3f9c1e2b4d67890" ``` -------------------------------- ### Commit Changes with Conventional Commits Source: https://github.com/andrea9293/mcp-documentation-server/blob/main/docs/CONTRIBUTING.md Examples of using conventional commit messages for feature, fix, and documentation changes. ```bash git commit -m "feat: add PDF text extraction support" git commit -m "fix: resolve embedding model initialization error" git commit -m "docs: update README with new features" ``` -------------------------------- ### List Files in Uploads Folder Source: https://context7.com/andrea9293/mcp-documentation-server/llms.txt Get a list of all files currently stored in the server's uploads folder. Includes file name, size, modification date, and supported status. ```bash curl http://localhost:3080/api/uploads ``` -------------------------------- ### Get a single document via REST API Source: https://context7.com/andrea9293/mcp-documentation-server/llms.txt Use this `GET` request with a document ID to retrieve the full document object, including its chunks. Handles 'Document not found' errors. ```bash curl http://localhost:3080/api/documents/a3f9c1e2b4d67890 # Response: 200 OK — full Document object with chunks array # Response: 404 { "error": "Document not found: a3f9c1e2b4d67890" } ``` -------------------------------- ### Create Feature or Fix Branch Source: https://github.com/andrea9293/mcp-documentation-server/blob/main/docs/CONTRIBUTING.md Branching strategy for starting new development work, whether for new features or bug fixes. ```bash git checkout -b feature/your-feature-name # or git checkout -b fix/bug-description ``` -------------------------------- ### Get Context Window for Chunk Source: https://github.com/andrea9293/mcp-documentation-server/blob/main/README.md Fetches neighboring chunks around a given chunk index. This provides broader context for the LLM, improving understanding. ```python get_context_window(id: str, chunk_index: int) ``` -------------------------------- ### GET /api/documents Source: https://context7.com/andrea9293/mcp-documentation-server/llms.txt Lists all documents stored in the system. Returns a summary of each document including its ID, title, creation and update timestamps, metadata, and a content preview. ```APIDOC ## GET /api/documents — List all documents ### Description Lists all documents stored in the system. Returns a summary of each document including its ID, title, creation and update timestamps, metadata, and a content preview. ### Method GET ### Endpoint /api/documents ### Response #### Success Response (200) - **id** (string) - Unique identifier for the document. - **title** (string) - The title of the document. - **created_at** (string) - Timestamp when the document was created. - **updated_at** (string) - Timestamp when the document was last updated. - **metadata** (object) - Key-value pairs for additional document information. - **content_preview** (string) - A short preview of the document's content. - **chunks_count** (integer) - The number of text chunks the document is divided into. ### Request Example ```bash curl http://localhost:3080/api/documents ``` ### Response Example ```json [ { "id": "a3f9c1e2b4d67890", "title": "TypeScript Handbook", "created_at": "2024-01-15T10:30:00.000Z", "updated_at": "2024-01-15T10:30:00.000Z", "metadata": { "author": "Microsoft" }, "content_preview": "## Introduction\nTypeScript is a typed superset...", "chunks_count": 42 } ] ``` ``` -------------------------------- ### Get MCP Web UI URL Source: https://github.com/andrea9293/mcp-documentation-server/blob/main/README.md Returns the URL for the Web UI, typically http://localhost:3080. This is helpful for accessing the dashboard or locating the uploads folder via the browser. ```python get_ui_url() ``` -------------------------------- ### Initialize Application Configuration Source: https://github.com/andrea9293/mcp-documentation-server/blob/main/src/public/index.html Fetches application configuration on startup and conditionally displays navigation elements based on Gemini availability. ```javascript async function init() { try { config = await api('GET', '/config'); if (config.gemini_available) { document.getElementById('nav-search-ai').style.display = ''; } } catch (e) { console.error('Failed to load config', e); } await loadDashboard(); } init(); ``` -------------------------------- ### Clone Repository and Set Up Remotes Source: https://github.com/andrea9293/mcp-documentation-server/blob/main/docs/CONTRIBUTING.md Clone your forked repository and add the upstream remote to fetch changes from the original project. ```bash git clone https://github.com/YOUR_USERNAME/mcp-documentation-server.git cd mcp-documentation-server git remote add upstream https://github.com/andrea9293/mcp-documentation-server.git ``` -------------------------------- ### Build and Inspect Project Tools Source: https://github.com/andrea9293/mcp-documentation-server/blob/main/docs/CONTRIBUTING.md Commands to build the project and then inspect its functionality, typically via a web interface. ```bash npm run build npm run inspect ``` -------------------------------- ### Get uploads directory path Source: https://context7.com/andrea9293/mcp-documentation-server/llms.txt Retrieves the absolute path to the server's uploads directory. ```APIDOC ## GET /api/uploads/path — Get uploads directory path ### Description Retrieves the absolute path to the server's uploads directory. ### Method GET ### Endpoint /api/uploads/path ### Response #### Success Response (200 OK) - **path** (string) - The absolute path to the uploads directory. #### Response Example ```json { "path": "/home/user/.mcp-documentation-server/uploads" } ``` ``` -------------------------------- ### Get Document Title Source: https://github.com/andrea9293/mcp-documentation-server/blob/main/src/public/index.html Retrieves the title of a document given its ID. Returns the ID if the document is not found. ```javascript function getDocTitle(id) { const doc = documents.find(d => d.id === id); return doc ? doc.title : id; } ``` -------------------------------- ### Build and Run Project Commands Source: https://github.com/andrea9293/mcp-documentation-server/blob/main/docs/CONTRIBUTING.md Commands to build the project, run it in development mode with hot reload, and inspect its tools. ```bash npm run build npm run dev npm run inspect ``` -------------------------------- ### MCP Architecture Overview Source: https://github.com/andrea9293/mcp-documentation-server/blob/main/README.md Provides a high-level overview of the server's architecture, detailing the components and their interactions, including the Web UI, MCP Tools, and DocumentManager. ```text Server (FastMCP, stdio) ├─ Web UI (Express, port 3080) │ └─ REST API → DocumentManager └─ MCP Tools └─ DocumentManager ├─ OramaStore — Orama vector DB (chunks DB + docs DB + parents DB), persistence, migration ├─ IntelligentChunker — Parent-child chunking (code, markdown, text, PDF) ├─ EmbeddingProvider — Local embeddings via @xenova/transformers │ └─ EmbeddingCache — LRU in-memory cache └─ GeminiSearchService — Optional AI search via Google Gemini ``` -------------------------------- ### Run Development and Build Commands Source: https://github.com/andrea9293/mcp-documentation-server/blob/main/README.md Execute various npm scripts for development, building, and testing the FastMCP server and web UI. ```bash npm run dev # FastMCP dev mode with hot reload npm run build # TypeScript compilation npm run inspect # FastMCP web UI for interactive tool testing npm start # Direct tsx execution (MCP server + web UI) npm run web # Run only the web UI (development) npm run web:build # Run only the web UI (compiled) ``` -------------------------------- ### Project Structure Source: https://github.com/andrea9293/mcp-documentation-server/blob/main/docs/CONTRIBUTING.md An overview of the project's directory structure, highlighting key directories and files. ```text src/ server.ts # Main MCP server implementation document-manager.ts # Document storage and retrieval embedding-provider.ts # AI embedding abstraction search-engine.ts # Semantic search functionality types.ts # TypeScript type definitions utils.ts # Utility functions .github/ workflows/ # CI/CD workflows copilot-instructions.md docs/ README.md SECURITY.md CONTRIBUTING.md (this file) ``` -------------------------------- ### GET /api/documents/:id Source: https://context7.com/andrea9293/mcp-documentation-server/llms.txt Retrieves a single document by its ID. Returns the full document object, including its content and associated chunks. ```APIDOC ## GET /api/documents/:id — Get a single document ### Description Retrieves a single document by its ID. Returns the full document object, including its content and associated chunks. ### Method GET ### Endpoint /api/documents/:id ### Parameters #### Path Parameters - **id** (string) - Required - The unique identifier of the document to retrieve. ### Response #### Success Response (200) - Returns the full Document object with a chunks array. #### Error Response (404) - **error** (string) - Description of the error, e.g., "Document not found: [id]" ### Request Example ```bash curl http://localhost:3080/api/documents/a3f9c1e2b4d67890 ``` ``` -------------------------------- ### Get context window around a parent section Source: https://context7.com/andrea9293/mcp-documentation-server/llms.txt Retrieves a context window of content surrounding a specified parent section within a document. ```APIDOC ## POST /api/context-window — Get context window around a parent section ### Description Retrieves a context window of content surrounding a specified parent section within a document. ### Method POST ### Endpoint /api/context-window ### Parameters #### Request Body - **document_id** (string) - Required - The ID of the document. - **parent_index** (integer) - Required - The index of the parent section. - **before** (integer) - Optional - The number of sections to include before the parent section. - **after** (integer) - Optional - The number of sections to include after the parent section. ### Request Example ```json { "document_id": "a3f9c1e2b4d67890", "parent_index": 3, "before": 1, "after": 1 } ``` ### Response #### Success Response (200 OK) - **window** (array) - An array of objects, each representing a section within the context window. Each object contains: - **parent_index** (integer) - The index of the section. - **content** (string) - The content of the section. - **heading** (string) - The heading of the section. - **center** (integer) - The index of the central parent section. - **total_parents** (integer) - The total number of parent sections in the document. #### Response Example ```json { "window": [ { "parent_index": 2, "content": "## Basic Types\n...", "heading": "Basic Types" }, { "parent_index": 3, "content": "## Interfaces\n...", "heading": "Interfaces" }, { "parent_index": 4, "content": "## Type Aliases\n...", "heading": "Type Aliases" } ], "center": 3, "total_parents": 18 } ``` ``` -------------------------------- ### Response from `get_uploads_path` tool Source: https://context7.com/andrea9293/mcp-documentation-server/llms.txt Provides the filesystem path to the uploads folder and suggests placing .txt and .md files there for subsequent processing. ```json "Uploads folder path: /home/user/.mcp-documentation-server/uploads\n\nYou can place .txt and .md files in this folder, then use the 'process_uploads' tool to create embeddings for them." ``` -------------------------------- ### Get Uploads Directory Path Source: https://context7.com/andrea9293/mcp-documentation-server/llms.txt Retrieve the absolute path to the server's uploads directory. This can be useful for external file system operations. ```bash curl http://localhost:3080/api/uploads/path ``` -------------------------------- ### Configure Environment Variables Source: https://github.com/andrea9293/mcp-documentation-server/blob/main/docs/CONTRIBUTING.md Create a .env file to set environment variables for local development, such as the embedding model. ```bash MCP_EMBEDDING_MODEL=Xenova/all-MiniLM-L6-v2 ``` -------------------------------- ### Configure MCP Client for Documentation Server Source: https://context7.com/andrea9293/mcp-documentation-server/llms.txt This JSON configuration is used by MCP clients like Claude Desktop or VS Code to connect to the MCP Documentation Server. Ensure the 'command' and 'args' correctly point to the server executable and set environment variables for customization. ```json { "mcpServers": { "documentation": { "command": "npx", "args": ["-y", "@andrea9293/mcp-documentation-server"], "env": { "MCP_BASE_DIR": "/path/to/workspace", "GEMINI_API_KEY": "your-gemini-api-key", "MCP_EMBEDDING_MODEL": "Xenova/all-MiniLM-L6-v2", "START_WEB_UI": "true", "WEB_PORT": "3080", "MCP_CACHE_ENABLED": "true", "MCP_STREAMING_ENABLED": "true", "MCP_STREAM_FILE_SIZE_LIMIT": "10485760", "MCP_STREAM_CHUNK_SIZE": "65536" } } } } ``` -------------------------------- ### Get Document Content by ID Source: https://github.com/andrea9293/mcp-documentation-server/blob/main/README.md Fetch the complete content of a specific document using its unique identifier. This is useful when you need the full text of a document. ```python get_document(id: str) ``` -------------------------------- ### Configure MCP Base Directory Source: https://github.com/andrea9293/mcp-documentation-server/blob/main/README.md Set the base directory for data storage using the `MCP_BASE_DIR` environment variable. Defaults to `~/.mcp-documentation-server`. ```bash export MCP_BASE_DIR="/path/to/custom/storage" ``` -------------------------------- ### Server Configuration Info Source: https://context7.com/andrea9293/mcp-documentation-server/llms.txt Retrieve information about the server's current configuration, including the availability of AI features and the embedding model being used. ```bash curl http://localhost:3080/api/config ``` -------------------------------- ### Get Uploads Folder Path Source: https://github.com/andrea9293/mcp-documentation-server/blob/main/README.md Retrieves the absolute path to the server's uploads folder. Use this to programmatically access or manage files within the uploads directory. ```python get_uploads_path() ``` -------------------------------- ### Create Lazy and Eager Embedding Providers with Transformers Source: https://context7.com/andrea9293/mcp-documentation-server/llms.txt Use `createLazyEmbeddingProvider` for non-blocking model loading on server startup. `createEmbeddingProvider` loads models eagerly and can fall back to a simpler provider. Both use `@xenova/transformers` for local model execution with caching. ```typescript import { createLazyEmbeddingProvider, createEmbeddingProvider, TransformersEmbeddingProvider } from './src/embedding-provider.js'; // Lazy (recommended for server startup — no blocking model load) const lazyProvider = createLazyEmbeddingProvider('Xenova/all-MiniLM-L6-v2'); console.log(lazyProvider.getModelName()); // 'Xenova/all-MiniLM-L6-v2' console.log(lazyProvider.getDimensions()); // 384 // Generate embedding (triggers model download on first call, ~80MB) const embedding = await lazyProvider.generateEmbedding('How do I configure authentication?'); console.log(embedding.length); // 384 — normalized float32 vector // Eager with fallback (tries models in order, falls back to SimpleEmbeddingProvider) const eagerProvider = await createEmbeddingProvider('Xenova/paraphrase-multilingual-mpnet-base-v2'); const embedding768 = await eagerProvider.generateEmbedding('كيفية الاستيثاق'); console.log(embedding768.length); // 768 // Cache stats (when MCP_CACHE_ENABLED=true) const stats = lazyProvider.getCacheStats(); // { size: 127, maxSize: 1000, hits: 843, misses: 127, hitRate: '86.9%' } ``` -------------------------------- ### Add Document to MCP Server Source: https://github.com/andrea9293/mcp-documentation-server/blob/main/README.md Use this tool to add a document with its title, content, and optional metadata. Ensure the document is properly formatted. ```python add_document(title: str, content: str, metadata: Optional[Dict] = None) ``` -------------------------------- ### Configure MCP Client (Advanced with Env Vars) Source: https://github.com/andrea9293/mcp-documentation-server/blob/main/README.md Advanced configuration for an MCP client, including environment variables for customization. This allows setting base directories, API keys, embedding models, and web UI preferences. ```json { "mcpServers": { "documentation": { "command": "npx", "args": [ "-y", "@andrea9293/mcp-documentation-server" ], "env": { "MCP_BASE_DIR": "/path/to/workspace", "GEMINI_API_KEY": "your-api-key-here", "MCP_EMBEDDING_MODEL": "Xenova/all-MiniLM-L6-v2", "START_WEB_UI": "true", "WEB_PORT": "3080" } } } } ``` -------------------------------- ### Get Context Window Around a Parent Section Source: https://context7.com/andrea9293/mcp-documentation-server/llms.txt Retrieve a context window of parent sections around a specified parent index within a document. Useful for understanding the surrounding content of a particular section. ```bash curl -X POST http://localhost:3080/api/context-window \ -H "Content-Type: application/json" \ -d '{ "document_id": "a3f9c1e2b4d67890", "parent_index": 3, "before": 1, "after": 1 }' ``` -------------------------------- ### Get Context Window Around Search Result Source: https://context7.com/andrea9293/mcp-documentation-server/llms.txt Retrieves a sliding window of surrounding parent sections for a given `document_id` and `parent_index` from a search result. Use `before` and `after` parameters to control the number of neighboring sections included, providing broader context without loading the entire document. ```json { "tool": "get_context_window", "arguments": { "document_id": "a3f9c1e2b4d67890", "parent_index": 3, "before": 1, "after": 2 } } ``` ```json { "window": [ { "parent_index": 2, "content": "## Basic Types\n...", "heading": "Basic Types" }, { "parent_index": 3, "content": "## Interfaces\n...", "heading": "Interfaces" }, { "parent_index": 4, "content": "## Type Aliases\n...", "heading": "Type Aliases" }, { "parent_index": 5, "content": "## Union Types\n...", "heading": "Union Types" } ], "center": 3, "total_parents": 18 } ``` -------------------------------- ### Ensure Build Passes Source: https://github.com/andrea9293/mcp-documentation-server/blob/main/docs/CONTRIBUTING.md Run the build script to verify that the project compiles successfully before submitting a pull request. ```bash npm run build ``` -------------------------------- ### Run Web UI Standalone Source: https://github.com/andrea9293/mcp-documentation-server/blob/main/README.md Commands to run the web UI independently. Use 'npm run web' for development with live reloading and 'npm run web:build' for a production-ready compiled version. ```bash npm run web ``` ```bash npm run web:build ``` -------------------------------- ### Access Web UI Source: https://github.com/andrea9293/mcp-documentation-server/blob/main/README.md The web interface is accessible via localhost on the configured port, typically 3080. This URL allows direct access to the dashboard and tools. ```bash http://localhost:3080 ``` -------------------------------- ### Response from `process_uploads` tool Source: https://context7.com/andrea9293/mcp-documentation-server/llms.txt Returns a processing summary indicating completion status, number of files processed, and any errors encountered during processing. ```json "Processing completed!\n- Files processed: 3\n" ``` ```json "Processing completed!\n- Files processed: 2\n- Errors encountered: 1\n\nErrors:\n • Error processing report.pdf: No text found in PDF or PDF might be image-based" ``` -------------------------------- ### MCP Storage Layout Source: https://github.com/andrea9293/mcp-documentation-server/blob/main/README.md Illustrates the directory structure for data storage, including Orama databases, migration flags, and uploaded files. ```text ~/.mcp-documentation-server/ # Or custom path via MCP_BASE_DIR ├── data/ │ ├── orama-chunks.msp # Orama vector DB (child chunks + embeddings) │ ├── orama-docs.msp # Orama document DB (full content + metadata) │ ├── orama-parents.msp # Orama parent chunks DB (context sections) │ ├── migration-complete.flag # Written after legacy JSON migration │ └── *.md # Markdown copies of documents └── uploads/ # Drop .txt, .md, .pdf files here ``` -------------------------------- ### Configure Web UI Port Source: https://github.com/andrea9293/mcp-documentation-server/blob/main/README.md Change the port for the web UI using the `WEB_PORT` environment variable. The default is `3080`. ```bash export WEB_PORT="8080" ``` -------------------------------- ### Load Context Window API Source: https://github.com/andrea9293/mcp-documentation-server/blob/main/src/public/index.html Fetches context window data from the API and updates the UI. Handles loading states and errors. ```javascript HTML = '