Skip to main content
Glama
manojsarkar457

Document Assistant

πŸ€– AI Document Scanner Using RAG & MCP Tools with Python

An intelligent AI Document Scanner and Assistant built with Python that allows users to upload documents, search their contents, and ask questions using Retrieval-Augmented Generation (RAG) and Model Context Protocol (MCP) tools.

The application combines document processing, text chunking, vector embeddings, FAISS similarity search, MCP tools, and Large Language Models (LLMs) to provide contextual answers from uploaded documents.


πŸ“Œ Project Overview

Traditional document search often depends on exact keyword matching. This project uses semantic search through vector embeddings, allowing users to ask questions naturally.

The system:

  1. Accepts documents from the user.

  2. Extracts text from the documents.

  3. Splits the text into smaller chunks.

  4. Converts chunks into vector embeddings.

  5. Stores embeddings in a FAISS vector database.

  6. Retrieves relevant chunks when the user asks a question.

  7. Uses an LLM to generate an answer based on the retrieved context.

  8. Uses MCP tools to expose document search and analysis capabilities to an AI agent.


Related MCP server: MinerU Document Explorer

✨ Features

  • πŸ“„ PDF document processing

  • πŸ“Š CSV and Excel data analysis

  • πŸ” Semantic document search

  • 🧠 Retrieval-Augmented Generation (RAG)

  • πŸ—‚οΈ FAISS vector database

  • πŸ€– LLM-powered question answering

  • πŸ”Œ Model Context Protocol (MCP) tool integration

  • πŸ’¬ Interactive document chat

  • 🌐 Streamlit web interface

  • πŸ“‘ Document chunking and embeddings

  • πŸ”Ž Context-aware information retrieval

  • 🧩 Modular project architecture

  • πŸ” Environment-variable based API key configuration


πŸ—οΈ Architecture

                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚        User         β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                               β”‚
                               β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚    Streamlit UI     β”‚
                    β”‚       app.py        β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                               β”‚
                               β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚   Document Loader   β”‚
                    β”‚  PDF / CSV / Excel  β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                               β”‚
                               β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚ Text Splitting &    β”‚
                    β”‚   Preprocessing     β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                               β”‚
                               β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚   Embedding Model   β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                               β”‚
                               β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚  FAISS Vector Store β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                               β”‚
                         User Question
                               β”‚
                               β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚ Semantic Retrieval  β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                               β”‚
                               β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚     MCP Tools       β”‚
                    β”‚ PDF / CSV / Excel   β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                               β”‚
                               β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚    RAG Pipeline     β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                               β”‚
                               β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚        LLM          β”‚
                    β”‚ Gemini / Other LLM  β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                               β”‚
                               β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚     AI Response     β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ”„ RAG Workflow

1. Document Loading

Documents are loaded using appropriate Python libraries.

  • PDF β†’ PyPDF

  • Excel β†’ Pandas / OpenPyXL

  • CSV β†’ Pandas

2. Text Splitting

Large documents are divided into smaller chunks using a text splitter. This improves retrieval accuracy and keeps prompts manageable.

3. Embeddings

Each text chunk is converted into a numerical vector representing its semantic meaning.

Document Text
      |
      v
Embedding Model
      |
      v
Numerical Vector

4. Vector Storage

The generated vectors are stored in FAISS, enabling efficient similarity-based retrieval.

When the user asks a question, the question is converted into an embedding and compared against stored document vectors. The most relevant chunks are retrieved.

6. Response Generation

The retrieved context is passed to the LLM along with the user's question. The model generates an answer based on the retrieved information.


πŸ”Œ MCP Integration

The project uses Model Context Protocol (MCP) to expose document-related functionality as tools that an AI agent can call.

Example MCP Tools

search_pdf(question)
find_employee(name)
analyze_csv(question)

This allows an AI system to retrieve information from documents or analyze structured data when required.

Example MCP Workflow

User
  |
  v
"Find the details of Manoj Sarkar."
  |
  v
AI Agent
  |
  v
MCP Tool
find_employee("Manoj Sarkar")
  |
  v
Vector / Document Search
  |
  v
Relevant Information
  |
  v
LLM
  |
  v
Final Answer

πŸ› οΈ Technologies Used

Technology

Purpose

Python

Core programming language

Streamlit

Web application interface

LangChain

RAG and document processing

FAISS

Vector similarity search

MCP

AI tool integration

Google Gemini

Large Language Model

PyPDF

PDF text extraction

Pandas

Data processing

OpenPyXL

Excel file processing

Vector Embeddings

Semantic representation

python-dotenv

Environment variable management


πŸ“ Project Structure

AI-Document-Scanner/
β”‚
β”œβ”€β”€ app.py
β”œβ”€β”€ server.py
β”œβ”€β”€ client.py
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ README.md
β”‚
β”œβ”€β”€ assistants/
β”‚   β”œβ”€β”€ pdf_assistant.py
β”‚   β”œβ”€β”€ excel_assistant.py
β”‚   β”œβ”€β”€ csv_assistant.py
β”‚   └── docx_assistant.py
β”‚
β”œβ”€β”€ utils/
β”‚   β”œβ”€β”€ loaders.py
β”‚   β”œβ”€β”€ splitter.py
β”‚   β”œβ”€β”€ vectorstore.py
β”‚   β”œβ”€β”€ rag_pipeline.py
β”‚   β”œβ”€β”€ llm_provider.py
β”‚   └── prompts.py
β”‚
β”œβ”€β”€ mcp_tools/
β”‚   β”œβ”€β”€ pdf_tool.py
β”‚   β”œβ”€β”€ rag_tool.py
β”‚   β”œβ”€β”€ excel_tool.py
β”‚   └── csv_tool.py
β”‚
β”œβ”€β”€ data/
β”‚   └── sample_documents/
β”‚
└── .env

The exact files and folders may vary depending on the current implementation.


βš™οΈ Installation

1. Clone the Repository

git clone https://github.com/your-username/AI-Document-Scanner.git
cd AI-Document-Scanner

2. Create a Virtual Environment

Windows

python -m venv venv
venv\Scripts\activate

Linux/macOS

python3 -m venv venv
source venv/bin/activate

3. Install Dependencies

pip install -r requirements.txt

πŸ”‘ Environment Variables

Create a .env file in the project root.

Google Gemini

GOOGLE_API_KEY=your_google_api_key

If your implementation also supports OpenAI:

OPENAI_API_KEY=your_openai_api_key

Important: Never commit your .env file or API keys to GitHub.

Add the following to .gitignore:

.env
venv/
__pycache__/
*.pyc
.faiss/

▢️ Running the Application

Start the Streamlit application:

streamlit run app.py

Then open the application in your browser:

http://localhost:8501

πŸ’‘ Example Questions

After uploading a document, users can ask questions such as:

What is this document about?
Summarize the document.
Who is Manoj Sarkar?
Find the employee with the highest sales.
What is the total revenue?
What are the main points discussed in the document?
Find information related to a specific topic.

πŸ§ͺ Example RAG Pipeline

documents = load_documents(file_path)

chunks = split_documents(documents)

vectorstore = create_vectorstore(chunks)

results = vectorstore.similarity_search(query, k=4)

context = "\n".join(
    document.page_content
    for document in results
)

response = llm.invoke(
    f"""
    Answer the question using the following context:

    {context}

    Question:
    {query}
    """
)

πŸ”Œ Example MCP Tool

A simplified MCP tool can look like:

from mcp.server.fastmcp import FastMCP

mcp = FastMCP("Document Assistant")


@mcp.tool()
def search_pdf(question: str) -> str:
    """Search the uploaded PDF and return relevant information."""

    # Vector search implementation
    return "Relevant document information"

The MCP server exposes this functionality so that an AI client or agent can use it when required.


🎯 Use Cases

This project can be useful for:

  • πŸ“š Research document assistants

  • 🏒 Company knowledge bases

  • πŸ“„ Legal document search

  • πŸŽ“ Educational document analysis

  • πŸ‘¨β€πŸ’Ό HR document assistants

  • πŸ“Š Business report analysis

  • 🧾 Invoice and report processing

  • πŸ“‘ Policy and documentation search

  • πŸ€– AI-powered knowledge management systems


πŸš€ Future Enhancements

  • Multi-document conversational memory

  • DOCX support

  • Image document scanning

  • OCR integration

  • Voice input

  • Source/page citations

  • Chat history

  • User authentication

  • Multi-user support

  • Cloud deployment

  • Advanced agentic workflows

  • Additional MCP tools

  • Database integration

  • Document summarization

  • Hybrid keyword + semantic search

  • Reranking for improved retrieval accuracy


πŸ” Security

For security:

  • Store API keys in .env.

  • Never upload API keys to GitHub.

  • Add .env to .gitignore.

  • Avoid storing sensitive documents in public repositories.

  • Validate uploaded files before processing.


🧠 Key Concepts Demonstrated

This project demonstrates practical knowledge of:

  • Python

  • Generative AI

  • Large Language Models

  • Retrieval-Augmented Generation

  • Vector Databases

  • Semantic Search

  • Embeddings

  • LangChain

  • FAISS

  • Model Context Protocol

  • AI Agents

  • Streamlit

  • Document Processing

  • API Integration


πŸ‘¨β€πŸ’» Author

Manoj Sarkar

B.Tech in Computer Science & Engineering

Interested in Python, Generative AI, Agentic AI, RAG, MCP, and AI-powered applications.


⭐ Support

If you find this project useful, consider giving the repository a ⭐ on GitHub.


πŸ“„ License

This project is intended for educational and development purposes. Add an appropriate license file if you plan to distribute or reuse the project publicly.

A
license - permissive license
-
quality - not tested
C
maintenance

Maintenance

–Maintainers
–Response time
–Release cycle
–Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

View all related MCP servers

Related MCP Connectors

  • Query any docs site via MCP. Submit a URL, ask questions, get cited answers.

  • OCR, transcription, file extraction, and image generation for AI agents via MCP.

  • Search and reason over your Obsidian-style Markdown vault, right from ChatGPT.

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/manojsarkar457/AI-DOCUMENT-SCANNER-USING-RAG-MCP-TOOLS-WITH-PYTHON'

If you have feedback or need assistance with the MCP directory API, please join our Discord server