File size: 17,214 Bytes
499d53b 48613bb 12b38bd 48613bb e86c88e 48613bb e05417c f7d462d 8c0cb8a ec0f1c1 836c9a8 499d53b 59e6760 48613bb f7d462d 6998810 f7d462d d1bb67f b514ecb f7d462d 30720a5 f7d462d 23e2d78 c2fcdce 23e2d78 f7d462d 709c564 f7d462d 709c564 f7d462d 30720a5 f7d462d 709c564 f7d462d 709c564 f7d462d 30720a5 d54f027 f73b7a7 d54f027 56014e8 a00ddd4 30720a5 a00ddd4 30720a5 a00ddd4 30720a5 a00ddd4 30720a5 a00ddd4 30720a5 a00ddd4 30720a5 a00ddd4 30720a5 a00ddd4 30720a5 a00ddd4 30720a5 a00ddd4 30720a5 a00ddd4 30720a5 a00ddd4 30720a5 a00ddd4 f7d462d 30720a5 709c564 30720a5 f7d462d d54f027 f7d462d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 |
---
title: Ragmint MCP Server
emoji: ๐ง
colorFrom: blue
colorTo: purple
sdk: gradio
sdk_version: "5.49.1"
app_file: app.py
license: apache-2.0
pinned: true
short_description: MCP server for Ragmint with RAG pipeline optimization
tags:
- building-mcp-track-enterprise
- mcp
- rag
- llm
- gradio
- bayesian-optimization
- embeddings
- vector-search
- gemini
- retrievers
- python-library
---
# Ragmint MCP Server
<p align="center">
<img src="https://raw.githubusercontent.com/andyolivers/ragmint/main/src/ragmint/assets/img/ragmint-banner70.png" height="70px" alt="Ragmint Banner">
</p>
Gradio-based MCP server for Ragmint, enabling **Retrieval-Augmented Generation (RAG) pipeline optimization and tuning** via an MCP interface.
    [](https://www.linkedin.com/posts/andyolivers_ragmint-mcp-server-a-hugging-face-space-activity-7399028674261348352-P5wy?utm_source=share&utm_medium=member_desktop&rcm=ACoAABanwk4Bp0A-FVwO9wyzwVp0g_yqZoRDptI)
---
## ๐งฉ Overview
Ragmint MCP Server exposes the full power of **Ragmint**, a modular Python library for **evaluating, optimizing, and tuning RAG pipelines**, through a **Multimodal Control Plane (MCP)**. This allows external clients (like Claude Desktop or Cursor) to **run experiments and tune RAG parameters programmatically**.
## Ragmint
[Ragmint](https://github.com/andyolivers/ragmint) (Retrieval-Augmented Generation Model Inspection & Tuning) is a **modular Python library** for **evaluating, optimizing, and tuning RAG pipelines**. Itโs designed for developers and researchers who want automated hyperparameter optimization, retriever selection, embedding tuning, explainability, and reproducible experiment tracking.


[](https://pypi.org/project/ragmint/)
[](https://huggingface.co/spaces/andyolivers/ragmint-mcp-server)




### Features exposed via MCP:
* โ
Automated hyperparameter optimization (Grid, Random, Bayesian via Optuna).
* ๐ค Auto-RAG Tuner for dynamic retrieverโembedding recommendations.
* ๐งฎ Validation QA generation for corpora without labeled data.
* ๐ฆ Chunking, embeddings, retrievers, rerankers configuration.
* โ๏ธ Full RAG pipeline control programmatically.
---
## ๐ Quick Start
### Installation
```bash
pip install -r requirements.txt
```
### Running the MCP Server
```bash
python app.py
```
The server will expose MCP-compatible endpoints, allowing clients to:
* Perform optimization experiments.
* Automatically autotune pipelines.
* Generate validation QA sets with LLM.
### Environment Variables
Set API keys for LLMs used in explainability and QA generation:
```bash
export GOOGLE_API_KEY="your_gemini_key"
```
---
## ๐ง MCP Usage
Ragmint MCP Server provides Python-callable interfaces for programmatic control. You can find an example of MCP usage in the [Ragmint MCP Server Space](https://huggingface.co/spaces/andyolivers/ragmint-mcp-server) on Hugging Face.
---
## ๐ค Supported Embeddings
* `sentence-transformers/all-MiniLM-L6-v2`
* `sentence-transformers/all-mpnet-base-v2`
* `BAAI/bge-base-en-v1.5`
* `intfloat/multilingual-e5-base`
### Configuration Example
```yaml
embedding_model: sentence-transformers/all-MiniLM-L6-v2
```
---
## ๐ Supported Retrievers
| Retriever | Description |
|--------------|------------------------------------------------------------------|
| FAISS | Fast vector similarity search and indexing. |
| Chroma | Persistent vector database with embeddings. |
| bm25 | Classical lexical search based on term relevance (TF-IDF-style). |
| numpy | Brute-force similarity search using raw vectors and matrix ops. |
### Configuration Example
```yaml
retriever: faiss
```
---
## ๐งฎ Dataset Options
| Mode | Example | Description |
|----------------------|------------------------------------|------------------------------------|
| Default | validation_set=None | Uses built-in validation_qa.json. |
| Custom File | validation_set="data/my_eval.json" | Your QA dataset. |
| Hugging Face Dataset | validation_set="squad" | Downloads benchmark dataset. |
| Generate | validation_set="generate" | Generates the QA dataset with LLM. |
---
## ๐งฉ Folder Structure
```
ragmint_mcp_server/
โโโ app.py # MCP server entrypoint
โโโ models.py
โโโ api.py
```
---
## ๐ง MCP Tools (app.py)
The `app.py` file provides the Gradio UI and also registers the functions exposed as **MCP Tools**, enabling external MCP clients (Claude Desktop, Cursor, VS Code MCP extension, etc.) to call Ragmint programmatically.
`app.py` launches the FastAPI backend (`api.py`) in a background thread and exposes the following MCP tools:
| MCP Tool | Python Function | Description |
|-----------|------------------------|------------------------------------------------------------------------------------|
| upload_docs | upload_docs_tool() | Uploads `.txt` files or remote URLs into the configured `docs_path`. |
| upload_urls | upload_urls_tool() | Downloads remote files from external URLs and stores them inside `docs_path`. |
| optimize_rag | optimize_rag_tool() | Runs explicit hyperparameter optimization for a RAG pipeline. |
| autotune | autotune_tool() | Automatically recommends best chunking + embedding configuration. |
| generate_qa | generate_qa_tool() | Generates synthetic QA validation dataset for evaluation. |
| clear_cache | clear_cache_tool() | Deletes all docs inside `data/docs` to reset the workspace. |
---
## ๐ฌ Demo
YouTube: https://www.youtube.com/watch?v=DKtHBI3jYgQ
---
## ๐ฅ Inputs
The Ragmint MCP Server exposes three main endpoints with the following inputs:
### 1. Upload Documents (`upload_docs`)
Input: `.txt` files or file-like objects to upload to the documents directory (`docs_path`).
<details>
<summary>View Input Model</summary>
| Field | Type | Description | Example |
|--------|-------|-------------|---------|
| files | File[] | Local `.txt` files selected or passed from MCP client | ["sample.txt"] |
| docs_path | str | Directory where files are stored | data/docs |
</details>
### 2. Upload URLs (`upload_urls`)
Input: List of URLs referencing `.txt` files to download and store in `docs_path`.
<details>
<summary>View Input Model</summary>
| Field | Type | Description | Example |
|--------|-------|-------------|---------|
| urls | List[str] | List of URLs pointing to remote documents | ["https://example.com/doc.txt"] |
| docs_path | str | Directory where downloaded files are saved | data/docs |
</details>
### 3. Optimize RAG (`optimize_rag`)
Input: JSON object following the `OptimizeRequest` model.
<details>
<summary>View Input Model</summary>
| Field | Type | Description | Example |
|-------|------|-------------|---------|
| docs_path | str | Folder containing documents | data/docs |
| retriever | List[str] | Retriever type | ["faiss"] |
| embedding_model | List[str] | Embedding model name or path | ["sentence-transformers/all-MiniLM-L6-v2"] |
| strategy | List[str] | RAG strategy | ["fixed"] |
| chunk_sizes | List[int] | Chunk sizes to evaluate | [200] |
| overlaps | List[int] | Overlap values to test | [50] |
| rerankers | List[str] | Rerankers to apply after retrieval | ["mmr"] |
| search_type | str | Parameter search method (grid, random, bayesian) | "grid" |
| trials | int | Number of optimization trials | 2 |
| metric | str | Evaluation metric for optimization | "faithfulness" |
| validation_choice | str | Validation data source (generate, local JSON path, HF dataset ID, etc.) | "generate" |
| llm_model | str | LLM used to generate QA dataset when validation_choice=generate | "gemini-2.5-flash-lite" |
</details>
### 4. Autotune RAG (`autotune`)
Input: JSON object following the `AutotuneRequest` model.
<details>
<summary>View Input Model</summary>
| Field | Type | Description | Example |
|-------|------|-------------|---------|
| docs_path | str | Folder containing documents | data/docs |
| embedding_model | str | Embedding model name or path | "sentence-transformers/all-MiniLM-L6-v2" |
| num_chunk_pairs | int | Number of chunk pairs to analyze for tuning | 2 |
| metric | str | Evaluation metric for optimization | "faithfulness" |
| search_type | str | Search method (grid, random, bayesian) | "grid" |
| trials | int | Number of optimization trials | 2 |
| validation_choice | str | Validation data source (generate, local JSON, HF dataset) | "generate" |
| llm_model | str | LLM used for generating QA dataset | "gemini-2.5-flash-lite" |
</details>
### 5. Generate QA (`generate_qa`)
Input: JSON object following the `QARequest` model.
<details>
<summary>View Input Model</summary>
| Field | Type | Description | Example |
|-------|------|-------------|---------|
| docs_path | str | Folder containing documents for QA generation | data/docs |
| llm_model | str | LLM used for question generation | "gemini-2.5-flash-lite" |
| batch_size | int | Number of documents processed per batch | 5 |
| min_q | int | Minimum number of questions per document | 3 |
| max_q | int | Maximum number of questions per document | 25 |
</details>
### 6. Clear Cache (`clear_cache`)
Deletes all stored documents from `data/docs`.
<details>
<summary>View Input Model</summary>
| Field | Type | Description | Example |
|--------|-------|-------------|---------|
| docs_path | str | Folder to wipe clean | data/docs |
</details>
---
## ๐ค Outputs
The Ragmint MCP Server exposes three main endpoints with the following example outputs:
### 1. Upload Documents Response (`upload_docs`)
<details>
<summary>View Response Example</summary>
```json
{
"status": "ok",
"uploaded_files": ["sample.txt"],
"docs_path": "data/docs"
}
```
</details>
- **status**: `"ok"` โ Indicates that the upload was successful.
- **uploaded_files**: List of file names that were successfully uploaded.
- **docs_path**: The directory where the uploaded documents are stored.
โ
Confirms your documents are ready for RAG operations.
### 2. Upload URLs Response (`upload_urls`)
<details>
<summary>View Response Example</summary>
```json
{
"status": "ok",
"uploaded_files": ["doc.txt"],
"docs_path": "data/docs"
}
```
</details>
- **status**: `"ok"` โ Indicates that the upload was successful.
- **uploaded_files**: List of file names that were successfully uploaded.
- **docs_path**: The directory where the uploaded documents are stored.
โ
Confirms your documents are ready for RAG operations.
### 3. Optimize RAG Response (`optimize_rag`)
<details>
<summary>View Response Example</summary>
```json
{
"status": "finished",
"run_id": "opt_1763222218",
"elapsed_seconds": 0.937,
"best_config": {
"retriever": "faiss",
"embedding_model": "sentence-transformers/all-MiniLM-L6-v2",
"reranker": "mmr",
"chunk_size": 200,
"overlap": 50,
"strategy": "fixed",
"faithfulness": 0.8659,
"latency": 0.0333
},
"results": [
{
"retriever": "faiss",
"embedding_model": "sentence-transformers/all-MiniLM-L6-v2",
"reranker": "mmr",
"chunk_size": 200,
"overlap": 50,
"strategy": "fixed",
"faithfulness": 0.8659,
"latency": 0.0333
}
],
"corpus_stats": {
"num_docs": 1,
"avg_len": 8.0,
"corpus_size": 61
}
}
```
</details>
- **status**: `"finished"` โ Optimization process completed.
- **run_id**: Unique identifier for this optimization run.
- **elapsed_seconds**: How long the optimization took.
- **best_config**: Configuration that gave the best performance.
- **retriever** โ The retrieval algorithm used (faiss).
- **embedding_model** โ Embedding model applied.
- **reranker** โ Reranking strategy after retrieval.
- **chunk_size** โ Size of document chunks used in RAG.
- **overlap** โ Overlap between consecutive chunks.
- **strategy** โ RAG retrieval strategy.
- **faithfulness** โ Evaluation score (higher = better).
- **latency** โ Time per query in seconds.
- **results**: List of all tested configurations and their scores.
- **corpus_stats**: Statistics about the uploaded documents.
- **num_docs** โ Number of documents in corpus.
- **avg_len** โ Average document length.
- **corpus_size** โ Total size in characters or tokens.
### 4. Autotune RAG Response (`autotune`)
<details>
<summary>View Response Example</summary>
```json
{
"status": "finished",
"run_id": "autotune_1763222228",
"elapsed_seconds": 4.733,
"recommendation": {
"retriever": "BM25",
"embedding_model": "sentence-transformers/all-MiniLM-L6-v2",
"chunk_size": 100,
"overlap": 30,
"strategy": "fixed",
"chunk_candidates": [[100, 30], [110, 30]]
},
"chunk_candidates": [[90, 50], [70, 50]],
"best_config": {
"retriever": "BM25",
"embedding_model": "sentence-transformers/all-MiniLM-L6-v2",
"reranker": "mmr",
"chunk_size": 70,
"overlap": 50,
"strategy": "fixed",
"faithfulness": 1.0,
"latency": 0.0272
},
"results": [
{
"retriever": "BM25",
"embedding_model": "sentence-transformers/all-MiniLM-L6-v2",
"reranker": "mmr",
"chunk_size": 70,
"overlap": 50,
"strategy": "fixed",
"faithfulness": 1.0,
"latency": 0.0272
},
{
"retriever": "BM25",
"embedding_model": "sentence-transformers/all-MiniLM-L6-v2",
"reranker": "mmr",
"chunk_size": 90,
"overlap": 50,
"strategy": "fixed",
"faithfulness": 1.0,
"latency": 0.0186
}
],
"corpus_stats": {
"num_docs": 1,
"avg_len": 8.0,
"corpus_size": 61
}
}
```
</details>
- **recommendation**: The tuned configuration suggested by the autotuner.
- **chunk_candidates**: List of possible chunk_size/overlap pairs analyzed.
- **best_config**: Best-performing configuration with metrics.
- **results**: All tested configurations and their performance.
- **corpus_stats**: Same as in optimize response.
- **status, run_id, elapsed_seconds**: Same meaning as Optimize endpoint.
๐ง **Difference from Optimize**: Autotune automatically selects the best hyperparameters, rather than testing all user-specified combinations.
### 5. Generate QA Response (`generate_qa`)
<details>
<summary>View Response Example</summary>
```json
{
"status": "finished",
"output_path": "data/docs/validation_qa.json",
"preview_count": 3,
"sample": [
{
"query": "What capability does Artificial Intelligence provide to machines?",
"expected_answer": "Artificial Intelligence enables machines to learn from data."
},
{
"query": "What is the primary source of learning for machines with Artificial Intelligence?",
"expected_answer": "Machines with Artificial Intelligence learn from data."
},
{
"query": "How does Artificial Intelligence facilitate machine learning?",
"expected_answer": "Artificial Intelligence enables machines to learn from data."
}
]
}
```
</details>
- **output_path**: Where the generated QA JSON file is saved.
- **preview_count**: Number of QA pairs included in the response preview.
- **sample**: Example QA pairs:
- **query** โ The question generated from the document.
- **expected_answer** โ The reference answer corresponding to that question.
- **status**: `"finished"` โ QA generation completed successfully.
### 6. Clear Cache Response (`clear_cache`)
<details>
<summary>View Response Example</summary>
```json
{
"status": "ok",
"deleted_files": 7,
"docs_path": "data/docs"
}
```
</details>
- **deleted_files**: Number of documents removed.
- **status**: "ok" indicates successful workspace reset.
---
## ๐ License
This project is licensed under the Apache License 2.0. See the [LICENSE](LICENSE) file for details.
---
<p align="center">
<sub>Built with โค๏ธ by <a href="https://andyolivers.com">Andrรฉ Oliveira</a> | Apache 2.0 License</sub>
</p>
|