MyInvois MCP RAG
by HengYpinn
README.md
# MyInvois MCP RAG
An end-to-end pipeline for scraping and indexing MyInvois SDK documentation.
Source of truth: https://sdk.myinvois.hasil.gov.my
## Features
- **Generative RAG**: Provides intelligent, documentation-grounded answers using a configurable LLM (Gemini by default).
- **MCP Server**: Implements the Model Context Protocol (MCP) for native integration with Claude Desktop, Cursor, and other AI clients.
- **Sitemap-based Scraping**: Automatically discovers and cleans content using `trafilatura`.
- **Change Detection**: Efficient incremental updates via content hashing.
- **FastAPI Search**: Standard REST interface for custom integrations.
## Project Structure
```text
data/ # Local cache for raw and processed docs (gitignored)
sample_data/ # Tiny synthetic snapshot for structure reference
scripts/ # Orchestration scripts
sync_docs.py # Main script to scrape and index
src/
mcp/ # MCP Server implementation
api/ # FastAPI service
indexer/ # LlamaIndex & Qdrant logic
scraper/ # Scraping pipeline
common/ # Configuration & Shared utilities
.env # API Keys & Local settings
docker-compose.yml # Local Qdrant setup
requirements.txt # Python dependencies
qdrant_storage/ # Local Qdrant data (gitignored)
```
## Setup Instructions
### 1. Prerequisites
- Python 3.9+
- Docker (for Qdrant)
- An API key for your selected LLM provider (Gemini/OpenAI/Anthropic) or a local Ollama setup
### 2. Install & Start (and Regenerate Later)
```powershell
pip install -r requirements.txt
docker-compose up -d
# Run once to pull documentation
$env:PYTHONPATH = "."; python scripts/sync_docs.py
```
Full data is generated locally. This writes to `data/` and `qdrant_storage/`, which are gitignored. A tiny synthetic sample is included under `sample_data/` for reference. To refresh later, rerun the same command (start Qdrant first if needed).
### 3. Usage Modes
#### A. MCP Mode (Recommended for AI Apps)
Integrate this system directly into your AI assistant (e.g., Cline). Add this to your `mcp_config.json`:
```json
{
"mcpServers": {
"myinvois-mcp-rag": {
"command": "python",
"args": ["C:/path/to/MyInvois MCP RAG/src/mcp/server.py"],
"env": {
"PYTHONPATH": "C:/path/to/MyInvois MCP RAG",
"GOOGLE_API_KEY": "your_key_here"
}
}
}
}
```
#### B. API Mode (For REST/Copilot Chat)
Start the FastAPI server:
```powershell
$env:PYTHONPATH = "."; python src/api/main.py
```
- **Ask Q&A**: `GET /ask?q=How do I validate a TIN?`
- **Search Docs**: `GET /search?q=login token`
### 4. API Examples
Search:
```bash
curl "http://localhost:8000/search?q=invoice%20validation"
```
Example response:
```json
{
"query": "invoice validation",
"results": [
{
"text": "...snippet...",
"source_url": "https://sdk.myinvois.hasil.gov.my/...",
"score": 0.78,
"metadata": { "file_name": "...", "url": "...", "title": "..." }
}
],
"answer": null,
"processing_time_ms": 123.45
}
```
Ask:
```bash
curl "http://localhost:8000/ask?q=What%20is%20MyInvois%3F"
```
Example response:
```json
{
"query": "What is MyInvois?",
"results": [
{
"text": "...snippet...",
"source_url": "https://sdk.myinvois.hasil.gov.my/...",
"score": 0.81,
"metadata": { "file_name": "...", "url": "...", "title": "..." }
}
],
"answer": "...synthesized answer...",
"processing_time_ms": 156.12
}
```
### 5. Model Configuration
Set these in `.env` to switch providers:
- `LLM_PROVIDER`: `gemini` | `openai` | `anthropic` | `ollama`
- `LLM_MODEL`: provider-specific model name (e.g., `gpt-4o-mini`)
- `EMBEDDING_PROVIDER`: `fastembed` | `openai` | `ollama`
- `EMBEDDING_MODEL`: provider-specific embedding model (e.g., `text-embedding-3-small`)
### 6. Scheduling (Optional)
GitHub Actions (manual): The workflow in `.github/workflows/monthly-sync.yml` is manual-only and has artifact upload disabled by default. If you enable artifact upload in a public repo, those artifacts are public.
Windows Task Scheduler:
```powershell
# Action: Start a program
# Program/script: python
# Add arguments: scripts/sync_docs.py
# Start in: C:\path\to\MyInvois MCP RAG
```
Make sure Docker is running and Qdrant is up (`docker compose up -d`), and set API keys via system/user environment variables or a wrapper script.
Linux/macOS cron:
```bash
0 0 1 * * cd /path/to/MyInvois\ MCP\ RAG && docker compose up -d && python scripts/sync_docs.py
```
Cron uses the machine timezone. Ensure your API keys are available in the cron environment.
## Key Implementation Details
- **LLM**: Configurable (Gemini/OpenAI/Anthropic/Ollama); default `models/gemini-2.5-flash`
- **Embeddings**: Configurable (FastEmbed/OpenAI/Ollama); default `BAAI/bge-small-en-v1.5`
- **Vector DB**: Qdrant (Local)
## License
MIT License. See `LICENSE`.
This server cannot be deployed
Maintenance
ActivityInactive
ResponsivenessNo recent community issues