MCP Documentation Server

repository·main·Indexed 43 days ago

https://github.com/andrea9293/mcp-documentation-server

A local-first TypeScript MCP server for document management and semantic search designed for AI coding agents. It supports text, markdown, and PDF files using local vector embeddings via @xenova/transformers. The server provides a web dashboard, a REST API for CRUD operations, and a Model Context Protocol (MCP) interface. Version 1.15.3.

Tokens
13.6K
Snippets
41
Records
65
Agent score
55%

What's inside MCP Documentation Server

  1. Security Considerations for Data, Files, and Network

    main

    When deploying or using the MCP Documentation Server, be aware of the following security boundaries:

    Data Storage

    • Documents are stored locally in ~/.mcp-documentation-server/.
    • No data is transmitted to external servers, except for initial embedding model downloads.
    • Action: Ensure proper file system permissions are set on the storage directory.

    File Upload Security

    • Supported formats: Only .txt, .md, and .pdf files are processed.
    • PDF Processing: Uses the unpdf library for safe text extraction without code execution.
    • Path Traversal: The server restricts file access to designated directories only.
    • Action: Always validate the source and content of uploaded files before processing.

    Network Security

    • The server runs locally via stdio transport by default.
    • No network ports are opened unless explicitly configured.
    • Communication is handled by the MCP client (e.g., Claude Desktop).

    Embedding Models

    • Models are downloaded from HuggingFace Hub on first use.
    • Models run locally; data is not sent to external services during inference.
    • Action: Verify model integrity if using custom embedding models.
  2. Understand the project structure and core components

    main

    The project is organized into several key modules located in the src/ directory:

    • server.ts: The main MCP server implementation.
    • document-manager.ts: Handles document storage and retrieval.
    • embedding-provider.ts: Provides an abstraction for AI embedding models.
    • search-engine.ts: Implements semantic search functionality.
    • types.ts: Contains TypeScript type definitions.
    • utils.ts: General utility functions.

    Key Technologies Used:

    • FastMCP: The framework used for building the MCP server.
    • @xenova/transformers: Used for running local AI embedding models.
    • pdf-ts: Used for extracting text from PDF files.
    • Zod: Used for runtime type validation.
  3. Understand the embedding model requirements

    main

    The server uses local embeddings via Transformers.js. You can select different models using the MCP_EMBEDDING_MODEL variable:

    ModelDimensionsNotes
    Xenova/all-MiniLM-L6-v2384Default — fast, good quality
    Xenova/paraphrase-multilingual-mpnet-base-v2768Recommended — best quality, multilingual

    ⚠️ Important: Changing the embedding model requires re-adding all documents. Embeddings from different models are incompatible. The Orama database is recreated automatically when the dimension changes.

  4. How the Parent-Child Chunking works

    main

    The server uses an IntelligentChunker that implements the Parent-Child Chunking pattern to improve search accuracy and context retrieval:

    1. Parent Chunks: Documents are first split into large parent chunks that preserve full context (such as sections or paragraphs).
    2. Child Chunks: Each parent is further split into small child chunks used for precise vector similarity search.
    3. Retrieval: When a query matches a child chunk, the system retrieves the corresponding parent chunk. This ensures the LLM receives both the specific matched fragment and the broader context surrounding it.
  5. Set up the development environment

    main

    To develop for the MCP Documentation Server, ensure you have the following prerequisites installed:

    Follow these steps to initialize your local environment:

    1. Fork and Clone: Fork the repository on GitHub, then clone your fork and add the original repository as an upstream remote.
    2. Install Dependencies: Run npm install to install required packages.
    3. Environment Configuration: (Optional) Create a .env file to specify the embedding model.
    4. Verify Setup: Build the project and run the development or inspector modes to ensure everything is working correctly.
    # Fork and clone
    git clone https://github.com/YOUR_USERNAME/mcp-documentation-server.git
    cd mcp-documentation-server
    
    # Add upstream
    git remote add upstream https://github.com/andrea9293/mcp-documentation-server.git
    
    # Install
    npm install
    
    # Verify
    npm run build
    npm run dev
    npm run inspect
  6. How to report a security vulnerability

    main

    If you discover a security vulnerability, please report it responsibly using one of the following methods:

    1. Email: Send details to andreabravaccino@gmail.com.
    2. GitHub Issues: Use the issue tracker for non-sensitive issues.
    3. Security Advisories: Use GitHub's private vulnerability reporting for sensitive vulnerabilities.

    What to include in your report

    • A description of the vulnerability.
    • Steps to reproduce the issue.
    • A potential impact assessment.
    • A suggested fix (if available).
    • Your contact information for follow-up.

    Response Timeline

    • Initial Response: Within 48 hours.
    • Status Updates: Weekly updates during investigation.
    • Resolution: Target of 30 days for fixes, depending on severity.
  7. Submit a pull request

    main

    Before submitting a Pull Request, follow these steps to ensure a smooth review process:

    1. Sync with upstream: Fetch and rebase your branch on upstream/main.
      git fetch upstream
      git rebase upstream/main
    2. **Verify Build**: Ensure `npm run build` passes.
    3. **Manual Testing**: Use `npm run inspect` to test the MCP functionality manually.
    4. **Documentation**: Update relevant documentation if your changes affect existing features.
    
    **PR Requirements**:
    - Use a **clear title** following the conventional commit format.
    - Provide a **description** explaining the *what*, *why*, and *how*.
    - Describe your **testing methodology**.
    - Explicitly mark any **breaking changes**.
    - Include **screenshots** for any changes to the inspector UI.
    
  8. Security Best Practices for Users

    main

    To maintain a secure environment when using the MCP Documentation Server, follow these practices:

    • Keep updated: Always use the latest stable version.
    • Manage files: Regularly review uploaded documents and clean up unused files.
    • Permissions: Use proper file system permissions for the ~/.mcp-documentation-server/ directory.
    • Validation: Validate document sources before processing.
    • Monitoring: Monitor system resources during embedding generation.
  9. Use the Documentation Server Web UI

    main

    The server includes a graphical web interface at http://127.0.0.1:3080. This is ideal for visual exploration and manual operations:

    • Dashboard: Overview of documents and statistics.
    • Documents: Browse, view, and delete documents.
    • Add Document: Create documents with title, content, and metadata.
    • Search: Perform semantic searches across all or specific documents.
    • AI Search: Gemini-powered analysis (requires GEMINI_API_KEY).
    • Upload Files: Drag-and-drop .txt, .md, or .pdf files.
    • Context Window: Interactively explore chunks around a specific index.
  10. Install and configure the MCP Documentation Server

    main

    You can install the server using npx without cloning the repository. To use it with an MCP client (like Claude Desktop), add the following configuration to your mcpServers settings:

    Minimal Configuration

    {
      "mcpServers": {
        "documentation": {
          "command": "npx",
          "args": ["-y", "@andrea9293/mcp-documentation-server"]
        }
      }
    }

    Advanced Configuration with Environment Variables

    You can customize the behavior by providing environment variables. This is useful for setting a custom storage directory, providing a Gemini API key for AI search, or changing the embedding model.

    {
      "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_HOST": "127.0.0.1",
            "WEB_PORT": "3080"
          }
        }
      }
    }
    {
      "mcpServers": {
        "documentation": {
          "command": "npx",
          "args": ["-y", "@andrea9293/mcp-documentation-server"]
        }
      }
    }
  11. Use the REST API for AI agents

    main

    While the server provides MCP tools, interacting via the REST API is recommended for AI agents (like Claude Code, Cursor, or Gemini CLI). This approach avoids bloating the conversation context with large MCP tool schemas, as only the JSON responses are sent to the LLM.

    The API is available at http://127.0.0.1:3080/api/.

    Example API Calls

    Get configuration:

    curl -s http://127.0.0.1:3080/api/config

    List documents:

    curl -s http://127.0.0.1:3080/api/documents

    Perform a search:

    curl -s -X POST http://127.0.0.1:3080/api/search-all \
      -H "Content-Type: application/json" \
      -d '{"query": "your search", "limit": 5}'

    Install the Agent Skill

    You can install a pre-made skill that teaches your agent how to use these endpoints:

    npx skills add https://github.com/andrea9293/mcp-documentation-server --skill documentation-server
    curl -s -X POST http://127.0.0.1:3080/api/search-all \
      -H "Content-Type: application/json" \
      -d '{"query": "your search", "limit": 5}'
  12. Follow TypeScript and code standards

    main

    When contributing code, adhere to these guidelines:

    TypeScript Guidelines

    • Use Strict mode settings.
    • Prefer explicit types over any.
    • Use interfaces for defining object shapes.
    • Use async/await instead of raw Promises.
    • Implement robust error handling.

    Code Style and Organization

    • Follow the Single Responsibility Principle (one class/function per file where appropriate).
    • Use descriptive naming for files and functions.
    • Use named exports instead of default exports where possible.
    • Provide JSDoc comments for all public methods and classes.