# Directory Structure
```
├── mcp.json
├── README.md
├── requirements.txt
└── server.py
```
# Files
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
```markdown
# MCP Document QA Server
This is an MCP (Model Context Protocol ) server built to help you **ingest documents** and **ask questions** about them. Powered by the GroundX API, the server enables seamless document parsing and querying.
## 🧠 Features
- **Ingest Tool**: Upload new documents to the server.
- **Answer Tool**: Ask questions and receive context-aware answers based on the ingested documents.
- Built with **FastMCP**, uses the **GroundX API** for document parsing and intelligence.
## 🚀 Getting Started
### 1. Fork the Repository
Start by forking this repository to your own GitHub account.
### 2. Open in Cursor
Open the forked repository in [Cursor](https://www.cursor.sh/).
### 3. Add MCP Integration
- Use the **"Add MCP"** option in Cursor.
- The platform will automatically detect the included `mcp.json` file.
### 4. Tools Available
Once the MCP server is loaded, you will have access to two tools:
- `ingest_documents`: Ingest new documents to the system.
- `answer_query`: Ask questions and get answers based on the ingested documents.
## 🔧 Configuration
### GroundX API Key
Make sure to **add your GroundX API key** in the `server.py` file:
```python
# server.py
GROUNDX_API_KEY = "your_api_key_here"
```
--------------------------------------------------------------------------------
/mcp.json:
--------------------------------------------------------------------------------
```json
{
"mcpServers": {
"eyelevel-rag": {
"command": "C:\\Users\\preet\\Desktop\\Rag_based_MCP\\env\\Scripts\\python.exe",
"args": ["C:\\Users\\preet\\Desktop\\Rag_based_MCP\\server.py"],
"transport": "stdio"
}
}
}
```
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
```
asgiref==3.8.1
async-timeout==4.0.3
asyncio==3.4.3
attrs==23.2.0
autobahn==23.6.2
Automat==22.10.0
beautifulsoup4==4.12.2
cachetools==5.5.2
certifi==2023.7.22
cffi==1.16.0
channels==4.1.0
channels-redis==4.2.0
charset-normalizer==3.2.0
constantly==23.10.4
contourpy==1.3.0
cryptography==42.0.8
cycler==0.12.1
daphne==3.0.2
distlib==0.3.8
Django==5.0.3
django-channels==0.7.0
django-mathfilters==1.0.0
djangorestframework==3.15.1
et-xmlfile==1.1.0
filelock==3.13.3
fonttools==4.54.1
gitdb==4.0.11
GitPython==3.1.40
google-auth==2.38.0
google-auth-oauthlib==1.2.1
gspread==6.2.0
h11==0.14.0
hyperlink==21.0.0
idna==3.4
incremental==22.10.0
kiwisolver==1.4.7
matplotlib==3.9.2
msgpack==1.0.8
numpy==2.1.1
oauthlib==3.2.2
openpyxl==3.1.5
outcome==1.3.0.post0
packaging==24.1
pandas==2.2.3
pdfkit==1.0.0
pillow==10.2.0
platformdirs==4.2.0
plyer==2.1.0
pyasn1==0.6.0
pyasn1_modules==0.4.0
pycparser==2.22
pyOpenSSL==24.1.0
pyparsing==3.1.4
pypdf==3.15.2
PyPDF2==3.0.1
PySocks==1.7.1
python-dateutil==2.9.0.post0
python-decouple==3.8
python-dotenv==1.1.0
pytz==2023.3
redis==5.0.8
requests==2.31.0
requests-oauthlib==2.0.0
rsa==4.9
selenium==4.30.0
service-identity==24.1.0
six==1.16.0
smmap==5.0.1
sniffio==1.3.1
sortedcontainers==2.4.0
soupsieve==2.4.1
sqlparse==0.4.4
trio==0.29.0
trio-websocket==0.12.2
Twisted==24.3.0
twisted-iocpsupport==1.0.4
txaio==23.1.1
typing_extensions==4.12.2
tzdata==2024.1
unzip==1.0.0
urllib3==2.0.4
virtualenv==20.25.1
webdriver-manager==4.0.2
websocket-client==1.8.0
wsproto==1.2.0
zope.interface==6.4.post2
```
--------------------------------------------------------------------------------
/server.py:
--------------------------------------------------------------------------------
```python
import os
from dotenv import load_dotenv
from groundx import GroundX,Document
from mcp.server.fastmcp import FastMCP
load_dotenv(dotenv_path=os.path.join(os.path.dirname(__file__), ".env"))
mcp = FastMCP("eyelevel-rag")
client = GroundX(api_key=os.getenv("GROUNDX_API_KEY"))
@mcp.tool()
def search_doc_for_rag_context(query:str)-> str:
"""Searches and retrieves context from a knowledge base,
in this function we provide with a bucket ID of ground x which
already had uploaded documents uploaded and parsed
Args:
query : The search query provided by user.
Returns:
str:Relative text context that can be used by LLM to answer query
"""
response = client.search.content(
id = 17707,
query=query,
n=10,
)
return response.search.text
@mcp.tool()
def ingest_documents(local_file_path: str) -> str:
"""Apart from just getting info from a single bucket using its id we can also
specify the path for the documants we want to ingest """
file_name = os.path.basename(local_file_path)
client.ingest(
documents = [
Document(
bucket_id=17709,
file_name=file_name,
file_path=local_file_path,
file_type="pdf",
search_data=dict(
key = "value",
),
)
]
)
return f"""Ingested {file_name} into the knowledge basse,will be availbale in few minutes"""
if __name__ == "__main__":
print("Starting MCP server...")
print("Using transport: stdio")
print("Server name: eyelevel-rag")
print("Available tools:")
print("- search_doc_for_rag_context")
print("- ingest_documents")
mcp.run(transport="stdio")
print("MCP server started successfully")
```