MCP HubMCP Hub
M-Gonzalo

cosa-sai

by: M-Gonzalo

MCP server for retrieving relevant documentation from a knowledge base

13created 27/02/2025
Visit
documentation
knowledgebase

📌Overview

Purpose: To provide an MCP server that facilitates access to documentation for various technologies using the Gemini API, enhancing learning and debugging experiences.

Overview: The Gemini Docs MCP Server leverages the Gemini API's extensive context window to offer precise, curated responses based on documentation. It is designed for various clients, with a specific focus on the Roo/Cline environment, and aims to improve the efficiency of accessing technical information.

Key Features:

  • Curated Knowledge Base: Access to a specific set of documents minimizes irrelevant results, enabling the model to deliver focused and accurate information.

  • Complex Query Handling: The server is capable of responding to multifaceted inquiries about technologies, providing tailored answers rather than merely snippets from documentation.

  • Multiple Query Tools: Supports various commands to assist users in checking feasibility, obtaining hints, validating best practices, and seeking examples across different technologies.

  • Simplified Architecture: Eliminates the need for chunking, custom retrievers, and vector databases, working directly with plain text to enhance usability and performance.


Gemini Docs MCP Server

Description

This project implements an MCP server that enables access to documentation for various technologies using the Gemini API with its large context window of 2 million tokens. It is designed primarily for the Roo/Cline environment but should work for any client.

Advantages over web browsing or traditional search engines:

  • Curated knowledge base: Uses specific, curated documentation to avoid junk results and false positives.
  • Overcomes context window limitations: Provides documentation directly so the LLM can access more information than web search alone.
  • Tailored and well-reasoned responses: Provides complex answers considering the entire specification of the technology.

Addresses some issues of traditional Retrieval-Augmented Generation (RAG) systems:

  • No need for chunking: The LLM can access entire documentation at once, avoiding complex chunking strategies.
  • No retriever needed: Gemini API acts as a powerful retriever.
  • No vectorization or vector DBs: Works directly with plain text without similarity search vectors.

Limitations:

  • No real-time updates: Documentation is static and won't reflect the latest changes unless updated manually or automatically.
  • Finite context window: The LLM sees up to 2 million tokens, which may be insufficient for very large documentation sets.
  • Performance: Using Gemini 1.5 Pro with a large documentation load may cause slower responses, especially on the first query.

Features

  • Enables an "ask your docs" interface for learning and debugging across multiple technologies, including obscure ones.
  • Uses Gemini API to answer documentation questions.
  • Supports multiple query tools:
    • can_x_be_done: Checks if a specific task can be done in a technology.
    • hints_for_problem: Provides hints for solving a problem.
    • is_this_good_practice: Evaluates if a code snippet follows best practices.
    • how_to_do_x: Provides examples and alternatives for tasks.
  • Includes a logging system for debugging (enabled with --verbose flag).

Getting Started

Installing via Smithery

To install Gemini Docs Server for Claude Desktop automatically via Smithery:

npx -y @smithery/cli install @M-Gonzalo/cosa-sai --client claude

The MCP server is automatically started and managed by the client. Enable it by configuring your settings file (e.g., ~/.config/Code/User/globalStorage/rooveterinaryinc.roo-cline/settings/cline_mcp_settings.json).

Example configuration:

{
  "command": "bun",
  "args": [
    "--watch",
    "path/to/repo/cosa-sai-mcp/src/index.ts",
    "--verbose"
  ],
  "env": {
    "GEMINI_API_KEY": "<your_gemini_api_key>"
  },
  "disabled": false,
  "alwaysAllow": [
    "can_x_be_done",
    "hints_for_problem",
    "is_this_good_practice",
    "how_to_do_x"
  ],
  "timeout": 60
}

Procuring and Sanitizing the Knowledge Base

You must manually obtain the knowledge base documentation from public repositories, websites, or other methods.

Optionally, clean the documentation by removing styling and unnecessary content.

Basic tools:

  • Naive Scraper:
wget --mirror --convert-links --adjust-extension --page-requisites --no-parent --directory-prefix=./local_copy --no-verbose --show-progress $1
  • Basic HTML to Markdown-ish Converter:
#!/bin/bash

directory="${1:-.}"
output_file="${2:-concatenated.md}"

echo "Concatenating files in '$directory' into '$output_file'..."

truncate -s 0 "$output_file"

find "$directory" -type f -name '*.html' | while IFS= read -r file; do
    echo "=== ${file#./} ===" >> "$output_file"
    cat "$file" \
    | grep -v 'base64' \
    | html2markdown >> "$output_file"
    echo -e "\n" >> "$output_file"
done

echo "Done! Output saved to '$output_file'"

Usage

The server provides the following tools:

  • can_x_be_done
    • Input: docs, prompt, x, technology
    • Output: success, data
  • hints_for_problem
    • Input: docs, prompt, problem, context, environment
    • Output: success, data
  • is_this_good_practice
    • Input: docs, prompt, snippet, context
    • Output: success, data
  • how_to_do_x
    • Input: docs, prompt, x, technology
    • Output: success, data

Contributing

Contributions are welcome!

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix.
  3. Make your changes and commit them with descriptive messages.
  4. Submit a pull request.

License

This project is licensed under the MIT License.

Disclaimer

This is an early version and may contain bugs and limitations. Please report issues and suggest improvements or features.