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>This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo issues