agentic-rag-mcp 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. agentic_rag_mcp-0.1.0/.github/workflows/ci.yml +123 -0
  2. agentic_rag_mcp-0.1.0/.github/workflows/pages.yml +45 -0
  3. agentic_rag_mcp-0.1.0/.github/workflows/release.yml +122 -0
  4. agentic_rag_mcp-0.1.0/.gitignore +27 -0
  5. agentic_rag_mcp-0.1.0/CHANGELOG.md +75 -0
  6. agentic_rag_mcp-0.1.0/LICENSE +21 -0
  7. agentic_rag_mcp-0.1.0/PKG-INFO +323 -0
  8. agentic_rag_mcp-0.1.0/README.md +267 -0
  9. agentic_rag_mcp-0.1.0/examples/mcp_client_demo.py +78 -0
  10. agentic_rag_mcp-0.1.0/pyproject.toml +66 -0
  11. agentic_rag_mcp-0.1.0/server.json +39 -0
  12. agentic_rag_mcp-0.1.0/site/index.html +278 -0
  13. agentic_rag_mcp-0.1.0/site/logo.svg +26 -0
  14. agentic_rag_mcp-0.1.0/site/og.png +0 -0
  15. agentic_rag_mcp-0.1.0/site/styles.css +263 -0
  16. agentic_rag_mcp-0.1.0/src/agentic_rag_mcp/__init__.py +3 -0
  17. agentic_rag_mcp-0.1.0/src/agentic_rag_mcp/__main__.py +3 -0
  18. agentic_rag_mcp-0.1.0/src/agentic_rag_mcp/agentic.py +119 -0
  19. agentic_rag_mcp-0.1.0/src/agentic_rag_mcp/cache.py +112 -0
  20. agentic_rag_mcp-0.1.0/src/agentic_rag_mcp/cli.py +230 -0
  21. agentic_rag_mcp-0.1.0/src/agentic_rag_mcp/corpus.py +124 -0
  22. agentic_rag_mcp-0.1.0/src/agentic_rag_mcp/demo_docs/api_reference.md +28 -0
  23. agentic_rag_mcp-0.1.0/src/agentic_rag_mcp/demo_docs/changelog.md +22 -0
  24. agentic_rag_mcp-0.1.0/src/agentic_rag_mcp/demo_docs/faq.md +26 -0
  25. agentic_rag_mcp-0.1.0/src/agentic_rag_mcp/demo_docs/migration_guide.md +26 -0
  26. agentic_rag_mcp-0.1.0/src/agentic_rag_mcp/demo_docs/overview.md +25 -0
  27. agentic_rag_mcp-0.1.0/src/agentic_rag_mcp/embedding.py +63 -0
  28. agentic_rag_mcp-0.1.0/src/agentic_rag_mcp/evaluation.py +322 -0
  29. agentic_rag_mcp-0.1.0/src/agentic_rag_mcp/knowledge_base.py +102 -0
  30. agentic_rag_mcp-0.1.0/src/agentic_rag_mcp/llm.py +264 -0
  31. agentic_rag_mcp-0.1.0/src/agentic_rag_mcp/multi_agent.py +157 -0
  32. agentic_rag_mcp-0.1.0/src/agentic_rag_mcp/server.py +178 -0
  33. agentic_rag_mcp-0.1.0/tests/__init__.py +0 -0
  34. agentic_rag_mcp-0.1.0/tests/conftest.py +76 -0
  35. agentic_rag_mcp-0.1.0/tests/scripted.py +60 -0
  36. agentic_rag_mcp-0.1.0/tests/test_agents.py +120 -0
  37. agentic_rag_mcp-0.1.0/tests/test_cli.py +127 -0
  38. agentic_rag_mcp-0.1.0/tests/test_corpus.py +96 -0
  39. agentic_rag_mcp-0.1.0/tests/test_evaluation.py +83 -0
  40. agentic_rag_mcp-0.1.0/tests/test_integration.py +57 -0
  41. agentic_rag_mcp-0.1.0/tests/test_knowledge_base.py +111 -0
  42. agentic_rag_mcp-0.1.0/tests/test_llm.py +194 -0
  43. agentic_rag_mcp-0.1.0/tests/test_server.py +92 -0
  44. agentic_rag_mcp-0.1.0/tools/make_og_image.py +111 -0
@@ -0,0 +1,123 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ workflow_dispatch:
8
+
9
+ concurrency:
10
+ group: ci-${{ github.ref }}
11
+ cancel-in-progress: true
12
+
13
+ env:
14
+ # The embedding model is downloaded here once per OS and then restored from
15
+ # the Actions cache, instead of fetched from Hugging Face on every job.
16
+ FASTEMBED_CACHE_PATH: ${{ github.workspace }}/.fastembed-cache
17
+ HF_HUB_DISABLE_SYMLINKS_WARNING: "1"
18
+
19
+ jobs:
20
+ test:
21
+ name: ${{ matrix.os }} / py${{ matrix.python }}
22
+ runs-on: ${{ matrix.os }}
23
+ strategy:
24
+ fail-fast: false
25
+ matrix:
26
+ # Oldest and newest supported Python on every OS, and every version
27
+ # in between on Linux.
28
+ os: [ubuntu-latest, windows-latest, macos-latest]
29
+ python: ["3.11", "3.14"]
30
+ include:
31
+ - os: ubuntu-latest
32
+ python: "3.12"
33
+ - os: ubuntu-latest
34
+ python: "3.13"
35
+ steps:
36
+ - uses: actions/checkout@v4
37
+ - uses: astral-sh/setup-uv@v5
38
+ with:
39
+ enable-cache: true
40
+ - name: Set up Python
41
+ run: uv python install ${{ matrix.python }}
42
+ - name: Install
43
+ run: uv sync --all-extras --python ${{ matrix.python }}
44
+ - uses: actions/cache@v4
45
+ with:
46
+ path: .fastembed-cache
47
+ key: fastembed-${{ runner.os }}-all-MiniLM-L6-v2
48
+ - name: Test, including the real model over stdio
49
+ run: uv run --python ${{ matrix.python }} pytest -q
50
+
51
+ lint:
52
+ name: lint
53
+ runs-on: ubuntu-latest
54
+ steps:
55
+ - uses: actions/checkout@v4
56
+ - uses: astral-sh/setup-uv@v5
57
+ with:
58
+ enable-cache: true
59
+ - run: uv sync --all-extras
60
+ - run: uv run ruff check src tests examples
61
+
62
+ package:
63
+ name: build, inspect and install the wheel
64
+ runs-on: ubuntu-latest
65
+ steps:
66
+ - uses: actions/checkout@v4
67
+ - uses: astral-sh/setup-uv@v5
68
+ - name: Build
69
+ run: uv build
70
+ - name: Check the artifacts render on PyPI
71
+ run: uvx twine check dist/*
72
+ - name: The wheel declares its dependencies and ships the demo docs
73
+ run: |
74
+ python3 - <<'PY'
75
+ import glob, zipfile
76
+ wheel = zipfile.ZipFile(glob.glob("dist/*.whl")[0])
77
+ names = wheel.namelist()
78
+ meta = wheel.read(next(n for n in names if n.endswith("METADATA"))).decode()
79
+ # A misplaced table in pyproject.toml can silently drop every
80
+ # dependency, and twine check passes such a wheel. Check directly.
81
+ needed = ["mcp", "fastembed", "faiss-cpu", "numpy", "pydantic"]
82
+ missing = [d for d in needed if f"Requires-Dist: {d}" not in meta]
83
+ assert not missing, f"wheel does not declare: {missing}"
84
+ docs = [n for n in names if "/demo_docs/" in n]
85
+ assert len(docs) == 5, f"expected 5 demo docs, found {docs}"
86
+ print("declares", needed, "and ships", len(docs), "demo docs")
87
+ PY
88
+ - uses: actions/cache@v4
89
+ with:
90
+ path: .fastembed-cache
91
+ key: fastembed-${{ runner.os }}-all-MiniLM-L6-v2
92
+ - name: A clean environment can install and run it
93
+ run: |
94
+ uv venv /tmp/fresh
95
+ uv pip install --python /tmp/fresh dist/*.whl
96
+ /tmp/fresh/bin/agentic-rag-mcp --version
97
+ /tmp/fresh/bin/agentic-rag-mcp search "what happens to records that keep failing" -k 1
98
+
99
+ measure:
100
+ name: retrieval measurement
101
+ runs-on: ubuntu-latest
102
+ steps:
103
+ - uses: actions/checkout@v4
104
+ - uses: astral-sh/setup-uv@v5
105
+ with:
106
+ enable-cache: true
107
+ # Core dependencies only: this also proves the package works without
108
+ # the optional Anthropic SDK.
109
+ - run: uv sync
110
+ - uses: actions/cache@v4
111
+ with:
112
+ path: .fastembed-cache
113
+ key: fastembed-${{ runner.os }}-all-MiniLM-L6-v2
114
+ - name: Single search against planned queries
115
+ run: |
116
+ for k in 2 4; do
117
+ {
118
+ echo "### k = $k"
119
+ echo '```'
120
+ uv run agentic-rag-mcp eval -k "$k"
121
+ echo '```'
122
+ } | tee -a "$GITHUB_STEP_SUMMARY"
123
+ done
@@ -0,0 +1,45 @@
1
+ name: Pages
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ paths:
7
+ - "site/**"
8
+ - ".github/workflows/pages.yml"
9
+ workflow_dispatch:
10
+
11
+ permissions:
12
+ contents: read
13
+ pages: write
14
+ id-token: write
15
+
16
+ # One deployment at a time, and never cancel one midway: a half-finished
17
+ # deploy would leave the published site in an unknown state.
18
+ concurrency:
19
+ group: pages
20
+ cancel-in-progress: false
21
+
22
+ jobs:
23
+ deploy:
24
+ runs-on: ubuntu-latest
25
+ environment:
26
+ name: github-pages
27
+ url: ${{ steps.deployment.outputs.page_url }}
28
+ steps:
29
+ - uses: actions/checkout@v4
30
+ - name: Check the links that point at files in this repo
31
+ run: |
32
+ set -euo pipefail
33
+ # A docs link that 404s is worse than no link, and these are easy to
34
+ # break by renaming a file. Check the local ones before publishing.
35
+ miss=0
36
+ for f in README.md CHANGELOG.md examples/mcp_client_demo.py site/og.png site/logo.svg; do
37
+ [ -f "$f" ] || { echo "::error::site links to missing $f"; miss=1; }
38
+ done
39
+ exit $miss
40
+ - uses: actions/configure-pages@v5
41
+ - uses: actions/upload-pages-artifact@v3
42
+ with:
43
+ path: site
44
+ - id: deployment
45
+ uses: actions/deploy-pages@v4
@@ -0,0 +1,122 @@
1
+ name: Release
2
+
3
+ # Publishing runs from a tag, not from a branch, so what reaches PyPI and the
4
+ # MCP Registry is exactly what was tagged and tested.
5
+ #
6
+ # No secrets are involved. PyPI uses Trusted Publishing and the registry uses
7
+ # GitHub OIDC, so there is no token to leak, rotate, or accidentally print.
8
+
9
+ on:
10
+ push:
11
+ tags: ["v*"]
12
+ workflow_dispatch:
13
+ inputs:
14
+ tag:
15
+ description: "Existing tag to publish, e.g. v0.1.0"
16
+ required: true
17
+
18
+ permissions:
19
+ contents: read
20
+
21
+ env:
22
+ FASTEMBED_CACHE_PATH: ${{ github.workspace }}/.fastembed-cache
23
+ HF_HUB_DISABLE_SYMLINKS_WARNING: "1"
24
+
25
+ jobs:
26
+ verify:
27
+ name: verify the tag
28
+ runs-on: ubuntu-latest
29
+ outputs:
30
+ version: ${{ steps.check.outputs.version }}
31
+ steps:
32
+ - uses: actions/checkout@v4
33
+ with:
34
+ ref: ${{ inputs.tag || github.ref }}
35
+ - uses: astral-sh/setup-uv@v5
36
+ - name: Versions must agree
37
+ id: check
38
+ run: |
39
+ set -euo pipefail
40
+ TAG="${{ inputs.tag || github.ref_name }}"
41
+ # The version lives in one place, __init__.py, and pyproject.toml
42
+ # reads it from there; server.json has to be kept in step by hand.
43
+ PY=$(python3 -c "import re; print(re.search(r'__version__ = \"(.+?)\"', open('src/agentic_rag_mcp/__init__.py').read()).group(1))")
44
+ SRV=$(python3 -c "import json; print(json.load(open('server.json'))['version'])")
45
+ PKG=$(python3 -c "import json; print(json.load(open('server.json'))['packages'][0]['version'])")
46
+ echo "tag=$TAG package=$PY server.json=$SRV server.json package=$PKG"
47
+ # A mismatch here would publish a version that nothing else agrees
48
+ # exists, which is far harder to unpick after the fact than before.
49
+ for V in "$PY" "$SRV" "$PKG"; do
50
+ [ "$TAG" = "v$V" ] || { echo "::error::version mismatch ($TAG vs v$V)"; exit 1; }
51
+ done
52
+ echo "version=$PY" >> "$GITHUB_OUTPUT"
53
+ - uses: actions/cache@v4
54
+ with:
55
+ path: .fastembed-cache
56
+ key: fastembed-${{ runner.os }}-all-MiniLM-L6-v2
57
+ - name: The suite must pass on the tag
58
+ run: |
59
+ uv sync --all-extras
60
+ uv run pytest -q
61
+ uv run ruff check src tests examples
62
+
63
+ pypi:
64
+ name: publish to PyPI
65
+ needs: verify
66
+ runs-on: ubuntu-latest
67
+ environment:
68
+ name: pypi
69
+ url: https://pypi.org/p/agentic-rag-mcp
70
+ permissions:
71
+ id-token: write # Trusted Publishing; no API token stored anywhere
72
+ steps:
73
+ - uses: actions/checkout@v4
74
+ with:
75
+ ref: ${{ inputs.tag || github.ref }}
76
+ - uses: astral-sh/setup-uv@v5
77
+ - name: Build
78
+ run: uv build
79
+ - name: Check the artifacts render on PyPI
80
+ run: uvx twine check dist/*
81
+ - name: The README must carry the registry ownership marker
82
+ run: |
83
+ # The MCP Registry reads this out of the published PyPI description.
84
+ # It is frozen per release, so a missing marker cannot be fixed
85
+ # without burning a version number.
86
+ grep -q "mcp-name: io.github.mqfarooqi1/agentic-rag-mcp" README.md \
87
+ || { echo "::error::ownership marker missing from README.md"; exit 1; }
88
+ - uses: pypa/gh-action-pypi-publish@release/v1
89
+
90
+ registry:
91
+ name: publish to the MCP Registry
92
+ needs: [verify, pypi]
93
+ runs-on: ubuntu-latest
94
+ permissions:
95
+ id-token: write # GitHub OIDC login, so no interactive device flow
96
+ contents: read
97
+ steps:
98
+ - uses: actions/checkout@v4
99
+ with:
100
+ ref: ${{ inputs.tag || github.ref }}
101
+ - name: Wait for PyPI to serve the new version
102
+ run: |
103
+ # The registry validates by fetching the package from PyPI, and a
104
+ # fresh upload takes a moment to appear. Failing here would need a
105
+ # whole new version, so it is worth waiting for.
106
+ for i in $(seq 1 30); do
107
+ if curl -fsS "https://pypi.org/pypi/agentic-rag-mcp/${{ needs.verify.outputs.version }}/json" > /dev/null; then
108
+ echo "visible on PyPI"; exit 0
109
+ fi
110
+ sleep 10
111
+ done
112
+ echo "::error::version never appeared on PyPI"; exit 1
113
+ - name: Install mcp-publisher
114
+ run: |
115
+ curl -L "https://github.com/modelcontextprotocol/registry/releases/latest/download/mcp-publisher_linux_amd64.tar.gz" \
116
+ | tar xz mcp-publisher
117
+ - name: Validate the manifest
118
+ run: ./mcp-publisher validate server.json || ./mcp-publisher validate
119
+ - name: Log in with OIDC
120
+ run: ./mcp-publisher login github-oidc
121
+ - name: Publish
122
+ run: ./mcp-publisher publish
@@ -0,0 +1,27 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ .venv/
5
+ venv/
6
+ env/
7
+ *.egg-info/
8
+ dist/
9
+ build/
10
+ .ruff_cache/
11
+ .pytest_cache/
12
+ .mypy_cache/
13
+
14
+ # CI resolves dependencies fresh on every run, so a new release of mcp or
15
+ # fastembed that breaks this package fails a build instead of a user's install.
16
+ uv.lock
17
+
18
+ # Local notes
19
+ .listing-checklist.md
20
+
21
+ # OS / editor
22
+ .DS_Store
23
+ Thumbs.db
24
+ .vscode/
25
+
26
+ # Local tool settings
27
+ .claude/
@@ -0,0 +1,75 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0
4
+
5
+ The first packaged release. The original weekend build is still here, module
6
+ for module, but it now installs as a package, runs on your own documents, and
7
+ measures the claim it was built to illustrate.
8
+
9
+ ### Fixed
10
+
11
+ - **The MCP server failed on import for anyone installing it fresh.** It used
12
+ `mcp.server.fastmcp`, which `mcp` 2.x removed, and `requirements.txt` did not
13
+ pin a version, so a clean install pulled 2.x and the server raised
14
+ `ModuleNotFoundError` before serving anything. It now uses the 2.x
15
+ `MCPServer` API, with `mcp>=2.3,<3` declared.
16
+ - **The verifier could be cut off before giving its verdict.** It ran with
17
+ `max_tokens=1500` while thinking was on, and thinking counts against that
18
+ limit, so the model could spend the budget reasoning and return no
19
+ structured output. The synthesizer had the same problem at 2000. Both now get
20
+ the same 16,000-token budget as the agent loop.
21
+ - **Hitting the turn limit returned a placeholder string as if it were an
22
+ answer**, which the multi-agent pipeline then passed on as evidence. A
23
+ refusal, running out of tokens, or the turn limit now raises `AgentStopped`.
24
+ - **An unknown tool name was reported to the model as a success.** It is now
25
+ flagged `is_error`.
26
+ - **The chunker could emit a duplicate final chunk** lying wholly inside the
27
+ one before it whenever a document's tail was shorter than the overlap,
28
+ crowding a real result out of the top k.
29
+ - **The embedding model was cached in the system temp folder** (fastembed's
30
+ default), which many Linux systems wipe on reboot, so the 90 MB model would
31
+ re-download and the first search after a restart could stall long enough for
32
+ an MCP client to time out. It now lives in a persistent per-user cache.
33
+ - **The README claimed Python 3.9+.** The dependencies need 3.11 or later.
34
+
35
+ ### Changed
36
+
37
+ - **Embeddings run on fastembed (ONNX Runtime) instead of
38
+ sentence-transformers.** Same all-MiniLM-L6-v2 weights and identical vectors
39
+ (cosine similarity 1.000000 on the same sentences), without PyTorch: a fresh
40
+ install is 308 MB, where PyTorch and transformers alone took 644 MB.
41
+ - **Models.** The agents use Claude Opus 5.5 with adaptive thinking and an
42
+ explicit effort level (`medium`, overridable), since Opus 5.5 changed its
43
+ default effort. Refusal fallbacks are on for the models that support them.
44
+ - **Prompt caching now caches something.** The breakpoint sat on the system
45
+ prompt alone, which is shorter than the model's minimum cacheable length, so
46
+ nothing was cached. The loop now uses automatic caching of the growing
47
+ conversation, which is the prefix each turn actually resends.
48
+ - **Tools return typed results.** Each MCP tool publishes an output schema and
49
+ returns structured content, and mistakes an agent can fix come back as
50
+ `ToolError` with an explanation rather than a bare "error executing tool".
51
+ - **The Anthropic SDK is optional** (`pip install agentic-rag-mcp[agents]`).
52
+ The MCP server needs no API key, because through MCP the client is the agent.
53
+ - **Credentials from `ant auth login` are recognised**, not only
54
+ `ANTHROPIC_API_KEY`.
55
+
56
+ ### Added
57
+
58
+ - **Your own documents**: `--docs DIR` or `AGENTIC_RAG_DOCS` indexes every
59
+ `.md`, `.markdown`, `.txt` and `.rst` file in a folder. The Halyard documents
60
+ are bundled as the demo corpus.
61
+ - **An embedding cache** keyed by a hash of the model and every chunk, so an
62
+ unchanged corpus loads instantly and an edited one can never serve a stale
63
+ vector. A corrupt or unwritable cache costs a re-embed, never a crash.
64
+ - **A command-line tool**: `serve`, `index`, `search`, `ask` and `eval`.
65
+ - **`naive_answer()`**, the fair baseline for agentic RAG: one search, then the
66
+ same model under the same rules. The original naive mode only returned the
67
+ retrieved text, so the two could not be compared answer to answer.
68
+ - **A recall measurement** (`agentic-rag-mcp eval`) comparing one search,
69
+ one search with twice the chunks, mechanically split questions, and planned
70
+ sub-queries, with `--agent` to score a real agent's searches.
71
+ - **Tests**: 86, including the real model over the real stdio protocol, and
72
+ the agent loop driven through the real Anthropic SDK against scripted HTTP
73
+ responses.
74
+ - CI on Linux, Windows and macOS, a website, and release automation for PyPI
75
+ and the MCP Registry.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Muhammad Farooqi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.