docprov-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.
- docprov_mcp-0.1.0/.github/workflows/ci.yml +36 -0
- docprov_mcp-0.1.0/.gitignore +14 -0
- docprov_mcp-0.1.0/CHANGELOG.md +14 -0
- docprov_mcp-0.1.0/CONTRIBUTING.md +27 -0
- docprov_mcp-0.1.0/LICENSE +21 -0
- docprov_mcp-0.1.0/PKG-INFO +202 -0
- docprov_mcp-0.1.0/README.md +172 -0
- docprov_mcp-0.1.0/SECURITY.md +11 -0
- docprov_mcp-0.1.0/pyproject.toml +60 -0
- docprov_mcp-0.1.0/skills/docprov-verification/SKILL.md +33 -0
- docprov_mcp-0.1.0/src/docprov_mcp/__init__.py +22 -0
- docprov_mcp-0.1.0/src/docprov_mcp/cli.py +232 -0
- docprov_mcp-0.1.0/src/docprov_mcp/loader.py +160 -0
- docprov_mcp-0.1.0/src/docprov_mcp/models.py +116 -0
- docprov_mcp-0.1.0/src/docprov_mcp/server.py +119 -0
- docprov_mcp-0.1.0/src/docprov_mcp/verifier.py +599 -0
- docprov_mcp-0.1.0/tests/conftest.py +116 -0
- docprov_mcp-0.1.0/tests/test_cli.py +114 -0
- docprov_mcp-0.1.0/tests/test_loader.py +80 -0
- docprov_mcp-0.1.0/tests/test_mcp_server.py +117 -0
- docprov_mcp-0.1.0/tests/test_verifier.py +155 -0
- docprov_mcp-0.1.0/uv.lock +1362 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
strategy:
|
|
13
|
+
fail-fast: false
|
|
14
|
+
matrix:
|
|
15
|
+
python-version: ["3.10", "3.11", "3.12"]
|
|
16
|
+
|
|
17
|
+
steps:
|
|
18
|
+
- name: Check out repository
|
|
19
|
+
uses: actions/checkout@v4
|
|
20
|
+
|
|
21
|
+
- name: Install uv
|
|
22
|
+
uses: astral-sh/setup-uv@v5
|
|
23
|
+
with:
|
|
24
|
+
python-version: ${{ matrix.python-version }}
|
|
25
|
+
|
|
26
|
+
- name: Install dependencies
|
|
27
|
+
run: uv sync --extra dev
|
|
28
|
+
|
|
29
|
+
- name: Run Ruff lint
|
|
30
|
+
run: uv run ruff check src tests
|
|
31
|
+
|
|
32
|
+
- name: Run pytest
|
|
33
|
+
run: uv run pytest -v
|
|
34
|
+
|
|
35
|
+
- name: Build distribution artifacts
|
|
36
|
+
run: uv build
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
## [0.1.0] - 2026-12-06
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
- Deterministic PDF, Markdown, and plain text document loader with SHA-256 hashing and printed-page detection.
|
|
9
|
+
- BM25-inspired `search_document()` with exact character offset snippets.
|
|
10
|
+
- `verify_citation()` and `audit_citations()` with `verified`, `page_mismatch`, `partial_match`, and `not_found` verdicts plus strict numeric verification (`missing_numbers`).
|
|
11
|
+
- `MCPServer` stdio server (`docprov-mcp`) exposing 5 tools and `grounded_qa_workflow` prompt.
|
|
12
|
+
- `docprov` CLI (`inspect`, `extract`, `search`, `verify`, `audit`, `serve`) with exit-code quality gates.
|
|
13
|
+
- Companion Agent Skill in `skills/docprov-verification/SKILL.md`.
|
|
14
|
+
- Full `pytest` suite and GitHub Actions CI matrix for Python 3.10–3.12.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Contributing to docprov-mcp
|
|
2
|
+
|
|
3
|
+
Thank you for considering contributing to `docprov-mcp`!
|
|
4
|
+
|
|
5
|
+
## Development Setup
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
git clone https://github.com/afiffathin31/docprov-mcp.git
|
|
9
|
+
cd docprov-mcp
|
|
10
|
+
uv sync --extra dev
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Running Checks
|
|
14
|
+
|
|
15
|
+
Before opening a pull request, please make sure linting, tests, and package builds succeed:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
uv run ruff check src tests
|
|
19
|
+
uv run pytest -v
|
|
20
|
+
uv build
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Pull Request Guidelines
|
|
24
|
+
|
|
25
|
+
- Keep changes focused and accompanied by deterministic unit tests in `tests/`.
|
|
26
|
+
- Preserve zero-external-API determinism in the core verification engine.
|
|
27
|
+
- Update `README.md` or `CHANGELOG.md` when adding user-facing CLI flags or MCP tools.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 afiffathin31
|
|
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.
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: docprov-mcp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Deterministic PDF & Markdown citation provenance verification MCP server and CLI for RAG and AI agents
|
|
5
|
+
Project-URL: Homepage, https://github.com/afiffathin31/docprov-mcp
|
|
6
|
+
Project-URL: Repository, https://github.com/afiffathin31/docprov-mcp
|
|
7
|
+
Project-URL: Issues, https://github.com/afiffathin31/docprov-mcp/issues
|
|
8
|
+
Author-email: afiffathin31 <afiffathin38@gmail.com>
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: ai-agents,citation,mcp,pdf,provenance,rag,verification
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
|
+
Classifier: Topic :: Text Processing :: Indexing
|
|
22
|
+
Requires-Python: >=3.10
|
|
23
|
+
Requires-Dist: mcp>=1.2.0
|
|
24
|
+
Requires-Dist: pypdf>=5.0.0
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: build>=1.2.0; extra == 'dev'
|
|
27
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
28
|
+
Requires-Dist: ruff>=0.6.0; extra == 'dev'
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
|
|
31
|
+
# docprov-mcp
|
|
32
|
+
|
|
33
|
+
**Deterministic PDF & Markdown Citation Provenance Verification MCP Server, CLI, and Agent Skill.**
|
|
34
|
+
|
|
35
|
+
[](https://github.com/afiffathin31/docprov-mcp/actions/workflows/ci.yml)
|
|
36
|
+
[](LICENSE)
|
|
37
|
+
[](https://www.python.org/downloads/)
|
|
38
|
+
|
|
39
|
+
`docprov-mcp` gives AI coding agents, RAG pipelines, and evaluation suites an auditable verification layer that checks whether generated claims, numbers, and page citations actually appear in the source PDF or Markdown file—**without relying on another LLM call**.
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## Why `docprov-mcp`?
|
|
44
|
+
|
|
45
|
+
RAG systems and LLM assistants frequently hallucinate **wrong page numbers** or **subtle numeric distortions** (e.g., citing `18.4%` when page 12 reports `14.8%`). `docprov-mcp` solves this with fast, deterministic provenance checks:
|
|
46
|
+
|
|
47
|
+
- **Exact & Lexical Verification:** Combines normalized verbatim substring checks with sentence/window overlap scoring.
|
|
48
|
+
- **Strict Numeric Guardrails:** Extracts numbers, percentages, currencies, and years from every claim and flags `missing_numbers` so numeric hallucinations never pass silently.
|
|
49
|
+
- **Page Mismatch Detection:** Distinguishes `verified`, `page_mismatch` (points you to the true `matched_page`), `partial_match`, and `not_found`.
|
|
50
|
+
- **PDF & Printed Page Awareness:** Captures 1-based `pdf_page` indices alongside `/PageLabels` or header/footer `printed_page` numbers.
|
|
51
|
+
- **CI-Ready CLI + Stdio MCP Server + Companion Agent Skill:** Run locally from any MCP client (Qoder, Claude Desktop, Cursor) or enforce `--strict` quality gates in automated tests.
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## Architecture
|
|
56
|
+
|
|
57
|
+
```mermaid
|
|
58
|
+
flowchart LR
|
|
59
|
+
Doc["PDF / Markdown / Text"] --> Loader["load_document() + SHA-256 + Page Labels"]
|
|
60
|
+
Loader --> Index["DocumentIndex (PageRecord[])"]
|
|
61
|
+
Index --> Search["search_document() (BM25 + Phrase Boost)"]
|
|
62
|
+
Index --> Verify["verify_citation() (Lexical + Numeric Gate)"]
|
|
63
|
+
Verify --> Audit["audit_citations() -> ProvenanceReport"]
|
|
64
|
+
Search --> MCP["MCPServer (docprov-mcp)"]
|
|
65
|
+
Verify --> MCP
|
|
66
|
+
Audit --> MCP
|
|
67
|
+
Audit --> CLI["CLI Quality Gate (docprov)"]
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## Installation
|
|
73
|
+
|
|
74
|
+
Using [`uv`](https://docs.astral.sh/uv/) (recommended):
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
uv tool install docprov-mcp
|
|
78
|
+
# or run from source:
|
|
79
|
+
uv sync --extra dev
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Using `pip`:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
pip install docprov-mcp
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
## Quick Start (MCP Server)
|
|
91
|
+
|
|
92
|
+
Add `docprov-mcp` to your MCP client configuration (works with **Qoder**, **Claude Desktop**, **Cursor**, or any stdio MCP host).
|
|
93
|
+
|
|
94
|
+
### Using `uvx`
|
|
95
|
+
|
|
96
|
+
```json
|
|
97
|
+
{
|
|
98
|
+
"mcpServers": {
|
|
99
|
+
"docprov": {
|
|
100
|
+
"command": "uvx",
|
|
101
|
+
"args": ["docprov-mcp"]
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Running from a local clone
|
|
108
|
+
|
|
109
|
+
```json
|
|
110
|
+
{
|
|
111
|
+
"mcpServers": {
|
|
112
|
+
"docprov": {
|
|
113
|
+
"command": "uv",
|
|
114
|
+
"args": ["--directory", "/path/to/docprov-mcp", "run", "docprov-mcp"]
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Exposed MCP Tools & Prompts
|
|
121
|
+
|
|
122
|
+
| Type | Name | Purpose |
|
|
123
|
+
|---|---|---|
|
|
124
|
+
| Tool | `inspect_document` | Inspect file type, SHA-256 fingerprint, total pages, and printed page labels |
|
|
125
|
+
| Tool | `extract_pages` | Extract verbatim text for a 1-based inclusive page range |
|
|
126
|
+
| Tool | `search_document` | BM25-inspired ranking with page-anchored snippets and character offsets |
|
|
127
|
+
| Tool | `verify_citation` | Verify a claim (and optional `cited_page`), catching mismatches and missing numbers |
|
|
128
|
+
| Tool | `audit_citations` | Batch-audit a list of citations and compute overall `pass_rate` |
|
|
129
|
+
| Prompt | `grounded_qa_workflow` | Structured agent workflow enforcing verification before final answers |
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
## CLI Usage & CI Quality Gates
|
|
134
|
+
|
|
135
|
+
### Inspect a document
|
|
136
|
+
```bash
|
|
137
|
+
docprov inspect ./annual_report.pdf --json
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Search for evidence
|
|
141
|
+
```bash
|
|
142
|
+
docprov search ./annual_report.pdf "operating margin" --top-k 3
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Extract specific pages
|
|
146
|
+
```bash
|
|
147
|
+
docprov extract ./annual_report.pdf --pages 12-13
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Verify a single claim (exit code `0` if verified, `2` otherwise)
|
|
151
|
+
```bash
|
|
152
|
+
docprov verify ./annual_report.pdf \
|
|
153
|
+
--claim "Operating margin improved to 18.4% in FY2025." \
|
|
154
|
+
--page 12 \
|
|
155
|
+
--json
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### Batch audit citations in CI
|
|
159
|
+
Given `claims.json`:
|
|
160
|
+
```json
|
|
161
|
+
[
|
|
162
|
+
{"claim": "Operating margin improved to 18.4% in FY2025.", "cited_page": 12},
|
|
163
|
+
{"claim": "Total capital expenditure reached USD 42M.", "cited_page": 14}
|
|
164
|
+
]
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
Run:
|
|
168
|
+
```bash
|
|
169
|
+
docprov audit ./annual_report.pdf --citations ./claims.json --format markdown --strict
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
## Companion Agent Skill
|
|
175
|
+
|
|
176
|
+
This repository also ships a portable Agent Skill at [`skills/docprov-verification/SKILL.md`](skills/docprov-verification/SKILL.md) that instructs AI coding and research agents to run `inspect_document` -> `search_document` -> `extract_pages` -> `audit_citations` before answering questions from documents.
|
|
177
|
+
|
|
178
|
+
---
|
|
179
|
+
|
|
180
|
+
## Development
|
|
181
|
+
|
|
182
|
+
```bash
|
|
183
|
+
git clone https://github.com/afiffathin31/docprov-mcp.git
|
|
184
|
+
cd docprov-mcp
|
|
185
|
+
uv sync --extra dev
|
|
186
|
+
uv run ruff check src tests
|
|
187
|
+
uv run pytest -v
|
|
188
|
+
uv build
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
---
|
|
192
|
+
|
|
193
|
+
## Roadmap
|
|
194
|
+
|
|
195
|
+
- **v0.1.0 (Current):** Deterministic PDF/Markdown/Text loader, SHA-256 provenance, BM25 search, numeric & page-mismatch verification, stdio MCP server, CLI quality gates, Agent Skill.
|
|
196
|
+
- **v0.2.0 (Planned):** Table cell coordinate verification, optional OCR/Docling JSON adapter, SARIF/JUnit audit export for CI pipelines, and PyPI Trusted Publishing.
|
|
197
|
+
|
|
198
|
+
---
|
|
199
|
+
|
|
200
|
+
## License
|
|
201
|
+
|
|
202
|
+
MIT License — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
# docprov-mcp
|
|
2
|
+
|
|
3
|
+
**Deterministic PDF & Markdown Citation Provenance Verification MCP Server, CLI, and Agent Skill.**
|
|
4
|
+
|
|
5
|
+
[](https://github.com/afiffathin31/docprov-mcp/actions/workflows/ci.yml)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
[](https://www.python.org/downloads/)
|
|
8
|
+
|
|
9
|
+
`docprov-mcp` gives AI coding agents, RAG pipelines, and evaluation suites an auditable verification layer that checks whether generated claims, numbers, and page citations actually appear in the source PDF or Markdown file—**without relying on another LLM call**.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Why `docprov-mcp`?
|
|
14
|
+
|
|
15
|
+
RAG systems and LLM assistants frequently hallucinate **wrong page numbers** or **subtle numeric distortions** (e.g., citing `18.4%` when page 12 reports `14.8%`). `docprov-mcp` solves this with fast, deterministic provenance checks:
|
|
16
|
+
|
|
17
|
+
- **Exact & Lexical Verification:** Combines normalized verbatim substring checks with sentence/window overlap scoring.
|
|
18
|
+
- **Strict Numeric Guardrails:** Extracts numbers, percentages, currencies, and years from every claim and flags `missing_numbers` so numeric hallucinations never pass silently.
|
|
19
|
+
- **Page Mismatch Detection:** Distinguishes `verified`, `page_mismatch` (points you to the true `matched_page`), `partial_match`, and `not_found`.
|
|
20
|
+
- **PDF & Printed Page Awareness:** Captures 1-based `pdf_page` indices alongside `/PageLabels` or header/footer `printed_page` numbers.
|
|
21
|
+
- **CI-Ready CLI + Stdio MCP Server + Companion Agent Skill:** Run locally from any MCP client (Qoder, Claude Desktop, Cursor) or enforce `--strict` quality gates in automated tests.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Architecture
|
|
26
|
+
|
|
27
|
+
```mermaid
|
|
28
|
+
flowchart LR
|
|
29
|
+
Doc["PDF / Markdown / Text"] --> Loader["load_document() + SHA-256 + Page Labels"]
|
|
30
|
+
Loader --> Index["DocumentIndex (PageRecord[])"]
|
|
31
|
+
Index --> Search["search_document() (BM25 + Phrase Boost)"]
|
|
32
|
+
Index --> Verify["verify_citation() (Lexical + Numeric Gate)"]
|
|
33
|
+
Verify --> Audit["audit_citations() -> ProvenanceReport"]
|
|
34
|
+
Search --> MCP["MCPServer (docprov-mcp)"]
|
|
35
|
+
Verify --> MCP
|
|
36
|
+
Audit --> MCP
|
|
37
|
+
Audit --> CLI["CLI Quality Gate (docprov)"]
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## Installation
|
|
43
|
+
|
|
44
|
+
Using [`uv`](https://docs.astral.sh/uv/) (recommended):
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
uv tool install docprov-mcp
|
|
48
|
+
# or run from source:
|
|
49
|
+
uv sync --extra dev
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Using `pip`:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
pip install docprov-mcp
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## Quick Start (MCP Server)
|
|
61
|
+
|
|
62
|
+
Add `docprov-mcp` to your MCP client configuration (works with **Qoder**, **Claude Desktop**, **Cursor**, or any stdio MCP host).
|
|
63
|
+
|
|
64
|
+
### Using `uvx`
|
|
65
|
+
|
|
66
|
+
```json
|
|
67
|
+
{
|
|
68
|
+
"mcpServers": {
|
|
69
|
+
"docprov": {
|
|
70
|
+
"command": "uvx",
|
|
71
|
+
"args": ["docprov-mcp"]
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Running from a local clone
|
|
78
|
+
|
|
79
|
+
```json
|
|
80
|
+
{
|
|
81
|
+
"mcpServers": {
|
|
82
|
+
"docprov": {
|
|
83
|
+
"command": "uv",
|
|
84
|
+
"args": ["--directory", "/path/to/docprov-mcp", "run", "docprov-mcp"]
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Exposed MCP Tools & Prompts
|
|
91
|
+
|
|
92
|
+
| Type | Name | Purpose |
|
|
93
|
+
|---|---|---|
|
|
94
|
+
| Tool | `inspect_document` | Inspect file type, SHA-256 fingerprint, total pages, and printed page labels |
|
|
95
|
+
| Tool | `extract_pages` | Extract verbatim text for a 1-based inclusive page range |
|
|
96
|
+
| Tool | `search_document` | BM25-inspired ranking with page-anchored snippets and character offsets |
|
|
97
|
+
| Tool | `verify_citation` | Verify a claim (and optional `cited_page`), catching mismatches and missing numbers |
|
|
98
|
+
| Tool | `audit_citations` | Batch-audit a list of citations and compute overall `pass_rate` |
|
|
99
|
+
| Prompt | `grounded_qa_workflow` | Structured agent workflow enforcing verification before final answers |
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
## CLI Usage & CI Quality Gates
|
|
104
|
+
|
|
105
|
+
### Inspect a document
|
|
106
|
+
```bash
|
|
107
|
+
docprov inspect ./annual_report.pdf --json
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Search for evidence
|
|
111
|
+
```bash
|
|
112
|
+
docprov search ./annual_report.pdf "operating margin" --top-k 3
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Extract specific pages
|
|
116
|
+
```bash
|
|
117
|
+
docprov extract ./annual_report.pdf --pages 12-13
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Verify a single claim (exit code `0` if verified, `2` otherwise)
|
|
121
|
+
```bash
|
|
122
|
+
docprov verify ./annual_report.pdf \
|
|
123
|
+
--claim "Operating margin improved to 18.4% in FY2025." \
|
|
124
|
+
--page 12 \
|
|
125
|
+
--json
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### Batch audit citations in CI
|
|
129
|
+
Given `claims.json`:
|
|
130
|
+
```json
|
|
131
|
+
[
|
|
132
|
+
{"claim": "Operating margin improved to 18.4% in FY2025.", "cited_page": 12},
|
|
133
|
+
{"claim": "Total capital expenditure reached USD 42M.", "cited_page": 14}
|
|
134
|
+
]
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Run:
|
|
138
|
+
```bash
|
|
139
|
+
docprov audit ./annual_report.pdf --citations ./claims.json --format markdown --strict
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
## Companion Agent Skill
|
|
145
|
+
|
|
146
|
+
This repository also ships a portable Agent Skill at [`skills/docprov-verification/SKILL.md`](skills/docprov-verification/SKILL.md) that instructs AI coding and research agents to run `inspect_document` -> `search_document` -> `extract_pages` -> `audit_citations` before answering questions from documents.
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
## Development
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
git clone https://github.com/afiffathin31/docprov-mcp.git
|
|
154
|
+
cd docprov-mcp
|
|
155
|
+
uv sync --extra dev
|
|
156
|
+
uv run ruff check src tests
|
|
157
|
+
uv run pytest -v
|
|
158
|
+
uv build
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
---
|
|
162
|
+
|
|
163
|
+
## Roadmap
|
|
164
|
+
|
|
165
|
+
- **v0.1.0 (Current):** Deterministic PDF/Markdown/Text loader, SHA-256 provenance, BM25 search, numeric & page-mismatch verification, stdio MCP server, CLI quality gates, Agent Skill.
|
|
166
|
+
- **v0.2.0 (Planned):** Table cell coordinate verification, optional OCR/Docling JSON adapter, SARIF/JUnit audit export for CI pipelines, and PyPI Trusted Publishing.
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
## License
|
|
171
|
+
|
|
172
|
+
MIT License — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
## Supported Versions
|
|
4
|
+
|
|
5
|
+
| Version | Supported |
|
|
6
|
+
|---|---|
|
|
7
|
+
| 0.1.x | Yes |
|
|
8
|
+
|
|
9
|
+
## Reporting a Vulnerability
|
|
10
|
+
|
|
11
|
+
If you discover a security vulnerability in `docprov-mcp` (for example, path traversal or unsafe parsing behavior), please open a private security advisory on GitHub or email `afiffathin38@gmail.com` with reproduction details rather than filing a public issue.
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "docprov-mcp"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Deterministic PDF & Markdown citation provenance verification MCP server and CLI for RAG and AI agents"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "afiffathin31", email = "afiffathin38@gmail.com" },
|
|
14
|
+
]
|
|
15
|
+
keywords = ["mcp", "rag", "citation", "provenance", "pdf", "verification", "ai-agents"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 4 - Beta",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"License :: OSI Approved :: MIT License",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.10",
|
|
22
|
+
"Programming Language :: Python :: 3.11",
|
|
23
|
+
"Programming Language :: Python :: 3.12",
|
|
24
|
+
"Programming Language :: Python :: 3.13",
|
|
25
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
26
|
+
"Topic :: Text Processing :: Indexing",
|
|
27
|
+
]
|
|
28
|
+
dependencies = [
|
|
29
|
+
"mcp>=1.2.0",
|
|
30
|
+
"pypdf>=5.0.0",
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
[project.optional-dependencies]
|
|
34
|
+
dev = [
|
|
35
|
+
"pytest>=8.0",
|
|
36
|
+
"ruff>=0.6.0",
|
|
37
|
+
"build>=1.2.0",
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
[project.urls]
|
|
41
|
+
Homepage = "https://github.com/afiffathin31/docprov-mcp"
|
|
42
|
+
Repository = "https://github.com/afiffathin31/docprov-mcp"
|
|
43
|
+
Issues = "https://github.com/afiffathin31/docprov-mcp/issues"
|
|
44
|
+
|
|
45
|
+
[project.scripts]
|
|
46
|
+
docprov = "docprov_mcp.cli:main"
|
|
47
|
+
docprov-mcp = "docprov_mcp.server:main"
|
|
48
|
+
|
|
49
|
+
[tool.hatch.build.targets.wheel]
|
|
50
|
+
packages = ["src/docprov_mcp"]
|
|
51
|
+
|
|
52
|
+
[tool.ruff]
|
|
53
|
+
line-length = 100
|
|
54
|
+
target-version = "py310"
|
|
55
|
+
|
|
56
|
+
[tool.ruff.lint]
|
|
57
|
+
select = ["E", "F", "I", "UP", "B"]
|
|
58
|
+
|
|
59
|
+
[tool.pytest.ini_options]
|
|
60
|
+
testpaths = ["tests"]
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: docprov-verification
|
|
3
|
+
description: Verify PDF and Markdown claims, numbers, and page citations against source documents using docprov-mcp before delivering grounded answers.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Document Provenance Verification Skill
|
|
7
|
+
|
|
8
|
+
Use this skill whenever an AI agent answers questions from PDF reports, technical specifications, contracts, or multi-page Markdown documents and must guarantee that **every claim, number, and page citation is verified**.
|
|
9
|
+
|
|
10
|
+
## Workflow
|
|
11
|
+
|
|
12
|
+
1. **Inspect the source document**
|
|
13
|
+
- Call `inspect_document(path)` to confirm total pages, printed page labels, and document SHA-256 fingerprint.
|
|
14
|
+
2. **Locate candidate pages**
|
|
15
|
+
- Call `search_document(path, query, top_k=5)` to rank relevant pages with BM25-inspired term and phrase matching.
|
|
16
|
+
3. **Read verbatim evidence**
|
|
17
|
+
- Call `extract_pages(path, start_page, end_page)` to inspect surrounding context before drafting conclusions.
|
|
18
|
+
4. **Verify before responding**
|
|
19
|
+
- For single claims, call `verify_citation(path, claim, cited_page)`.
|
|
20
|
+
- For multi-claim answers, call `audit_citations(path, citations=[{"claim": ..., "cited_page": ...}])`.
|
|
21
|
+
5. **Resolve failures deterministically**
|
|
22
|
+
- `page_mismatch`: Update your citation to the returned `matched_page` after re-reading that page.
|
|
23
|
+
- `partial_match`: Check `missing_numbers` — never ship unverified percentages, years, currencies, or quantities.
|
|
24
|
+
- `not_found`: Remove the unsupported claim or state explicitly that the source document does not cover it.
|
|
25
|
+
|
|
26
|
+
## CLI Quality Gate
|
|
27
|
+
|
|
28
|
+
Run deterministic verification inside CI pipelines or local evaluation scripts:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
docprov verify ./annual_report.pdf --claim "Operating margin reached 18.4% in FY2025" --page 12
|
|
32
|
+
docprov audit ./annual_report.pdf --citations ./claims.json --format markdown --strict
|
|
33
|
+
```
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"""docprov-mcp: Deterministic citation provenance verification for PDF & Markdown."""
|
|
2
|
+
|
|
3
|
+
from docprov_mcp.loader import load_document
|
|
4
|
+
from docprov_mcp.verifier import (
|
|
5
|
+
audit_citations,
|
|
6
|
+
extract_pages,
|
|
7
|
+
format_report_markdown,
|
|
8
|
+
search_document,
|
|
9
|
+
verify_citation,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
__version__ = "0.1.0"
|
|
13
|
+
|
|
14
|
+
__all__ = [
|
|
15
|
+
"__version__",
|
|
16
|
+
"load_document",
|
|
17
|
+
"extract_pages",
|
|
18
|
+
"search_document",
|
|
19
|
+
"verify_citation",
|
|
20
|
+
"audit_citations",
|
|
21
|
+
"format_report_markdown",
|
|
22
|
+
]
|