Skip to main content
Glama
mahsamb
by mahsamb
README.md
# Ollama MCP Assistant

Ask questions about a **local document** using **Ollama** on your machine. The project exposes document Q&A through an **MCP server** ([FastMCP](https://github.com/jlowin/fastmcp)) and two optional UIs: a lightweight browser page and a Streamlit app.

Includes a synthetic Persian demo document (`context.txt`) about a public library — safe to run immediately after clone.

## Why this project

- **Local-first** — no cloud API keys; runs against Ollama on `localhost:11434`
- **MCP tool** — `ask_ollama` reads `.txt` or `.pdf`, sends context + question to Ollama, returns a Persian answer
- **Persian output** — system prompt enforces Farsi answers grounded in the provided context
- **Two UIs** — stdlib browser UI (`ui.py`) or Streamlit app (`app.py`)
- **CLI client** — `MCP_Client.py` demonstrates calling the MCP server via stdio

## Stack

`Python` · `Ollama` · `FastMCP` · `Streamlit` · `pdfplumber` · `requests`

## Project layout

| File | Description |
|------|-------------|
| [`MCP_Server.py`](MCP_Server.py) | FastMCP server with `ask_ollama` tool and shared chat helper |
| [`MCP_Client.py`](MCP_Client.py) | Async stdio client example (Persian terminal output) |
| [`ui.py`](ui.py) | Minimal RTL browser UI (stdlib + requests only) |
| [`app.py`](app.py) | Streamlit document Q&A app with file upload |
| [`check_progress.py`](check_progress.py) | Quick helper to monitor Ollama model pull progress |
| [`context.txt`](context.txt) | Synthetic Persian demo document (public library sections) |

## Quick start

### 1. Install Ollama

Install [Ollama](https://ollama.com/) and pull a model, for example:

```bash
ollama pull llama3.2:1b
```

### 2. Install Python dependencies

```bash
python -m venv .venv
.venv\Scripts\activate        # Windows
# source .venv/bin/activate   # macOS / Linux
pip install -r requirements.txt
```

### 3. Run (pick one)

**MCP server (stdio):**

```bash
python MCP_Server.py
```

**Browser UI:**

```bash
python ui.py
```

Opens `http://127.0.0.1:8765` with RTL Persian layout.

**Streamlit app:**

```bash
streamlit run app.py
```

**MCP client demo:**

```bash
python MCP_Client.py
```

**Check model download progress:**

```bash
python check_progress.py
```

## MCP tool: `ask_ollama`

| Parameter | Description |
|-----------|-------------|
| `file_path` | Path to a `.txt` or `.pdf` document |
| `question` | User question (answer will be in Persian) |
| `model_name` | Ollama model tag, e.g. `llama3.2:1b` |

The server extracts text from the file, sends it with the question to Ollama's chat API, and returns the model response.

## Demo document

`context.txt` is an **original synthetic Persian text** describing sections of a fictional central city library. It is included only for testing the Q&A pipeline — replace it with your own `.txt` or `.pdf` files.

## Disclaimer

- **Unofficial project** — independent work by Marzieh Babaali. **Not affiliated with Ollama, FastMCP, or any document provider.**
- **Local models** — quality and language behavior depend on the Ollama model you choose.
- **Your documents** — only upload or point to files you have the right to use.
- Code in this repository is original MIT-licensed work ([LICENSE](LICENSE)).

## Author

**Marzieh Babaali** — PhD Researcher · NLP & Generative AI

- [Google Scholar](https://scholar.google.com/citations?user=eOcempcAAAAJ&hl=en)
- [LinkedIn](https://www.linkedin.com/in/marzieh-babaali-75934266)
- [ORCID](https://orcid.org/0000-0003-2209-9745)