Skip to main content
Glama
harmitprajapati2006

MCP Docs Intelligence Server

README.md
# ๐Ÿ“š MCP Docs Intelligence Server

<p align="center">

**An asynchronous Model Context Protocol (MCP) server for searching, extracting, cleaning, and answering questions from official AI & Python ecosystem documentation.**

<br/>

<img src="https://img.shields.io/badge/Python-3.11%2B-3776AB?style=for-the-badge&logo=python&logoColor=white" alt="Python"/>
<img src="https://img.shields.io/badge/MCP-FastMCP-6A4C93?style=for-the-badge" alt="MCP"/>
<img src="https://img.shields.io/badge/LLM-Groq-FF4F00?style=for-the-badge" alt="Groq"/>
<img src="https://img.shields.io/badge/Search-Serper-4285F4?style=for-the-badge" alt="Serper"/>
<img src="https://img.shields.io/badge/Async-httpx-005571?style=for-the-badge" alt="Async HTTP"/>
<img src="https://img.shields.io/badge/License-MIT-green?style=for-the-badge" alt="MIT"/>

</p>

<p align="center">
  <em>Ask a question. Find the official docs. Clean the content. Ground the answer.</em>
</p>

---

## โœฆ Overview

**MCP Docs Intelligence Server** is a lightweight asynchronous documentation intelligence system built around the **Model Context Protocol (MCP)**.

Instead of asking an LLM to answer from potentially stale or incomplete internal knowledge, this project dynamically retrieves information from the **official documentation** of supported libraries and uses that documentation as the grounding context for the final response.

The system combines:

- **FastMCP** โ€” MCP server and tool interface
- **Serper** โ€” web search restricted to official documentation domains
- **Trafilatura** โ€” extraction and cleaning of useful page content
- **Groq** โ€” fast LLM inference
- **GPT-OSS-20B** โ€” response generation
- **httpx** โ€” asynchronous web requests
- **Python async/await** โ€” non-blocking architecture
- **python-dotenv** โ€” environment-based configuration

The result is a clean pipeline that transforms:

```text
Natural Language Query
        โ†“
Official Documentation Search
        โ†“
Documentation Retrieval
        โ†“
HTML โ†’ Clean Text
        โ†“
Context Grounding
        โ†“
Groq LLM
        โ†“
Human-readable Answer
```

---

# ๐Ÿš€ Why This Project?

Traditional documentation workflows often look like this:

```text
Search Google
     โ†“
Open multiple tabs
     โ†“
Read long documentation pages
     โ†“
Find the relevant section
     โ†“
Understand the implementation
     โ†“
Write the answer
```

This project compresses that workflow into a single intelligent interface:

```text
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚   Developer Query   โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                               โ”‚
                               โ–ผ
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚     MCP Client      โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                               โ”‚
                               โ–ผ
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚   FastMCP Server    โ”‚
                    โ”‚      get_docs()     โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                               โ”‚
                               โ–ผ
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚   Serper Search     โ”‚
                    โ”‚ Official Docs Only  โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                               โ”‚
                               โ–ผ
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚   Documentation     โ”‚
                    โ”‚      Pages          โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                               โ”‚
                               โ–ผ
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚    Trafilatura      โ”‚
                    โ”‚ HTML โ†’ Clean Text   โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                               โ”‚
                               โ–ผ
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚  Grounded Context   โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                               โ”‚
                               โ–ผ
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚       Groq          โ”‚
                    โ”‚   GPT-OSS-20B       โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                               โ”‚
                               โ–ผ
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚   Final Answer +    โ”‚
                    โ”‚       Sources       โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
```

---

# โœจ Key Features

| Feature | Description |
|---|---|
| ๐Ÿ”Œ **MCP-native architecture** | Documentation retrieval is exposed as an MCP tool |
| โšก **Async-first** | Uses asynchronous HTTP and MCP execution |
| ๐ŸŒ **Official documentation search** | Searches within trusted documentation domains |
| ๐Ÿงน **HTML cleaning** | Converts complex web pages into usable text |
| ๐Ÿง  **Context-grounded generation** | LLM answers are constrained to retrieved documentation |
| ๐Ÿ”— **Source preservation** | Source URLs are retained in the final response |
| ๐Ÿค– **Groq inference** | Fast model inference through Groq |
| ๐Ÿงฉ **Library-aware queries** | Supports different documentation ecosystems |
| ๐Ÿ› ๏ธ **Simple extensibility** | New libraries can be added through configuration |
| ๐Ÿ” **Environment-based secrets** | API keys are loaded through `.env` |
| ๐Ÿ’ป **CLI-friendly** | User can submit queries directly from the terminal |

---

# ๐Ÿ—๏ธ System Architecture

```mermaid
flowchart TB

    U["๐Ÿ‘จโ€๐Ÿ’ป User"]

    C["๐Ÿ–ฅ๏ธ MCP Client<br/>client.py"]

    M["๐Ÿ”Œ FastMCP Server<br/>mcp_server.py"]

    S["๐Ÿ”Ž Serper API"]

    D["๐Ÿ“– Official Documentation"]

    T["๐Ÿงน Trafilatura<br/>HTML Extraction"]

    CTX["๐Ÿ“ฆ Clean Documentation Context"]

    G["โšก Groq API<br/>GPT-OSS-20B"]

    A["๐Ÿ’ฌ Grounded Answer"]

    U --> C
    C --> M
    M --> S
    S --> D
    D --> T
    T --> CTX
    CTX --> C
    C --> G
    G --> A
    A --> U
```

---

# ๐Ÿ”„ End-to-End Request Flow

```mermaid
sequenceDiagram

    actor User
    participant Client as MCP Client
    participant MCP as FastMCP Server
    participant Serper as Serper Search API
    participant Docs as Official Docs
    participant Extractor as Trafilatura
    participant Groq as Groq LLM

    User->>Client: Enter query + library

    Client->>MCP: call_tool("get_docs")

    MCP->>Serper: Search official documentation

    Serper-->>MCP: Search results

    loop Top documentation results
        MCP->>Docs: GET documentation page
        Docs-->>MCP: HTML content
        MCP->>Extractor: Extract readable text
        Extractor-->>MCP: Clean documentation
    end

    MCP-->>Client: Documentation context + sources

    Client->>Groq: Generate answer from context

    Groq-->>Client: Grounded response

    Client-->>User: Final answer + sources
```

---

# ๐Ÿง  Core Design Principle

The system follows a simple but important principle:

> **Retrieve first. Generate second.**

The LLM is not directly responsible for discovering documentation.

Instead:

```text
          SEARCH
             โ†“
       RETRIEVE DOCS
             โ†“
       CLEAN CONTENT
             โ†“
      BUILD CONTEXT
             โ†“
        GENERATE
```

This separation makes the system easier to reason about and reduces the possibility of unsupported answers.

---

# ๐Ÿงฉ Supported Libraries

The current implementation supports:

| Library | Documentation Domain |
|---|---|
| ๐Ÿฆœ LangChain | `python.langchain.com/docs` |
| ๐Ÿฆ™ LlamaIndex | `docs.llamaindex.ai/en/stable` |
| ๐ŸŸข OpenAI | `platform.openai.com/docs` |
| โšก uv | `docs.astral.sh/uv` |

The mapping is maintained in `mcp_server.py`:

```python
docs_urls = {
    "langchain": "python.langchain.com/docs",
    "llama-index": "docs.llamaindex.ai/en/stable",
    "openai": "platform.openai.com/docs",
    "uv": "docs.astral.sh/uv",
}
```

Adding a new documentation source is intentionally simple.

Example:

```python
docs_urls = {
    "langchain": "python.langchain.com/docs",
    "llama-index": "docs.llamaindex.ai/en/stable",
    "openai": "platform.openai.com/docs",
    "uv": "docs.astral.sh/uv",
    "fastapi": "fastapi.tiangolo.com",
}
```

---

# ๐Ÿ“ Project Structure

```text
MCP-Docs-Intelligence/
โ”‚
โ”œโ”€โ”€ ๐Ÿ“„ mcp_server.py
โ”‚   โ””โ”€โ”€ MCP server + documentation retrieval tool
โ”‚
โ”œโ”€โ”€ ๐Ÿ“„ client.py
โ”‚   โ””โ”€โ”€ User-facing MCP client
โ”‚
โ”œโ”€โ”€ ๐Ÿ“„ utils.py
โ”‚   โ””โ”€โ”€ HTML extraction + Groq LLM utility
โ”‚
โ”œโ”€โ”€ ๐Ÿ“„ pyproject.toml
โ”‚   โ””โ”€โ”€ Project metadata and dependencies
โ”‚
โ”œโ”€โ”€ ๐Ÿ“„ requirements.txt
โ”‚   โ””โ”€โ”€ pip-compatible dependency list
โ”‚
โ”œโ”€โ”€ ๐Ÿ“„ README.md
โ”‚   โ””โ”€โ”€ Project documentation
โ”‚
โ”œโ”€โ”€ ๐Ÿ“„ .env
โ”‚   โ””โ”€โ”€ Local API credentials
โ”‚
โ”œโ”€โ”€ ๐Ÿ“„ .gitignore
โ”‚   โ””โ”€โ”€ Files excluded from Git
โ”‚
โ””โ”€โ”€ ๐Ÿ“ .venv/
    โ””โ”€โ”€ Python virtual environment
```

---

# ๐Ÿ”ง Technology Stack

## FastMCP

FastMCP provides the MCP server abstraction and exposes:

```python
@mcp.tool()
async def get_docs(query: str, library: str):
```

This makes documentation retrieval available as a reusable MCP tool.

---

## Serper

Serper is used for web discovery.

The search query is restricted to the selected documentation domain:

```python
query = f"site:{docs_urls[library]} {query}"
```

Example:

```text
site:docs.astral.sh/uv How to publish a package with uv
```

This keeps the retrieval focused on the selected documentation ecosystem.

---

## Trafilatura

Documentation pages contain navigation, scripts, menus, advertisements, and other irrelevant HTML.

Trafilatura extracts the useful text:

```python
extracted = trafilatura.extract(
    html,
    include_comments=False,
    include_tables=False,
    favor_recall=False,
)
```

Conceptually:

```text
Raw HTML
   โ”‚
   โ”œโ”€โ”€ Navigation
   โ”œโ”€โ”€ Scripts
   โ”œโ”€โ”€ CSS
   โ”œโ”€โ”€ Footer
   โ”œโ”€โ”€ Menus
   โ””โ”€โ”€ Documentation Content
                โ”‚
                โ–ผ
         Trafilatura
                โ”‚
                โ–ผ
       Clean Documentation
```

---

## Groq

The final answer is generated using Groq's API.

Current model:

```text
openai/gpt-oss-20b
```

The model receives:

```text
System Instructions
        +
User Query
        +
Retrieved Documentation Context
```

and produces the final human-readable answer.

---

# ๐Ÿ” Environment Variables

Create a `.env` file in the project root:

```env
GROQ_API_KEY=your_groq_api_key
SERPER_API_KEY=your_serper_api_key
```

### Required credentials

| Variable | Purpose |
|---|---|
| `GROQ_API_KEY` | Authenticates requests to Groq |
| `SERPER_API_KEY` | Authenticates web search requests |

Never commit your `.env` file.

Add this to `.gitignore`:

```gitignore
.env
.venv/
__pycache__/
*.pyc
```

---

# ๐Ÿ“ฆ Installation

## 1. Clone the repository

```bash
git clone https://github.com/your-username/mcp-docs-intelligence.git
cd mcp-docs-intelligence
```

---

## 2. Create a virtual environment

### Windows

```powershell
python -m venv .venv
.venv\Scripts\activate
```

### Linux / macOS

```bash
python3 -m venv .venv
source .venv/bin/activate
```

---

## 3. Install dependencies

```bash
pip install -r requirements.txt
```

Or with `uv`:

```bash
uv sync
```

---

# ๐Ÿ“‹ Dependencies

The project requires:

```text
fastmcp>=2.12.2
groq>=0.31.1
httpx>=0.28.1
python-dotenv>=1.1.1
trafilatura>=2.0.0
mcp>=1.16.0
```

---

# โ–ถ๏ธ Running the Project

Start the client:

```bash
python client.py
```

The client will ask:

```text
Enter your documentation query:
```

Example:

```text
Enter your documentation query:
How do I publish a Python package with uv?

Enter library (langchain/openai/llama-index/uv):
uv
```

The client automatically launches the MCP server and executes the request.

---

# ๐Ÿ”Ž Example Request

### Input

```text
Query:
How do I publish a package with uv on GitLab?

Library:
uv
```

### Internal processing

```text
1. Receive query
       โ†“
2. Select uv documentation
       โ†“
3. Build site-restricted search
       โ†“
4. Query Serper
       โ†“
5. Retrieve documentation pages
       โ†“
6. Extract readable text
       โ†“
7. Return context to client
       โ†“
8. Send context to Groq
       โ†“
9. Generate answer
       โ†“
10. Display sources
```

---

# ๐Ÿง  Grounded Answer Strategy

The client uses a system prompt similar to:

```text
Answer ONLY using the provided context.
If information is missing, say you don't know.
Keep every 'SOURCE:' line exactly.
List sources at the end.
```

This creates a clear separation between:

```text
Retrieved Facts
      โ”‚
      โ–ผ
Documentation Context
      โ”‚
      โ–ผ
LLM Reasoning / Response Formatting
```

The model is instructed not to invent information that does not exist in the supplied context.

---

# ๐Ÿ”Œ MCP Tool

The server exposes one primary tool:

```text
get_docs(query, library)
```

### Parameters

| Parameter | Type | Description |
|---|---|---|
| `query` | `string` | Documentation question |
| `library` | `string` | Supported documentation ecosystem |

### Example tool call

```json
{
  "query": "How do I create a virtual environment with uv?",
  "library": "uv"
}
```

### Example response structure

```text
SOURCE: https://docs.astral.sh/uv/...

Relevant documentation content...

SOURCE: https://docs.astral.sh/uv/...

Additional documentation content...
```

---

# ๐Ÿ›ก๏ธ Error Handling

The server validates the selected documentation ecosystem:

```python
if library not in docs_urls:
    raise ValueError(
        f"Library {library} not supported by this tool"
    )
```

The search request also raises HTTP errors when the external API fails:

```python
response.raise_for_status()
```

This prevents silent failures and makes external API problems visible.

---

# โš™๏ธ Async Architecture

The project uses Python's asynchronous execution model.

Web requests use:

```python
async with httpx.AsyncClient() as client:
```

The MCP tool is also asynchronous:

```python
async def get_docs(query: str, library: str):
```

This is important because the application is primarily I/O-bound.

Instead of blocking during network operations:

```text
Application
     โ”‚
     โ”œโ”€โ”€ waiting for search API
     โ”œโ”€โ”€ waiting for docs page
     โ””โ”€โ”€ waiting for another docs page
```

the async architecture allows the runtime to manage I/O efficiently.

---

# ๐Ÿ“Š Request Lifecycle

```mermaid
flowchart LR

    Q["Query"] --> V["Validate Library"]

    V --> S["Build site:<domain> Search"]

    S --> W["Serper"]

    W --> R["Top Search Results"]

    R --> F["Fetch URLs"]

    F --> C["Clean HTML"]

    C --> X["Build Context"]

    X --> L["Groq"]

    L --> O["Grounded Answer"]
```

---

# ๐Ÿงฑ Component Responsibilities

| Component | Responsibility |
|---|---|
| `mcp_server.py` | Search, retrieval, cleaning orchestration and MCP tool exposure |
| `client.py` | User interaction, MCP execution and LLM call |
| `utils.py` | HTML extraction and Groq API wrapper |
| `pyproject.toml` | Package metadata and dependencies |
| `requirements.txt` | pip installation support |
| `.env` | Secrets and configuration |

---

# ๐Ÿงช Example Queries

### uv

```text
How do I create and manage a virtual environment using uv?
```

### LangChain

```text
How do I create a tool-calling agent in LangChain?
```

### LlamaIndex

```text
How do I create a vector index in LlamaIndex?
```

### OpenAI

```text
How do I use structured outputs with the OpenAI API?
```

---

# ๐Ÿ”„ Extending the Server

The architecture is deliberately simple to extend.

## Add another documentation source

Update:

```python
docs_urls = {
    "langchain": "python.langchain.com/docs",
    "llama-index": "docs.llamaindex.ai/en/stable",
    "openai": "platform.openai.com/docs",
    "uv": "docs.astral.sh/uv",
}
```

Example:

```python
"fastapi": "fastapi.tiangolo.com"
```

The rest of the retrieval pipeline remains unchanged.

---

# ๐Ÿ—บ๏ธ Future Roadmap

The current implementation establishes the foundation for a much larger documentation intelligence platform.

### Phase 1 โ€” Current

```text
โœ… MCP server
โœ… Async retrieval
โœ… Official documentation search
โœ… HTML extraction
โœ… Groq integration
โœ… Source preservation
โœ… Interactive client
```

### Phase 2 โ€” Retrieval Intelligence

```text
โฌœ Multi-result ranking
โฌœ Duplicate URL removal
โฌœ Query rewriting
โฌœ Better document chunking
โฌœ Relevance scoring
โฌœ Retry / timeout strategy
```

### Phase 3 โ€” Advanced RAG

```text
โฌœ Embedding-based retrieval
โฌœ Vector database
โฌœ Semantic search
โฌœ Reranking
โฌœ Persistent document cache
โฌœ Citation-aware generation
```

### Phase 4 โ€” Developer Platform

```text
โฌœ Web UI
โฌœ IDE integration
โฌœ VS Code extension
โฌœ Documentation diffing
โฌœ Version-aware documentation
โฌœ API migration assistant
โฌœ Code generation from docs
```

---

# ๐Ÿ”ฎ Possible Future Architecture

```mermaid
flowchart TB

    USER["Developer"]

    UI["Web / IDE / CLI"]

    MCP["MCP Gateway"]

    QUERY["Query Understanding"]

    SEARCH["Hybrid Retrieval"]

    WEB["Official Documentation"]

    CACHE["Document Cache"]

    VECTOR["Vector Database"]

    RERANK["Reranker"]

    CONTEXT["Context Builder"]

    LLM["Groq / LLM"]

    CITE["Citation Engine"]

    ANSWER["Final Developer Answer"]

    USER --> UI
    UI --> MCP
    MCP --> QUERY

    QUERY --> SEARCH

    SEARCH --> WEB
    SEARCH --> CACHE
    SEARCH --> VECTOR

    WEB --> CONTEXT
    CACHE --> CONTEXT
    VECTOR --> RERANK
    RERANK --> CONTEXT

    CONTEXT --> LLM
    LLM --> CITE
    CITE --> ANSWER
    ANSWER --> USER
```

---

# ๐ŸŽฏ Design Philosophy

This project is built around four principles:

### 1. Trust the source

Prefer authoritative documentation rather than arbitrary online content.

### 2. Retrieve before generating

The model should work from current retrieved context rather than relying entirely on memorized knowledge.

### 3. Keep components replaceable

Search, extraction, MCP, and LLM layers are separated so individual components can evolve independently.

### 4. Make the system developer-friendly

The final interface should feel like asking a senior developer who knows where the official documentation is.

---

# ๐Ÿ”’ Security Considerations

### API keys

Never hardcode credentials:

```python
os.getenv("GROQ_API_KEY")
os.getenv("SERPER_API_KEY")
```

### Environment files

Do not commit:

```text
.env
```

### External content

Documentation retrieved from the web should be treated as external/untrusted input. Future versions should consider:

- content size limits
- URL allowlists
- response validation
- redirect validation
- request retry policies
- rate limiting
- malicious content filtering

---

# ๐Ÿงฐ Troubleshooting

## `ModuleNotFoundError`

Install dependencies:

```bash
pip install -r requirements.txt
```

---

## `GROQ_API_KEY` error

Verify `.env` contains:

```env
GROQ_API_KEY=your_key_here
```

and that the project is being executed from the correct directory.

---

## `SERPER_API_KEY` error

Verify:

```env
SERPER_API_KEY=your_key_here
```

---

## MCP server appears to hang

Running:

```bash
python mcp_server.py
```

directly may appear to do nothing.

That is expected for a stdio MCP server because it waits for an MCP client to communicate with it.

Normally run:

```bash
python client.py
```

instead.

---

## No documentation results

Check:

1. The selected library is supported.
2. The Serper API key is valid.
3. The documentation domain is correct.
4. Internet connectivity is available.

---

# ๐Ÿ“œ Environment Example

```env
# Search provider
SERPER_API_KEY=your_serper_api_key

# LLM provider
GROQ_API_KEY=your_groq_api_key
```

---

# ๐Ÿ“Œ Minimal API Flow

```text
client.py
   โ”‚
   โ”‚ call_tool()
   โ–ผ
mcp_server.py
   โ”‚
   โ”‚ search_web()
   โ–ผ
Serper
   โ”‚
   โ”‚ documentation URLs
   โ–ผ
fetch_url()
   โ”‚
   โ”‚ raw HTML
   โ–ผ
clean_html_to_txt()
   โ”‚
   โ”‚ clean text
   โ–ผ
MCP response
   โ”‚
   โ–ผ
Groq GPT-OSS-20B
   โ”‚
   โ–ผ
Final answer
```

---

# ๐Ÿง‘โ€๐Ÿ’ป Development

For local development:

```bash
git clone https://github.com/your-username/mcp-docs-intelligence.git

cd mcp-docs-intelligence

python -m venv .venv
```

Activate the environment and install dependencies:

```bash
pip install -r requirements.txt
```

Then configure `.env` and run:

```bash
python client.py
```

---

# โœ… Project Checklist

```text
[โœ“] MCP server implemented
[โœ“] FastMCP tool exposed
[โœ“] Async web requests
[โœ“] Serper integration
[โœ“] Official documentation restriction
[โœ“] HTML extraction
[โœ“] Groq integration
[โœ“] GPT-OSS-20B support
[โœ“] Environment variable configuration
[โœ“] Interactive query input
[โœ“] Source preservation
[โœ“] GitHub documentation
[โœ“] Architecture diagrams
```

---

# ๐ŸŒŸ What Makes This Project Different?

This is not simply a web scraper.

It is a small **documentation intelligence layer** that sits between a developer and the web.

The architecture creates a clear chain of responsibility:

```text
Developer
    โ†“
Question
    โ†“
MCP
    โ†“
Retrieval
    โ†“
Official Source
    โ†“
Content Extraction
    โ†“
Context
    โ†“
LLM
    โ†“
Answer
    โ†“
Source
```

That separation is the foundation for turning this prototype into a larger **developer knowledge infrastructure**.

---

# ๐Ÿ“ˆ Performance Characteristics

The application is primarily I/O-bound.

Potential latency contributors include:

```text
Serper Search
     +
Documentation HTTP Requests
     +
HTML Extraction
     +
LLM Generation
```

The use of asynchronous HTTP requests reduces unnecessary blocking during network operations.

Future performance improvements can include:

```text
Caching
Parallel fetching
Connection pooling
Result deduplication
Context compression
Persistent document storage
```

---

# ๐Ÿค Contributing

Contributions are welcome.

A typical contribution workflow:

```bash
git checkout -b feature/my-feature

# Make your changes

git add .

git commit -m "feat: add documentation source"

git push origin feature/my-feature
```

Then open a pull request.

For larger architectural changes, document:

- Problem
- Proposed solution
- Architectural impact
- Backward compatibility
- Testing strategy

---

# ๐Ÿ“„ License

This project is licensed under the **MIT License**.

Add a `LICENSE` file containing the standard MIT License text before publishing the repository.

---

# โญ Acknowledgements

Built using excellent open-source and developer infrastructure technologies:

- **Model Context Protocol**
- **FastMCP**
- **Groq**
- **Serper**
- **Trafilatura**
- **httpx**
- **Python**

---

# ๐Ÿงญ Final Architecture Snapshot

```text
                         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                         โ”‚      DEVELOPER     โ”‚
                         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                   โ”‚
                                   โ–ผ
                         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                         โ”‚    MCP CLIENT      โ”‚
                         โ”‚     client.py      โ”‚
                         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                   โ”‚
                                   โ–ผ
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚       FASTMCP SERVER       โ”‚
                    โ”‚        mcp_server.py       โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                  โ”‚
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚                           โ”‚
                    โ–ผ                           โ–ผ
          โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
          โ”‚   SERPER API    โ”‚         โ”‚  DOCUMENTATION  โ”‚
          โ”‚  Web Discovery  โ”‚โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ถโ”‚     PAGES       โ”‚
          โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                               โ”‚
                                               โ–ผ
                                     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                                     โ”‚    TRAFILATURA     โ”‚
                                     โ”‚   Content Cleaner  โ”‚
                                     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                               โ”‚
                                               โ–ผ
                                     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                                     โ”‚  CONTEXT BUILDER   โ”‚
                                     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                               โ”‚
                                               โ–ผ
                                     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                                     โ”‚       GROQ         โ”‚
                                     โ”‚    GPT-OSS-20B     โ”‚
                                     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                               โ”‚
                                               โ–ผ
                                     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                                     โ”‚   GROUNDED ANSWER  โ”‚
                                     โ”‚    + SOURCES       โ”‚
                                     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
```

---

<p align="center">

### โšก Search. Extract. Ground. Answer.

**MCP Docs Intelligence Server**

</p>